You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Kraus, David" <dk...@MicroStrategy.com> on 2007/07/24 20:13:07 UTC

Problem handing bitflag enums in Axis2 serialization.

System.flags is used in dotnet to identify a bitflag enum, where one
value is associated with each bit of the enum, and multiple values/bits
can be set for the value of the enum (see dotnet generated WSDL below).
The problem is, how do you specify the null set, and can Axis2 handle
such a case in serialization? Enums are a tricky type since their
representation as a numeric entity (bits) making them a non-nullable
type, although their value is transfered as a string with multiple
concatenated enum values.

 

There are two classes generated by wsdl2java to handle the bitflag enum
at the server (eg. EnumMWSSearchFlags, EnumMWSSearchFlags_type0- see
attached). EnumMWSSearchFlags contains an array of
EnumMWSearchFlags_type0, each element of which can refer to a bit value.

 

Both dotnet and java clients serialize the empty set as a zero length
string. This zero length string is parsed, at the server, looking for
individual enum values. Of course, none are found, and when the zero
length string is used in a table lookup for valid members of the enum
(in EnumMWSSearchFlags_type0) an IllegalArgumentException is generated.
I have been able to get this to work by commenting out the check for
valid enum members being passed in, but obviously this isn't the best
way to do this (see specific commented out code below).

 

Shouldn't Axis2 generated serialization handle the special case where a
zero length string is passed in as the value of a bitflag enum??

 

Thanks, Dave Kraus

 

Altered code - see comment:

 

                public static EnumMWSSearchFlags_type0
fromValue(java.lang.String value)

                      throws java.lang.IllegalArgumentException {

                    EnumMWSSearchFlags_type0 enumeration =
(EnumMWSSearchFlags_type0)

                       

                               _table_.get(value);

                           

 

                    //drk: Comment out so that bitflag enum can accept
an emptyset enum

                    /*if (enumeration==null) throw new
java.lang.IllegalArgumentException();*/

                    return enumeration;

                }

 

 

WSDL representation of a bitflag enum:

 

      <s:simpleType name="EnumMWSSearchFlags">

        <s:list>

          <s:simpleType>

            <s:restriction base="s:string">

              <s:enumeration value="MWSAbbreviationWildCard"/>

              <s:enumeration value="MWSDescriptionWildCard"/>

              <s:enumeration value="MWSFolderBrowseStyle"/>

              <s:enumeration value="MWSModificationTime"/>

              <s:enumeration value="MWSNameWildCard"/>

              <s:enumeration value="MWSRootRecursive"/>

              <s:enumeration value="MWSUsedByOneOf"/>

              <s:enumeration value="MWSUsedByRecursive"/>

              <s:enumeration value="MWSUsesOneOf"/>

              <s:enumeration value="MWSUsesRecursive"/>

              <s:enumeration value="MWSVisibleOnly"/>

              <s:enumeration value="MWSBrowseAsync"/>

              <s:enumeration value="MWSOwnedByCurrentUser"/>

            </s:restriction>

          </s:simpleType>

        </s:list>

      </s:simpleType>

 

WSDL representation of usage of the bitflag enum as a parameter showing
minoccurs=1 because it's a non-nullable type.

 

<s:element maxOccurs="1" minOccurs="1" name="eFlags"
type="tns:EnumMWSSearchFlags"/>

 

 


RE: How to handle soap faults?

Posted by "Moore, Greg" <Gr...@adp.com>.
Dims,

Wow. thanks!! I didn't expect such a quick response with an example in
jyhton... 

Thank you very much. You've made my week. I've been struggling with this
for a while now. I was expecting it to be harder.

Regards,
Greg. 

-----Original Message-----
From: Davanum Srinivas [mailto:davanum@gmail.com] 
Sent: Wednesday, August 01, 2007 2:06 PM
To: Moore, Greg
Cc: axis-user@ws.apache.org
Subject: Re: How to handle soap faults?

Here you go:

#This handles the imports of the java stuff
from org.apache.commons.httpclient import *
from org.apache.commons.httpclient.methods import *
from org.apache.axis2.builder import *
from java.lang import *
from java.io import File

# xmlfilename contains a complete SOAP Envelope and all the headers
xmlFilename = 'aSoapEnvelope.xml'
xmlData = File(xmlFilename)
length = xmlData.length()
url = "http://localhost:5050/axis2/services/Version"
soapAction = "urn:getVersion"

# setup the http client -- post method and http headers
post = PostMethod(url)
entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
post.addRequestHeader("Content-Length", str(length))
post.setRequestEntity(entity)
post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
post.addRequestHeader("User-Agent", "SQA_TestClient0")
post.setRequestHeader("SOAPAction", soapAction)

# every thing is set now fire it off.
# responseText is whatever the server sends back either
# a response containing soap fault or a one containing cdata
httpClient = HttpClient()
statusCode = httpClient.executeMethod(post)
print "HTTP status code: " + Integer.toString(statusCode)
if statusCode == HttpStatus.SC_OK:
    builder =
BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print envelope.toString();
else:
# I'd like to check for soap fault here instead of a generic
# failure.
    builder =
BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print "Has Fault? : " +
Boolean.toString(envelope.getBody().hasFault());

thanks,
dims

On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
> Hi dims,
>
> Sure, but I'll warn you its in Jython so its not straight Java but
> pretty readable as is. # are single line comments just like the java
//
>
>         #This handles the imports of the java stuff
>         from org.apache.commons.httpclient import *
>         from org.apache.commons.httpclient.methods import *
>         from java.io import File
>
>         # xmlfilename contains a complete SOAP Envelope and all the
> headers
>         xmlFilename = 'aSoapEnvelope.xml'
>         xmlData = File(xmlFilename)
>         length = xmlData.length()
>         url = "http://myserver.somewhere.com/services/Check.asmx"
>         soapAction = "http://GateWay/Services/Check/GetReportXml"
>
>         # setup the http client -- post method and http headers
>         post = PostMethod(url)
>         entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
>         post.addRequestHeader("Content-Length", str(length))
>         post.setRequestEntity(entity)
>         post.addRequestHeader("Content-type", "text/xml;
charset=utf-8")
>         post.addRequestHeader("User-Agent", "SQA_TestClient0")
>         post.setRequestHeader("SOAPAction", soapAction)
>
>         # every thing is set now fire it off.
>         # responseText is whatever the server sends back either
>         # a response containing soap fault or a one containing cdata
>         httpClient = HttpClient()
>         statusCode = httpClient.executeMethod(post)
>        if statusCode == HttpStatus.SC_OK:
>                 resultText = post.getResponseBodyAsString()
>        else:
>           # I'd like to check for soap fault here instead of a generic
>               # failure.
>               print " failure: " + post.getStatusLine().toString()
>
> Hope this helps
>
> Regards,
> Greg,
>
>
> On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
[truncated]
> My question is it possible to use Axis to handle soap errors and/or 
> faults using HttpClient. 
-- 
Davanum Srinivas :: http://davanum.wordpress.com


This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to handle soap faults?

Posted by Davanum Srinivas <da...@gmail.com>.
Here you go:

#This handles the imports of the java stuff
from org.apache.commons.httpclient import *
from org.apache.commons.httpclient.methods import *
from org.apache.axis2.builder import *
from java.lang import *
from java.io import File

# xmlfilename contains a complete SOAP Envelope and all the headers
xmlFilename = 'aSoapEnvelope.xml'
xmlData = File(xmlFilename)
length = xmlData.length()
url = "http://localhost:5050/axis2/services/Version"
soapAction = "urn:getVersion"

# setup the http client -- post method and http headers
post = PostMethod(url)
entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
post.addRequestHeader("Content-Length", str(length))
post.setRequestEntity(entity)
post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
post.addRequestHeader("User-Agent", "SQA_TestClient0")
post.setRequestHeader("SOAPAction", soapAction)

# every thing is set now fire it off.
# responseText is whatever the server sends back either
# a response containing soap fault or a one containing cdata
httpClient = HttpClient()
statusCode = httpClient.executeMethod(post)
print "HTTP status code: " + Integer.toString(statusCode)
if statusCode == HttpStatus.SC_OK:
    builder = BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print envelope.toString();
else:
# I'd like to check for soap fault here instead of a generic
# failure.
    builder = BuilderUtil.getSOAPBuilder(post.getResponseBodyAsStream());
    envelope = builder.getDocumentElement();
    print "Has Fault? : " + Boolean.toString(envelope.getBody().hasFault());

thanks,
dims

On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
> Hi dims,
>
> Sure, but I'll warn you its in Jython so its not straight Java but
> pretty readable as is. # are single line comments just like the java //
>
>         #This handles the imports of the java stuff
>         from org.apache.commons.httpclient import *
>         from org.apache.commons.httpclient.methods import *
>         from java.io import File
>
>         # xmlfilename contains a complete SOAP Envelope and all the
> headers
>         xmlFilename = 'aSoapEnvelope.xml'
>         xmlData = File(xmlFilename)
>         length = xmlData.length()
>         url = "http://myserver.somewhere.com/services/Check.asmx"
>         soapAction = "http://GateWay/Services/Check/GetReportXml"
>
>         # setup the http client -- post method and http headers
>         post = PostMethod(url)
>         entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
>         post.addRequestHeader("Content-Length", str(length))
>         post.setRequestEntity(entity)
>         post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
>         post.addRequestHeader("User-Agent", "SQA_TestClient0")
>         post.setRequestHeader("SOAPAction", soapAction)
>
>         # every thing is set now fire it off.
>         # responseText is whatever the server sends back either
>         # a response containing soap fault or a one containing cdata
>         httpClient = HttpClient()
>         statusCode = httpClient.executeMethod(post)
>        if statusCode == HttpStatus.SC_OK:
>                 resultText = post.getResponseBodyAsString()
>        else:
>           # I'd like to check for soap fault here instead of a generic
>               # failure.
>               print " failure: " + post.getStatusLine().toString()
>
> Hope this helps
>
> Regards,
> Greg,
>
>
> -----Original Message-----
> From: Davanum Srinivas [mailto:davanum@gmail.com]
> Sent: Wednesday, August 01, 2007 9:11 AM
> To: axis-user@ws.apache.org
> Subject: Re: How to handle soap faults?
>
> Greg,
>
> Can you please post what you have so far?
>
> thanks,
> dims
>
>
>
> This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.
>


-- 
Davanum Srinivas :: http://davanum.wordpress.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: How to handle soap faults?

Posted by "Moore, Greg" <Gr...@adp.com>.
Hi dims,

Sure, but I'll warn you its in Jython so its not straight Java but
pretty readable as is. # are single line comments just like the java // 

        #This handles the imports of the java stuff
        from org.apache.commons.httpclient import *
        from org.apache.commons.httpclient.methods import *
        from java.io import File

        # xmlfilename contains a complete SOAP Envelope and all the
headers
        xmlFilename = 'aSoapEnvelope.xml'
        xmlData = File(xmlFilename)
        length = xmlData.length()
        url = "http://myserver.somewhere.com/services/Check.asmx"
        soapAction = "http://GateWay/Services/Check/GetReportXml"
        
        # setup the http client -- post method and http headers
        post = PostMethod(url)
        entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
        post.addRequestHeader("Content-Length", str(length))
        post.setRequestEntity(entity)
        post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
        post.addRequestHeader("User-Agent", "SQA_TestClient0")
        post.setRequestHeader("SOAPAction", soapAction)
        
        # every thing is set now fire it off.
        # responseText is whatever the server sends back either 
        # a response containing soap fault or a one containing cdata 
        httpClient = HttpClient()
        statusCode = httpClient.executeMethod(post)
       if statusCode == HttpStatus.SC_OK:
                resultText = post.getResponseBodyAsString()
       else:
	  # I'd like to check for soap fault here instead of a generic
              # failure.
              print " failure: " + post.getStatusLine().toString()

Hope this helps 

Regards,
Greg,


-----Original Message-----
From: Davanum Srinivas [mailto:davanum@gmail.com] 
Sent: Wednesday, August 01, 2007 9:11 AM
To: axis-user@ws.apache.org
Subject: Re: How to handle soap faults?

Greg,

Can you please post what you have so far?

thanks,
dims



This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to handle soap faults?

Posted by Davanum Srinivas <da...@gmail.com>.
Greg,

Can you please post what you have so far?

thanks,
dims

On 8/1/07, Moore, Greg <Gr...@adp.com> wrote:
> Hi,
>
> Done some searching of axis and other lists as well as google searches
> and I haven't come up with anything that explained what I am wondering
> about.
>
> I'm posting an xml file containing a soap envelope to a service and I
> get back a xml response that will either contain a soap fault or a CDATA
> element. I'm using apache commons HttpClient to do this.
>
> My question is it possible to use Axis to handle soap errors and/or
> faults using this method. If it is a pointer on how to do it brief
> example would be greatly appreciated.
>
> Thanks in Advance,
>
> Greg Moore
> QA Specialist IV
> Dealer Services
> ADP, Inc.
>
>
> This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Davanum Srinivas :: http://davanum.wordpress.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


How to handle soap faults?

Posted by "Moore, Greg" <Gr...@adp.com>.
Hi, 

Done some searching of axis and other lists as well as google searches
and I haven't come up with anything that explained what I am wondering
about. 

I'm posting an xml file containing a soap envelope to a service and I
get back a xml response that will either contain a soap fault or a CDATA
element. I'm using apache commons HttpClient to do this. 

My question is it possible to use Axis to handle soap errors and/or
faults using this method. If it is a pointer on how to do it brief
example would be greatly appreciated. 

Thanks in Advance,

Greg Moore
QA Specialist IV
Dealer Services
ADP, Inc.


This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


can I handle soap faults when using httpClient?

Posted by "Moore, Greg" <Gr...@adp.com>.
Hi, 

Done some searching of axis and other lists as well as google searches
and I haven't come up with anything that explained what I am wondering
about. Maybe some kind person will take pity on the confused. :) 

I'm posting an xml file containing a soap envelope to a service and I
get back a xml response that should contain a CDATA element. I'm using
apache commons HttpClient to do this. Below is the essential Jython code
that I'm using as an example similar to what I'm doing.  I originally
was trying to do this using Axis but after several days of trying was
never successful.

My question is it possible to use Axis to handle soap errors and/or
faults using the method below or do I have to parse xml or beat my head
against a wall until I figure out how to get the axis client to work.

        from org.apache.commons.httpclient import *
        from org.apache.commons.httpclient.methods import *
        from java.io import File

        xmlData = File(xmlFilename)
        length = xmlData.length()
        url = "http://myserver.somewhere.com/ services/Check.asmx"
        soapAction = "http://GateWay/Services/CreditCheck/GetReportXml"
        post = PostMethod(url)
        entity = FileRequestEntity(xmlData, "text/xml; charset=utf-8")
        post.addRequestHeader("Content-Length", str(length))
        post.setRequestEntity(entity)
        post.addRequestHeader("Content-type", "text/xml; charset=utf-8")
        post.addRequestHeader("User-Agent", "SQA_TestClient0")
        post.setRequestHeader("SOAPAction", soapAction)
        httpClient = HttpClient()
        statusCode = httpClient.executeMethod(post)
       if statusCode == HttpStatus.SC_OK:
                resultText = post.getResponseBodyAsString()
       else:
	  # I'd like to check for soap fault here instead of a generic
              # failure.
              print " failure: " + post.getStatusLine().toString()

Did I mention I was new to Axis? :)

Thanks in advance,
Greg Moore
Software QA
ADP, Inc.


This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org