wood burning stoves 2.0*
The moose likes Web Services and the fly likes order of request parameters causing unexpected subelement exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "order of request parameters causing unexpected subelement exception" Watch "order of request parameters causing unexpected subelement exception" New topic
Author

order of request parameters causing unexpected subelement exception

varun srivastv
Greenhorn

Joined: Oct 15, 2009
Posts: 16
I have a wsdl code as

<wsdl:message name="getRolesResponse">
<wsdl:part name="RolesCollection" type="sd:RolesCollectionType" />
<wsdl:part name="error" type="sd:ErrorType" />
</wsdl:message>

<wsdl:message name="getRolesRequest">
<wsdl:part name="userName" type="xsd:string" />
<wsdl:part name="applicationName" type="xsd:string"/>
<wsdl:part name="applicationStrategyName" type="xsd:string"/>
</wsdl:message>

But my auto generated(from wsdl2code)file GetRoles.java has the order of parameters as

applicationStrategyName
applicationName
userName

Out of the 6 possible ordering of the parameters, only following three gives the result

http://.../getRoles?applicationStrategyName=ABC&userName=TestUser&applicationName=TestApp
http://...../getRoles?applicationName=TestApp&userName=TestUser&applicationStrategyName=ABC
http://.../getRoles?userName=TestUser&applicationStrategyName=ABC&applicationName=TestApp

Rest three gives "unexpected subelement userName" exception.

And strangely, the original ordering in the wsdl also gives exception.

Can anyone tell some way that the order of the request parameter don't cause any issue.


Thanks
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Do you really succeed in doing anything when putting the parameters in the URL like you have shown?
If you are doing SOAP web services, and I assume that you do since you have a WSDL, then the parameters are to be in a SOAP envelope.
Take a look at Wikipedia for some examples: http://en.wikipedia.org/wiki/SOAP_%28protocol%29
If you want to try out a web service server without writing any code, I suggest using soapUI - it will let you examine the in- and out-going SOAP messages of the web service.
The order of the parameters in the generated Java code does not matter, what matters is the contents of the SOAP request message.
Best wishes!
varun srivastv
Greenhorn

Joined: Oct 15, 2009
Posts: 16
hey ..thanks for the reply.

The URL things works as i have restful service for the service.

>>The order of the parameters in the generated Java code does not matter, what matters is the contents of the SOAP request message
Even the soap message requires the parameters in specific order (different from that defined in wsdl)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://service.server.abcd">
<soap:Header/>
<soap:Body>
<ser:getRoles>
<applicationStrategyName>TestStrategy</applicationStrategyName>
<applicationName>TestApp</applicationName>
<userName>TestUser</userName>
</ser:getRoles>
</soap:Body>
</soap:Envelope>

the above soap request works but if I change the order of the request parameters, as follows , i get unexpected subelement userName exception

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://service.server.abcd">
<soap:Header/>
<soap:Body>
<ser:getRoles>
<userName>TestUser</userName>
<applicationName>TestApp</applicationName>
<applicationStrategyName>TestStrategy</applicationStrategyName>
</ser:getRoles>
</soap:Body>
</soap:Envelope>

This soap request gives exception even the parameter order are same as specified in the wsdl.


Thanks !!


Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
varun srivastv wrote:The URL things works as i have restful service for the service.

Aha, that explains things!


>>The order of the parameters in the generated Java code does not matter, what matters is the contents of the SOAP request message
Even the soap message requires the parameters in specific order (different from that defined in wsdl)

Have you tried to invoke the SOAP web service using soapUI or to generate the client artifacts using wsimport (instead of wsdl2java)?
It sounds like wsdl2java acts slightly funky. By trying one, or both, of the above you can determine if wsdl2java generates the correct artifacts or not.
Best wishes!
varun srivastv
Greenhorn

Joined: Oct 15, 2009
Posts: 16
Hi,

I am invoking the SOAP web service using soapUI and also i have created client in perl. But in both cases the request parameters need to be in specific order as
mentioned in previous update. The two soap request posted earlier were created using Soap Ui and only one of them worked.

Also if I try to specify parameterOrder attribute for the operation, I am getting exception while building the jar

" org.apache.axis2.AxisFault: the parameter order can left atmost one part"


<wsdl:message name="getRolesRequest">
<wsdl:part name="userName" type="xsd:string" />
<wsdl:part name="applicationName" type="xsd:string"/>
<wsdl:part name="applicationStrategyName" type="xsd:string"/>
</wsdl:message>

<wsdl:message name="getRolesResponse">
<wsdl:part name="RolesCollection" type="sd:RolesCollectionType" />
<wsdl:part name="error" type="sd:ErrorType" />
</wsdl:message>
.
.
.
.
<wsdl:portType name="ABCServicePort">
<wsdlperation name="getRoles" parameterOrder="userName applicationName aplicationStrategyName">
<wsdl:input name="input6"
message="tns:getRolesRequest" />
<wsdlutput name="output6"
message="tns:getRolesResponse" />
</wsdlperation>
</wsdl:portType>

So i am not even to able to specify the parameter ordering.


Thanks!!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
First of all, concerning the parameterOrder attribute, check these links:
Take a look at example 5 that shows how to use the attribute: http://www.w3.org/TR/wsdl#_soap-e
WS-I Basic Profile about how to use the attribute: http://www.ws-i.org/Profiles/BasicProfile-1.1.html#parameterOrder_Attribute_Construction
The problem is that you have two parts in the response. In the parameterOrder attribute you can at most leave out one part.

Considering the order of the parameters: It looks like it is the reverse of what is defined in the WSDL. I can't say I have seen this before.
I hope you will succeed in using the parameterOrder attribute.
Best wishes!
varun srivastv
Greenhorn

Joined: Oct 15, 2009
Posts: 16
Hi,
Please have a look at the wsdl

<?xml version="1.0" encoding="utf-8"?>

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.abcd.com/security/service/062007"
xmlns:sd="http://www.abcd.com/security/data/062007"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="authorization"
targetNamespace="http://www.abcd.com/security/service/062007">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.abcd.com/security/data/062007"
xmlns:tns="http://www.abcd.com/security/data/062007"
elementFormDefault="qualified">

<xsd:complexType name="ErrorType">
<xsd:sequence>
<xsd:element name="errorMessage"
type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>

<wsdl:message name="findSubjectResponse">
<wsdl:part name="subject" type="xsd:String" />
</wsdl:message>

<wsdl:message name="findSubjectRequest">
<wsdl:part name="userName" type="xsd:string" />
<wsdl:part name="applicationName" type="xsd:string" />
<wsdl:part name="applicationStrategyName" type="xsd:string" />
</wsdl:message>

<wsdl:message name="getRolesRequest">
<wsdl:part name="userName" type="xsd:string" />
<wsdl:part name="applicationName" type="xsd:string"/>
<wsdl:part name="applicationStrategyName" type="xsd:string"/>
</wsdl:message>

<wsdl:message name="getRolesResponse">
<wsdl:part name="RolesCollection" type="sd:RolesCollectionType" />
<wsdl:part name="error" type="sd:ErrorType" />
</wsdl:message>


<wsdl:portType name="servicePort">
<wsdlperation name="findSubject" parameterOrder="applicationName userName applicationStrategyName">
<wsdl:input name="input1"
message="tns:findSubjectRequest" />
<wsdlutput name="output1"
message="tns:findSubjectResponse" />
</wsdlperation>

<wsdlperation name="getRoles" parameterOrder="userName applicationName applicationStrategyName">
<wsdl:input name="input2"
message="tns:getRolesRequest" />
<wsdlutput name="output2"
message="tns:getRolesResponse" />
</wsdlperation>
</wsdl:portType>

<wsdl:binding name="securitySOAPBinding"
type="tns:servicePort">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdlperation name="findSubject">
<soapperation soapAction="findSubject" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdlutput>
<soap:body use="literal" />
</wsdlutput>
</wsdlperation>

<wsdlperation name="getRoles">
<soapperation soapAction="getRoles" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdlutput>
<soap:body use="literal" />
</wsdlutput>
</wsdlperation>
</wsdl:binding>
<wsdl:service name="securityService">
<wsdl:port binding="tns:securitySOAPBinding"
name="securityServicePort062007">
<soap:address
location="http://abcd...../" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>


The parameterOrder attribute in getSubject operation works fine but it gives exception in getRoles operation.

I think the problem is in having multiple parts in getRoles response.
Any idea??


Thanks !!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
varun srivastv wrote:
I think the problem is in having multiple parts in getRoles response.
Any idea??

Yes, that is what I said in my last post.
Since you have two parts in the getRoles response, you must include at least one of the parts in the parameterOrder attribute.
The part not listed in the parameterOrder attribute will be the return value of the operation.
Best wishes!
varun srivastv
Greenhorn

Joined: Oct 15, 2009
Posts: 16
Hi..

Thanks...that works....

So part of problem is solved i.e by setting parameterOrder attribute I can specify the order in which I want the request parameters.
At least i can be sure or what order of request parameters does the web service expect.

But the original problem still remains, that can I have any order of parameters to work. This is important when an external client tries to use the web service.

Thanks !!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi again!
varun srivastv wrote:
But the original problem still remains, that can I have any order of parameters to work. This is important when an external client tries to use the web service.

With your current approach, I am rather sure that arbitrary ordering of the parameters is not possible.
What you could do is to, in XML, declare a parameter container that is a <complexType> in which you use the <all> element, which allows the elements of the type to appear in any order.
Example:

Note that, when using <all> there are some restrictions:
• Child elements always have a maxOccurs of 1 and a minOccurs of 0.
• Only single elements may occur in an <all> group.
No groupings like <sequence> or <all> can occur in an <all> group, however, custom types
declared using either <simpleType> or <complexType> can occur in an <all> group.
Best wishes!
varun srivastv
Greenhorn

Joined: Oct 15, 2009
Posts: 16
Hey thanks...
that works!!

but the structure of soap request changes by using that solution, making it more complicated.

Another interesting result that I have found that if i use

<wsdl:message name="getRolesRequest">
<wsdl:part name="userName" type="xsd:string" />
<wsdl:part name="applicationName" type="xsd:string"/>
<wsdl:part name="applicationStrategyName" type="xsd:string"/>
</wsdl:message>

The order of parameters expected in soap request is applicationStrategyName , applicationName, userName and also if I try to use RESTful service,
only these three ordering works.

http://.../getRoles?applicationStrategyName=ABC&us...stUser&applicationName=TestApp
http://...../getRoles?applicationName=TestApp&user...er&applicationStrategyName=ABC
http://.../getRoles?userName=TestUser&applicationS...me=ABC&applicationName=TestApp


And when I use

<wsdl:message name="getRolesRequest">
<wsdl:part name="userId" type="xsd:string" />
<wsdl:part name="applicationId" type="xsd:string"/>
<wsdl:part name="strategyId" type="xsd:string"/>
</wsdl:message>

The order of parameters expected in soap request is userId, applicationId, strategyId (same order as in wsdl) and also if I try to use RESTful service,
all the six ordering of parameters work.

Any comment??

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: order of request parameters causing unexpected subelement exception
 
Similar Threads
Parameter order reversed when using Mule and Axis for a web service
WSDL and attachments
How do I consume Web Services in Swing
Axis2 generating diff. java files in Jdk 1.5 and Jdk 1.6
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement