Need help returning a SOAP Fault using JAX_WS, NetBeans, WSDL

I am new to Web Services and have been trying to get SOAP Faults to work for days (going nuts here).  If there is no error to throw then things are working just fine.  To make my problem clear I have created a very simple test WSDL file and created a new project in NetBeans 6.7.  I then built a new Web Service from the WSDL file.  I then put in some very simple logic to either throw an error or not.  The service takes a String for input.  If it is passed ‘error’ it will throw an error, otherwise it will return instructions.  I built and deployed this simple service to Sun GlassFish Enterprise Server v2.1.  The service works fine, however when it throws an error I don’t get a nicely formatted XML SOAP Fault like I want, I just get a long list of errors.

Someone please tell me what I am doing wrong and how to fix this.  I will then apply this knowledge to my project.

You will find the Java logic attached.  Cheers
<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://www.example.org/TestWSDLFile/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TestWSDLFile"
    targetNamespace="http://www.example.org/TestWSDLFile/">
    <wsdl:types>
        <xsd:schema targetNamespace="http://www.example.org/TestWSDLFile/">
            <xsd:element name="NewOperation">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="in" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="NewOperationResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="out" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="NewOperationFault">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="ErrorMessage" type="xsd:string"> </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="NewOperationRequest">
        <wsdl:part element="tns:NewOperation" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="NewOperationResponse">
        <wsdl:part element="tns:NewOperationResponse" name="parameters"/>
    </wsdl:message>
    <wsdl:message name="FaultResponse">
        <wsdl:part name="parameters" element="tns:NewOperationFault"/>
    </wsdl:message>
    <wsdl:portType name="TestWSDLFile">
        <wsdl:operation name="NewOperation">
            <wsdl:input message="tns:NewOperationRequest"/>
            <wsdl:output message="tns:NewOperationResponse"/>
            <wsdl:fault name="FaultResponse" message="tns:FaultResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="TestWSDLFileSOAP" type="tns:TestWSDLFile">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="NewOperation">
            <soap:operation soapAction="http://www.example.org/TestWSDLFile/NewOperation"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="FaultResponse">
                <soap:fault use="literal" name="FaultResponse"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="TestWSDLFile">
        <wsdl:port binding="tns:TestWSDLFileSOAP" name="TestWSDLFileSOAP">
            <soap:address location="http://www.example.org/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Open in new window

WebServiceFromWSDL.java
LVL 1
stevenkerrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stevenkerrAuthor Commented:
To answer this question you need to look at the short attached Java file and see if it is correct for returning a SOAP fault for the above WSDL.  That's all.  For a better look, create a new project and build a web service from the WSDL file.  This will take about a minute.  Cheers
0
stevenkerrAuthor Commented:
I have concluded that SOAP Faults are not very well supported and are not necessary.  If you are stuck like me I suggest you build fault messages into the standard payload and forget SOAP Faults.

Here is some discussion
http://www.infoq.com/articles/lublinsky-soa-exception

I will leave this question open if someone would like to post a solution.  Otherwise, moderator, please close this question.  Cheers
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Thats not a better way, don't embed fault messages in the SOAP messages, give them back as SOAP Faults only.

you were ideally suppose to throw back a javax.xml.ws.soap.SOAPFaultException

any way read this nice article

http://www.ibm.com/developerworks/webservices/library/ws-jaxws-faults/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Infact if i am not wrong you through any kind of exception, JAXWS engine use to wrap it as a soap fault, try that to, with appropriate exception message.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.