Solved

Help with SOAP webservice: PHP and Java.

Posted on 2014-04-01
24
2,020 Views
Last Modified: 2016-02-26
Greetings Team,
We are creating a Webservice for a customer in WSDL mode. We develop in PHP, they work in Java. Our service, when we test with/out nusoap library in PHP works fine. But when the customer calls the service they get:
-Null response
-Unexpected format text/html, expected text/xml
-Error in msg parsing.

Do we need to recheck the WSDL? If this was the case, then it shouldnt work with PHP too.
We tried different permutations, combinations but they keep getting one of these cases.
How do we solve this? Attached WSDL.
Thank you in Advance.
Query.txt
0
Comment
Question by:Nilima-Mohite
  • 11
  • 6
  • 5
24 Comments
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39969241
Did you try to send in the same request as your customer and see if it works ?
0
 

Author Comment

by:Nilima-Mohite
ID: 39971544
We asked them to send us a copy of the JAX-WS code. We are now trying to install Eclipse, Java and the related softwares to replicate the issue. Figuring out what softwares needed to do this,
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39971891
I think you got me wrong . No need of installing all that . Did you actually test with the same input to the webservice ?
0
 

Author Comment

by:Nilima-Mohite
ID: 39971927
Yes.
Their input is:
--uuid:6035feb3-d1da-4493-b32b-7146115d0327
Content-Id: <rootpart*6035feb3-d1da-4493-b32b-7146115d0327@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><updateDelivery xmlns="http://ourwebservice.domain.com/><data>9861164345-98611643451391407829-20140219000000-test one-100003767</data><hashkey>2604574653</hashkey></updateDelivery></S:Body></S:Envelope>
--uuid:6035feb3-d1da-4493-b32b-7146115d0327--

Open in new window


When we try to make a client and pass this as input, it works fine. We get the SOAP envelope in response:

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:Body><ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/"><return xsi:type="xsd:string">100|2604574653|
</return></ns1:updateDeliveryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Open in new window



Why they cant get the response is what we cant understand.
They get:
com.sun.xml.internal.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}updateDeliveryReturn

Open in new window



or:
com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html Supported ones are: [text/xml]

Open in new window

Any solution to this?
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39972061
Is updateDeliveryReturn valid element in the input?
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39972063
BTW , instead of installing eclipse and all , you can use SoapUI - java based web services util
0
 

Author Comment

by:Nilima-Mohite
ID: 39972146
Was sending response as [updateDeliveryReturn]=response. Removed that. Then they started getting 'null' is response.

We tested on SoapUI too.
Steps:
1) Create SOAP Project.
2) Give project name, enter the WSDL path.
3) It shows updateDelivery as method, with Request 1.
4) We added the input which we receive from client

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><updateDelivery xmlns="http://ourwebservice.domain.com/"><data>9861164345-98611643451391407829-20140219000000-test one-100003767</data><hashkey>2604574653</hashkey></updateDelivery></S:Body></S:Envelope>

Open in new window


& Click Run.

5) It gives response:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:Body>
      <ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/">
         <return xsi:type="xsd:string">100|2604574653|</return>
      </ns1:updateDeliveryResponse>
   </SOAP-ENV:Body>

Open in new window

</SOAP-ENV:Envelope>

Hope we are doing the correct steps.

How can the customer pick up this response in Java? Please check the WSDL attached in the original question. The customer keeps asking us to update the WSDL and send the service. Why?
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39974714
You said you gave the input in soapUI as :
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><updateDelivery xmlns="http://ourwebservice.domain.com/"><data>9861164345-98611643451391407829-20140219000000-test one-100003767</data><hashkey>2604574653</hashkey></updateDelivery></S:Body></S:Envelope>

Open in new window

but in one of the earlier posts , you said customer request started with:
--uuid:6035feb3-d1da-4493-b32b-7146115d0327
Content-Id: <rootpart*6035feb3-d1da-4493-b32b-7146115d0327@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

Open in new window

0
 

Author Comment

by:Nilima-Mohite
ID: 39974911
Hi,
Yes. The input received from the customer comes with this header information. If we point that out to them they say they are not doing anything to add the header information, it is as per our WSDL. How is that possible, beats us.

 Even we had a tough time getting that header information out from the input and submitting only the SOAP envelope to our SOAP server.
But if the entire input with the header information is given to the SOAP server built using 'nusoap' library, it works.

We created a client in 'nusoap' library whose Request Response is as below:

Request

POST /PATH/delivery.php HTTP/1.0
Host: ourwebservice.domain.com/
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "OURWEBSERVICEservice#updateDelivery"
Content-Length: 558

<?xml version="1.0" encoding="ISO-8859-1"?><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/" xmlns:ns2235="http://tempuri.org"><SOAP-ENV:Body><updateDelivery xmlns="http://ourwebservice.domain.com/"><data>9861164345-98611643451391407829-20140219000000-test one-100003767</data><hashkey>2604574653</hashkey></updateDelivery></SOAP-ENV:Body></SOAP-ENV:Envelope>

Open in new window


Response

HTTP/1.1 200 OK
Date: Thu, 03 Apr 2014 13:02:45 GMT
Server: Apache/2.0.55 (Unix) PHP/5.2.13
X-Powered-By: PHP/5.2.13
X-SOAP-Server: NuSOAP/0.9.5 (1.123)
Content-Length: 567
Connection: close
Content-Type: text/xml; charset=ISO-8859-1

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:Body><ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/"><return xsi:type="xsd:string">100|2604574653|
</return></ns1:updateDeliveryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Open in new window



Does this throw any light on the issue of why the customer cant get the Response in Java.
Thank you in advance !
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39974943
Is the webservice developed using NuSOAP / Whatever it is , webservices are supposed to be language independent . Also , when you pass the client's 'corrupt' request as is , what is the exception you see at the server side?
0
 

Author Comment

by:Nilima-Mohite
ID: 39977456
Hi,
Please check the attached screenshots from SoupUI for valid and corrupt input.
In the current code we are using 'nusoap' library and not doing any processing to get the valid SOAP xml input.
Input is taken with :
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

This contains the header information when the customer calls the service.
Corrupt input with header information
When we call the service, we receive only the SOAP envelope.
Valid input with only SOAP envelope
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39987692
There are a few things that just don't sound quite right with this, but let's tackle one thing at a time...

The customer keeps asking us to update the WSDL and send the service
That is probably because as it stands at the moment, the WSDL that you are providing them and the response that your server send them does NOT match. Let me point out a few things... If you look at the content of the WSDL, in the "wsdl:types" section there is an element with the name "updateDeliveryResponse" and that that element is defined to have a child element with the name "updateDeliveryReturn" which is a string that contains the important info. But know if you look at the response examples that you have posted in this thread, all your responses have an element called "updateDeliveryResponse" (this part is correct) but this element has a child element that is simply called "return" (not updateDeliveryReturn).

If you fix this (either change your service to return the correct element or change the WSDL to reflect what you are really sending) then the "customers" code may just start working. It will at least be a little bit closer. If it's still not working, post the new details of what is happening, ie. your new WSDL, exactly what they are sending as a request, what they get as a response and what errors they are getting. Also, if you are allowed, it would be handy if you code post the code that they are using.

Note, even though it looks strange, I don't think your problem is to do with the "header" information in the customers request. (If you are interested in researching further, what they are sending is a "Content-Type: multipart/related" request. It seems that your service is decoding that properly. You got an error when using SOAP UI, in that screenshot that you posted, because other HTTP Header information would not have been set up properly, ie. it was a true replication of what the customer was sending. However, the customers statement that "the WSDL caused the request to be sent that way" appears to be incorrect because there is nothing in that WSDL that would force a client to send a "multipart" request. But as I said, don't focus too much on that at the moment because I don't think it is the cause of your problems.
0
 

Author Comment

by:Nilima-Mohite
ID: 39988091
Thank you mccarl. You are absolutely right. We have been sort of roaming around in the dark trying to hit the target without a clue.

We installed and executed the JAX-WS code. We too started getting 'null' in response.

This is because, as you pointed out the response as per the WSDL should have:
<updateDeliveryResponse xmlns="http://ourwebservice.domain.com/">
         <updateDeliveryReturn xsi:type="xsd:string">100|2604574653|</updateDeliveryReturn>
      </updateDeliveryResponse>

It instead returns:
<ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/">
         <return xsi:type="xsd:string">100|2604574653|</return>
      </ns1:updateDeliveryResponse>

We cant figure out from where the 'return' element is coming from.

Solution as you say:
1) Change WSDL to return 'updateDeliveryReturn' instead of 'return->updateDeliveryReturn'
2) Change service.

We tried both but still the same or worse errors keep coming up.

Can you suggest what in the WSDL needs to change.

The namespace : http://ourwebservice.domain.com/ is just a path from our servers.

Does this have to do anything with the buggy output? We are trying to keep the WSDL simple.

Should we do something to write a wrapper to change the SOAP response, correct it and send it out again? Dont know how to do that. Will be last resort.

Thank you for taking a look at the issue.
0
 

Author Comment

by:Nilima-Mohite
ID: 39988384
Hello Team,
Update !
We managed to get the updateDeliveryReturn node in the SOAP response.

This is by sort of pushing the XML nodes as response.

 $output = '<ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/"><updateDeliveryReturn>'.$resp.'</updateDeliveryReturn></ns1:updateDeliveryResponse>';
            $result = new SoapVar($output,XSD_ANYXML);
            return $result;

The SOAP response now looks like:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ourwebservice.domain.com/"><SOAP-ENV:Body><ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/"><updateDeliveryReturn>100|2604574653|
</updateDeliveryReturn></ns1:updateDeliveryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>


But still the response from the service is 'null'

What is missing now? Do we HAVE to change the WSDL? If yes, then tell us where and how.

Please.
Thank you.
0
 

Author Comment

by:Nilima-Mohite
ID: 39988570
Hello, Update to above comment.
The change was in the XML we were sending out as output:
so this was changed from:
<ns1:updateDeliveryResponse xmlns:ns1="http://ourwebservice.domain.com/">

Open in new window

to
<ns1:updateDeliveryResponse xmlns="http://ourwebservice.domain.com/">

Open in new window


We got the response for the this change.


But when the customer tests, the input is :

--uuid:dbe88e4b-4b0f-4662-823c-7f2bfd5f9b80
Content-Id: <rootpart*dbe88e4b-4b0f-4662-823c-7f2bfd5f9b80@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><updateDelivery xmlns="http://ourwebservice.domain.com/"><data>9861164345-98611643451391407829-20140219000000-test one-100003767,9861159602-98611596021391408014-20140219000000-test three-100003769,9861163442-98611634421391407911-20140219000000-test two-100003768</data><hashkey>2604574653</hashkey></updateDelivery></S:Body></S:Envelope>
--uuid:dbe88e4b-4b0f-4662-823c-7f2bfd5f9b80--

Open in new window



After this our service stops working.
The customer sends us error as:
javax.xml.ws.soap.SOAPFaultException: Bad Request

        at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:190)

        at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:123)

        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:120)

        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:90)

        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:119)

        at $Proxy26.updateDelivery(Unknown Source)

Open in new window

................................


Now who is at fault?
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 500 total points
ID: 39990586
Sorry, I hadn't been able to return to this until now. Although it looks like you've made some progress on your own, that's great!

After this last change you say, 'We got the response for the this change". Does that mean that you got the correct response in the JAX-WS code that you are running on your side? But when you run this code from your end, the request that is sent to your service in the plain SOAP envelope but when they run it (from apparently exactly the same code) the request that is sent from them to you includes the "multipart" stuff? Is that correct?

If so, then it is still a little strange because (as far as I can tell from the words that you used in a previous post) I thought your server was properly accepting this "multipart" style request. In your post (http:#a39974911) you said, "The input received from the customer comes with this header information.  ...(edited)...  if the entire input with the header information is given to the SOAP server built using 'nusoap' library, it works." Were you saying there that you were able to make it work with this "multipart" style request?

Anyway, that aside, the request doesn't NEED to be sent using "multipart" as there is only ONE part to it. And it is a bit hard to really work out how/why this is happening without seeing any of the code. Although, it is still interesting why what is apparently the same code does different things for you or your customer. Anyway, possibly they may be doing something like this in their code...
BindingProvider bp = (BindingProvider) XXXXX;     // where XXXXX is the "Port" that is created for the Service
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);

Open in new window

Either that, or the JAX-WS implementation that they are using is different to what you are using and there is some configuration that is instructing the requests to be sent in this way.

But I guess, getting down to the real answer that you want... I would say that they are at fault at the moment. I can't see anything in that WSDL that would cause their client code to send the request as "multipart/related" so I would advise you to say this to them and stress that they need to work out why it is sending the request in this fashion on their end.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39990591
Oh, and the other thing that I was going to say...  In your last post where you said that you fixed the namespace issue so that you sent this...
<ns1:updateDeliveryResponse xmlns="http://ourwebservice.domain.com/">

Open in new window

You should really change this to remove the prefix too, such as...
<updateDeliveryResponse xmlns="http://ourwebservice.domain.com/">

Open in new window

(And obviously the same on the closing element. While you say that it already worked with this prefix, it is more correct to do it this way, and it would remove the possibility of latent issues that may come up in the future.

The entire code should look like this then...
 $output = '<updateDeliveryResponse xmlns="http://ourwebservice.domain.com/"><updateDeliveryReturn>'.$resp.'</updateDeliveryReturn></updateDeliveryResponse>';
            $result = new SoapVar($output,XSD_ANYXML);
            return $result;

Open in new window

0
 

Assisted Solution

by:Nilima-Mohite
Nilima-Mohite earned 0 total points
ID: 39991386
We solved the issue Finally !

Thank you mccarl. Your pointing out the issues was helpful in looking for the correct solution.



Summary of the solution:
-'null' response: The Soap response was missing the updateDeliveryReturn node. We added that using code:

$output = '<updateDeliveryResponse xmlns="http://ourwebservice.domain.com/"><updateDeliveryReturn>'.$resp.'</updateDeliveryReturn></updateDeliveryResponse>';
            $result = new SoapVar($output,XSD_ANYXML);
            return $result;

Open in new window


-The headers which were being sent by customer, which caused the service to throw exception of Bad Request.: We found the reason, that the Jar files which they sent had a .java file called SERVICENAME_Proxy.java. In the method to invoke the 'updateDelivery' they were using this Proxy class(pardon my confusion about naming, still unsure). This was sending different headers.
 While the Client we created using the WSDL didnt have the Proxy file. It had SERVICENAME_Service.java which we used to call the 'updateDelivery' in our method.
This sent the correct headers and SOAP Envelope, which the service successfully processed and gave the SOAP output.

-WSDL: We didnt change the WSDL at all.


I was going to never look at SOAP again in life. Now hope to explore it more and try some more real life integrations.

Thank you everyone for the help.
0
 

Author Comment

by:Nilima-Mohite
ID: 39996973
I've requested that this question be closed as follows:

Accepted answer: 0 points for Nilima-Mohite's comment #a39991386

for the following reason:

Worked around after a lot of trial and error
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39996974
I am happy with the asker accepting his answer as the solution, but I thought that my contribution (http:#a39987692) would at least deserve some "assist" points, especially as the asker says...
Thank you mccarl. Your pointing out the issues was helpful in looking for the correct solution
0
 

Author Closing Comment

by:Nilima-Mohite
ID: 40010148
Thanks for all the help
0
 
LVL 35

Expert Comment

by:mccarl
ID: 40016472
Thanks for all the help
Not a problem. I'm glad that you were able to get to a solution! :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now