Java Servlets & PHP
Moderator: General Moderators
-
Sinnix
- Forum Commoner
- Posts: 43
- Joined: Mon Apr 28, 2003 11:01 am
- Location: Ottawa, ON Canada
- Contact:
Java Servlets & PHP
I'm having severe issues getting my website to retrieve information from a Java Servlet server thingy. I need this:http://206.222.76.240:8080/LMS/intermap ... bmit+Query saved into a PHP variable so I can parse through it. Does anyone have any ideas?
Just as a brief explanation:
Okay, so it needs rewriting (to get all the funny codes right), but the general usage of the $_GET was shown. You can also use $_SERVER['QUERY_STRING'] to get everything after the first '?' and go from there.
Hope it helped some.
Code: Select all
Test Link
Array
(
[user] => bob
[role] => student
[request] =>
/MANIFEST[@course_id='1129']
[Send_Request] => Submit Query
)
<pre>
<a href="index.php?user=bob&role=student&request=%3CLMSIS_REQUEST+request_type%3D%22get%22+content_type%3D%22manifest%22%3E%0D%0A%09%3CGET%3E+%0D%0A%09%09%3CXPATH%3E%0D%0A%09%09%09%2FMANIFEST%5B@course_id%3D%271129%27%5D%0D%0A%09%09%3C%2FXPATH%3E%0D%0A%09%3C%2FGET%3E%0D%0A%3C%2FLMSIS_REQUEST%3E%0D%0A%09%09&Send+Request=Submit+Query">Test Link</a>
<?php
print_r($_GET);
show_source(__FILE__);
?>Hope it helped some.
-
Sinnix
- Forum Commoner
- Posts: 43
- Joined: Mon Apr 28, 2003 11:01 am
- Location: Ottawa, ON Canada
- Contact:
Hmm... tried this out. Still not what I'm looking for I don't think ($_GET doesn't seem to be holding any data). Allow me to further clarify my problem.
My webserver is running on a seperate machine than the java servlet computer. What I'm needing to do is ...
index.html - user inputs an ID number, calls action.php
action.php - connects to java servlet server and requests XML file pertaining to previously entered ID #(see link above). action.php then saves the XML file into a variable. action.php then outputs specific information to the user, but not the entire file.
I can handle navigating the XML file, but I'm used to working with files directly... not getting feedback through a java servlet thing.
My webserver is running on a seperate machine than the java servlet computer. What I'm needing to do is ...
index.html - user inputs an ID number, calls action.php
action.php - connects to java servlet server and requests XML file pertaining to previously entered ID #(see link above). action.php then saves the XML file into a variable. action.php then outputs specific information to the user, but not the entire file.
I can handle navigating the XML file, but I'm used to working with files directly... not getting feedback through a java servlet thing.
hmmm. not sure hot to have them interact.
i think it was 4.0.6 that was the last one with $HTTP_GET_VARS and after it was $_GET
check on your php version. knowing that will help us help you
ummm... hmmm
ssince it's two machines i'm not quite sure what to say.. not sure how much of an impact that will be... is php a cgi module or stand alone?
i think it was 4.0.6 that was the last one with $HTTP_GET_VARS and after it was $_GET
check on your php version. knowing that will help us help you
ummm... hmmm
ssince it's two machines i'm not quite sure what to say.. not sure how much of an impact that will be... is php a cgi module or stand alone?
Well, its because my example is printing out the value(s) to a page, and it contains controlcodes that makes certain things 'invisible'. Reason of gap in the print_r() array.Sinnix wrote:Hmm... tried this out. Still not what I'm looking for I don't think ($_GET doesn't seem to be holding any data). Allow me to further clarify my problem.
I'm not sure what information you need with the applet, but if you can clean up the URI from %22 and its likes, you will get a brand new result.
you could re-work it to use a db like say mysql instead of the servlets.. well i don't know for sure, but that's something to think aboutSinnix wrote:Yeah, I'm pretty much screwed.I'm using the latest version of php too. Thanks for your help JAM, I'm gonna contact the makers of this damn servlet (all ASP/Java people) and ask them what I'm supposed to do with this crap.
![]()
Oh, and for the record... I freakin' hate Java.
-
Sinnix
- Forum Commoner
- Posts: 43
- Joined: Mon Apr 28, 2003 11:01 am
- Location: Ottawa, ON Canada
- Contact:
Yeah, to answer both these questions... the servlet isn't mine. My company is doing a contract with another company and we're both responsible for different parts. It's the other company's stupid Java servlet that's causing the problems. I requested it in a database when the project started but, in the end, I got stuck with stupid servlets and XML files.
I called their project manager earlier today and told him that I was stuck, he said that he would have one of his coders send me a code snippit to parse out the XML by the end of the day. I'm *very much* looking forward to seeing this 'wonder code'.
I'll be sure to post it if it works.
I called their project manager earlier today and told him that I was stuck, he said that he would have one of his coders send me a code snippit to parse out the XML by the end of the day. I'm *very much* looking forward to seeing this 'wonder code'.
:idea: I just happen to spot some examples in the php manual, that surely must help out. ;)
Try and see if you can work something out with this small example.
Try and see if you can work something out with this small example.
Code: Select all
<pre>
<?php
// this is your previously posted link
$link = "http://206.222.76.240:8080/LMS/intermap/servlet/information?user=bob&role=student&request=%3CLMSIS_REQUEST+request_type%3D%22get%22+content_type%3D%22manifest%22%3E%0D%0A%09%3CGET%3E+%0D%0A%09%09%3CXPATH%3E%0D%0A%09%09%09%2FMANIFEST%5B@course_id%3D%271129%27%5D%0D%0A%09%09%3C%2FXPATH%3E%0D%0A%09%3C%2FGET%3E%0D%0A%3C%2FLMSIS_REQUEST%3E%0D%0A%09%09&Send+Request=Submit+Query";
$a = explode('&', $link);
$i = 0;
while ($i < count($a)) {
$b = split('=', $a[$i]);
echo 'Value for parameter ', htmlspecialchars(urldecode($b[0])),
' is ', htmlspecialchars(urldecode($b[1])), "<br />\n";
$i++;
}
?>-
Sinnix
- Forum Commoner
- Posts: 43
- Joined: Mon Apr 28, 2003 11:01 am
- Location: Ottawa, ON Canada
- Contact:
I got some example code back from the other developer, but it's kinda WAY above my head! lol
and the second file...
I'm so screwed!! But... there it is... and it works! (although how is beyond me!)
Code: Select all
<?php
include("AdgaLmsisClient.php");
$requestXml = "<LMSIS_REQUEST request_type='get' content_type='manifest'>";
$requestXml .= "<GET>\n<XPATH>";
$requestXml .= "/MANIFEST[@course_id='1131']";
$requestXml .= "</XPATH></GET></LMSIS_REQUEST>";
$client = new AdgaLmsisClient(
"http://206.222.76.240:8080/LMS/intermap/servlet/information","rwolf");
//$responseXml = $client->getServerResponse($requestXml);
//echo "The response XML (whole response) was:\n";
//echo $responseXml;
echo "<html><body>";
$response = $client->handleRequest($requestXml);
if( $response['status'] == 'success' )
{
// we have a successful response
echo "<p>Request succeeded";
echo "<ul>";
foreach ($response as $responseKey=>$responseVal)
{
echo "<li>$responseKey: $responseVal";
}
echo "</ul>";
// now we parse the inner response with the same parser as we used for the
// outer response; this is not recommended (you should use another set of
// parser handlers to avoid confusing code...); this is for purposes of example
// I only partially parse the manifest here as a demonstration; a proper parser should
// create a recursive data structure to hold any response in the general sense
$innerResponse = $client->parseServerResponse($response['successInfo']);
echo "<p>Manifest title:" . $innerResponse['courseTitle'];
}
else
{
echo "<p>Request failed";
}
echo "</body></html>";
?>Code: Select all
<?php
class AdgaLmsisClient
{
var $serverBaseUrl;
var $user;
var $role;
var $currentElement;
function AdgaLmsisClient($serverBaseUrl,$user)
{
$this->serverBaseUrl = $serverBaseUrl;
$this->role = "trainer";
$this->user = $user;
}
function handleRequest($xmlString)
{
$responseString = $this->getServerResponse($xmlString);
return $this->parseServerResponse($responseString);
}
function getServerResponse($xmlString)
{
$url = $this->serverBaseUrl . "?user=".$this->user;
$url .= "&role=".$this->role."&request=".urlencode($xmlString);
// echo "<p>Using url:" . $url;
$responseFH = fopen($url,"r");
$responseString = "";
while( $nextLine = fgets($responseFH,1024) )
{
$responseString .= $nextLine;
}
return $responseString;
}
function parseServerResponse($responseString)
{
$this->response = array(
'requestType'=>'',
'contentType'=>'',
'status'=>'',
'successInfo'=>"");
$parser = xml_parser_create();
xml_set_object($parser,$this);
xml_set_element_handler($parser,"xmlStartElementHandler","xmlEndElementHandlder");
xml_set_character_data_handler($parser,"xmlCdataHandler");
xml_parse($parser,$responseString);
return $this->response;
}
function xmlStartElementHandler($parser, $elementName, &$elementAttributes)
{
// echo "<p>Saw $elementName";
if( $elementName == "LMSIS_RESPONSE" )
{
$this->currentElement = $elementName;
$this->response["status"] = $elementAttributes["STATUS"];
$this->response["contentType"] = $elementAttributes["CONTENT_TYPE"];
$this->response["requestType"] = $elementAttributes["REQUEST_TYPE"];
}
elseif( $elementName == "SUCCESS_INFO" )
{
$this->currentElement = $elementName;
}
elseif( $elementName == "MANIFEST" )
{
$this->response["courseTitle"] = $elementAttributes["TITLE"];
}
}
function xmlEndElementHandlder($parser,$elementName)
{
}
function xmlCdataHandler($parser,$cdata)
{
// echo "<br>$cdata";
// this collects the inner XML from a get response
if( $this->currentElement == "SUCCESS_INFO" )
{
$this->response["successInfo"] .= $cdata;
}
}
}
?>-
Sinnix
- Forum Commoner
- Posts: 43
- Joined: Mon Apr 28, 2003 11:01 am
- Location: Ottawa, ON Canada
- Contact:
I don't suppose someone could take a moment to explain a few things to me...
what exactly does this mean:I mean, what's up with that "->" thing? And I've seen "=>" too, what's the difference? 
what exactly does this mean:
Code: Select all
$var1 = $var2->function($var3);