Page 1 of 2
Java Servlets & PHP
Posted: Thu Sep 11, 2003 2:10 pm
by Sinnix
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?
Posted: Thu Sep 11, 2003 2:15 pm
by m3rajk
have you tried grabbong the request string?
using sessions?
Posted: Thu Sep 11, 2003 2:17 pm
by Sinnix
No I have not actually. I wasn't even aware that was possible.

I'll head to php.net and see what I can learn.
Posted: Thu Sep 11, 2003 2:22 pm
by Sinnix
Alright... I checked it out... it's official. I have no idea what you're talking about.

Posted: Thu Sep 11, 2003 3:01 pm
by JAM
Just as a brief explanation:
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__);
?>
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.
Posted: Thu Sep 11, 2003 3:42 pm
by Sinnix
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.

Posted: Thu Sep 11, 2003 10:08 pm
by m3rajk
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?
Posted: Thu Sep 11, 2003 10:17 pm
by JAM
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.
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.
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.
Posted: Fri Sep 12, 2003 9:29 am
by Sinnix
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.

Posted: Fri Sep 12, 2003 10:54 am
by JAM
Haha

Where did you get the applet from? Most applets (or any script-like code for that matter) usually comes with a piece of explanation and what usage/params that is needed.
Posted: Fri Sep 12, 2003 11:17 am
by m3rajk
Sinnix 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.

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 about
Posted: Fri Sep 12, 2003 12:52 pm
by Sinnix
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.
Posted: Fri Sep 12, 2003 2:04 pm
by JAM
: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.
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++;
}
?>
Posted: Mon Sep 15, 2003 10:16 am
by Sinnix
I got some example code back from the other developer, but it's kinda WAY above my head! lol
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>";
?>
and the second file...
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;
}
}
}
?>

I'm so screwed!! But... there it is... and it works! (although how is beyond me!)
Posted: Mon Sep 15, 2003 10:20 am
by Sinnix
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?
