API Issue

Started by nicotine, October 08, 2008, 09:24:38 AM

Previous topic - Next topic

nicotine

I'm having some issues trying to use the API interface to Nictool Server -- I'm currently using XML_RPC2 from the PEAR library.  I'm successfully able to create a client session, but when I attempt to login, I get the following error (I have XML_RPC2's debugging option enabled):


***** Request *****
<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>login</methodName>
<params>
<param>
  <value>
   <struct>
    <member>
     <name>username</name>
     <value>
      <string>test@example.com</string>
     </value>
    </member>
    <member>
     <name>password</name>
     <value>
      <string>testingtesting</string>
     </value>
    </member>
   </struct>
  </value>
</param>
</params>
</methodCall>
***** End Of request *****

***** Server response *****
<?xml version="1.0" encoding="us-ascii"?><methodResponse><params><param><value><struct><member><name>error_msg</name><value><string>Your session has expired. Please login again</string></value></member><member><name>error_code</name><value><int>403</int></value></member></struct></value></param></params></methodResponse><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>200 OK</title>
</head><body>
<h1>OK</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
sysadmin@example.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

***** End of server response *****

expat reports error code 5
        description: Invalid document end
        line: 1
        column: 321
        byte index: 283
        total bytes: 283

        data beginning 10 before byte index: struct>


The following is logged in the server's log:


[Wed Oct 08 08:43:24 2008] [error] [client 10.10.17.13] Handler for perl-script returned invalid result code 1
[Wed Oct 08 10:16:26 2008] [error] [client 10.10.17.13] Handler for perl-script returned invalid result code 1


I believe the expat error is generated locally, as it has a problem parsing the server response (as it contains both XML and HTML) Can anyone provide any further insight as to what exactly is going on?  Is it my XMLRPC library, or a misconfiguration on the server?

matt

Not sure about that. I had issues trying to get XMLRPC working correctly. I switched to SOAP and never bothered trying XMLRPC again.

nicotine

#2
So I switched to SOAP -- still seeing the same error. :/


<?
require_once('SOAP/Client.php');
$client = new SOAP_Client('http://nictool.example.com:8082');
$result = $client->login(array("username" => "test@example.com", "password" => "testingtesting"));
if (PEAR::isError($result)) print_r($result->getFault());

Result is

php blah.php
stdClass Object
(
    [faultcode] => Parser
    [faultstring] => XML error on line 1 col 321 byte 283 Invalid document end
    [faultactor] =>
    [detail] => &lt;?xml version=&quot;1.0&quot; encoding=&quot;us-ascii&quot;?&gt;&lt;methodResponse&gt;&lt;params&gt;&lt;param&gt;&lt;value&gt;&lt;struct&gt;&lt;member&gt;&lt;name&gt;error_msg&lt;/name&gt;&lt;value&gt;&lt;string&gt;Your session has expired. Please login again&lt;/string&gt;&lt;/value&gt;&lt;/member&gt;&lt;member&gt;&lt;name&gt;error_code&lt;/name&gt;&lt;value&gt;&lt;int&gt;403&lt;/int&gt;&lt;/value&gt;&lt;/member&gt;&lt;/struct&gt;&lt;/value&gt;&lt;/param&gt;&lt;/params&gt;&lt;/methodResponse&gt;&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;
&lt;html&gt;&lt;head&gt;
&lt;title&gt;200 OK&lt;/title&gt;
&lt;/head&gt;&lt;body&gt;
&lt;h1&gt;OK&lt;/h1&gt;
&lt;p&gt;The server encountered an internal error or
misconfiguration and was unable to complete
your request.&lt;/p&gt;
&lt;p&gt;Please contact the server administrator,
sysadmin@example.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.&lt;/p&gt;
&lt;p&gt;More information about this error may be available
in the server error log.&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;
)


Any suggestions on additional debugging options that could be enabled on the nictool server?

matt

If you take a look at NicToolServer.pm, there's a sub named 'handler'. That sub handles the XML::RPC/SOAP request. You'll notice there's a bunch of warn calls in there that'll spit out debug output if debug_X is true. Immediately above the handler sub, is this:

sub debug             {0}
sub debug_session_sql {0}
sub debug_sql         {0}
sub debug_permissions {0}
sub debug_result      {0}
sub debug_request     {0}
sub debug_logs        {0}

You should be able to figure out what those do. Keep in mind that NicToolServer is a mod_perl application, so it's debug output will most likely be found in error.log.

Matt

nicotine

#4
Additional logging did not reveal anything new.  After digging through NicToolServerAPI.pm for a while, I discovered that my URI should have /soap on the end of it.  Adding that, now I'm told my unauthenticated user doesn't have access to the login() method:

stdClass Object
(
    [faultcode] => soap:Client
    [faultstring] => Denied access to method (login) in class (main) at /usr/local/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2509.

    [faultactor] =>
    [detail] =>
)
OUTGOING:

POST /soap HTTP/1.0
User-Agent: PEAR-SOAP 0.12.0-beta
Host: 127.0.0.1
Content-Type: text/xml; charset=UTF-8
Content-Length: 535
SOAPAction: ""
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<login>
<username xsi:type="xsd:string">test</username>
<password xsi:type="xsd:string">testpass</password></login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


INCOMING

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Denied access to method (login) in class (main) at /usr/local/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2509.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>

Is there a similar trace mechanism in NicToolServerAPI so I can compare the incoming/outgoing SOAP messages?

nicotine

After CONTINUING to poke this with a sharp pointy stick, I have enabled debugging in NicToolServerAPI.pm, and captured the following SOAP request via Perl:


SOAP::Transport::HTTP::Client::send_receive: POST http://127.0.0.1:8082/soap HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 618
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://127.0.0.1/NicToolServer/SOAP#login"


<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"   
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<login xmlns="http://127.0.0.1/NicToolServer/SOAP">
<c-gensym3>
<nt_protocol_version xsi:type="xsd:float">1.0</nt_protocol_version>
<password xsi:type="xsd:string">testpass</password>
<username xsi:type="xsd:string">test</username>
</c-gensym3>
</login>
</soap:Body>
</soap:Envelope>


I now have the following PHP script, that generates the output below it:

<?

require_once('SOAP/Client.php');

SOAP_BASE::SOAPENVPrefix("soap");
SOAP_BASE::SOAPENCPrefix("soapenc");
$client = new SOAP_Client('http://127.0.0.1:8082/soap');
$client->setTrace(true);
$result = $client->call("login", array("nt_protocol_version" => 1.0, "username" => "test", "password" => "testpass"), false, "http://127.0.0.1/NicToolServer/SOAP#login");
if (PEAR::isError($result)) print_r($result->getFault());
echo $client->getWire();

output:

OUTGOING:

POST /soap HTTP/1.0
User-Agent: PEAR-SOAP 0.12.0-beta
Host: 127.0.0.1
Content-Type: text/xml; charset=UTF-8
Content-Length: 511
SOAPAction: "http://127.0.0.1/NicToolServer/SOAP#login"
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<login>
<nt_protocol_version xsi:type="xsd:float">1</nt_protocol_version>
<username xsi:type="xsd:string">test</username>
<password xsi:type="xsd:string">testpass</password>
</login>
</soap:Body>
</soap:Envelope>


INCOMING

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Denied access to method (login) in class (main) at /usr/local/lib/perl5/site_perl/5.8.8/SOAP/Lite.pm line 2509.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>


I, unfortunately , am no where NEAR familiar enough with the actual structure of SOAP messages to determine how to line up the remaining missing items on the PHP side (mostly the c-gensym3 stanza, which is missing on the PHP SOAP request) -- any further guidance would be appreciated.

nicotine

Regarding the gensym tags in the Perl SOAP::Lite request:

http://www.soaplite.com/2003/08/how_do_you_turn.html

Related?