dev@jax-ws.java.net

Re: SOAPFault headers? (and SOAPFault in general)

From: Ryan Shoemaker - JavaSoft East <Ryan.Shoemaker_at_Sun.COM>
Date: Mon, 18 Dec 2006 15:40:49 -0500

Arun Gupta wrote:
> Ryan,
>
> See in line ...
>
>>>> One final question: suppose that I want to dispatch a SOAPFault to
>>>> an EPR
>>>
>>> What do you mean by dispatching a fault to an EPR ?
>>
>> My wsdl is full of one-way operations that do not specify any faults.
>> For
>> example:
>>
>> <wsdl:portType name="RegistrationCoordinatorPortType">
>> <wsdl:operation name="RegisterOperation">
>> <wsdl:input message="wscoor:Register"
>>
>> wsa:Action="http://schemas.xmlsoap.org/ws/2004/10/wscoor/Register"/>
>> </wsdl:operation>
>> </wsdl:portType>
>>
>> The implementation of this operation is required to send faults under
>> certain
>> error conditions, but I can't throw SOAPFaultException since it's
>> one-way.
>>
>> Everyone else I've spoke with about this says that I need to use
>> Dispatch to
>> send the fault. I'm currently trying something like this (but the code
> That seems the right thing to do.
>
>

Arun,

Here is the latest code and resulting fault. I'm still not seeing any
WS-A headers - can you advise?

--Ryan


<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Header>
     <jaxws:objectId xmlns:jaxws="http://jax-ws.dev.java.net/xml/ns/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">305d682b-f1fb-4b8f-936d-a4805835b34f</jaxws:objectId>
   </S:Header>
   <S:Body>
     <SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
       <faultcode xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wscoor="http://schemas.xmlsoap.org/ws/2004/10/wscoor">wscoor:InvalidParameters</faultcode>
       <faultstring xml:lang="en">The message contained invalid parameters and could not be processed: foo</faultstring>
     </SOAP-ENV:Fault>
   </S:Body>
</S:Envelope>


public static void sendFault(@Nullable WSEndpointReference faultTo, @NotNull EndpointReference replyTo,
                              @NotNull SOAPFault fault, String msgID) {
     WSEndpointReference to = faultTo != null ? faultTo : new WSEndpointReference(replyTo);

     WSService s = WSService.create();
     final QName port = new QName("foo", "bar");
     s.addPort(port, SOAPBinding.SOAP11HTTP_BINDING, to.getAddress());

     // one-way feature
     OneWayFeature owf = new OneWayFeature();
     owf.setRelatesToID(msgID);
     // member submission addressing feature
     WebServiceFeature af = new MemberSubmissionAddressingFeature(true);

     Dispatch<Source> d = s.createDispatch(port, to, Source.class, Service.Mode.PAYLOAD, owf, af);
     d.invokeOneWay(new DOMSource(fault));
}