FileDocCategorySizeDatePackage
WsaHelper.javaAPI DocExample7553Tue May 29 16:57:16 BST 2007com.sun.xml.ws.tx.common

WsaHelper

public class WsaHelper extends Object
WS-Addressing helper methods.
author
Ryan.Shoemaker@Sun.COM

Fields Summary
Constructors Summary
Methods Summary
static javax.xml.soap.SOAPFaultcreateFault(com.sun.xml.ws.api.SOAPVersion soapVer, TxFault fault, java.lang.String message)
Create a SOAPFault from the specified information.

param
soapVer soap version
param
fault fault enum
param
message message
return
the new SOAPFault

        try {
            final SOAPFactory soapFactory = soapVer.saajSoapFactory;
            final SOAPFault soapFault = soapFactory.createFault();
 
            if (soapVer == SOAPVersion.SOAP_11) {
                soapFault.setFaultCode(fault.subcode);
                soapFault.setFaultString(fault.reason + ": " + message, Locale.ENGLISH);
            } else { // SOAP 1.2
                soapFault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
                soapFault.appendFaultSubcode(fault.subcode);
                soapFault.setFaultString(fault.reason + ": " + message, Locale.ENGLISH);
            }
            return soapFault;
        } catch (SOAPException e) {
            throw new WebServiceException(e);
        }
    
public static com.sun.xml.ws.api.addressing.WSEndpointReferencegetFaultTo(javax.xml.ws.WebServiceContext wsContext)

        HeaderList headers = getInboundHeaderList(wsContext);
        return headers.getFaultTo(AddressingVersion.MEMBER, SOAPVersion.SOAP_11);
    
static com.sun.xml.ws.api.message.HeaderListgetInboundHeaderList(javax.xml.ws.WebServiceContext wsContext)

        MessageContext msgContext = wsContext.getMessageContext();
        return (HeaderList) msgContext.get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
    
public static java.lang.StringgetMsgID(javax.xml.ws.WebServiceContext wsContext)

        HeaderList headers = getInboundHeaderList(wsContext);
        return headers.getMessageID(AddressingVersion.MEMBER, SOAPVersion.SOAP_11);
    
public static javax.xml.ws.EndpointReferencegetReplyTo(javax.xml.ws.WebServiceContext wsContext)

        HeaderList headers = getInboundHeaderList(wsContext);
        return (headers.getReplyTo(AddressingVersion.MEMBER, SOAPVersion.SOAP_11)).toSpec();
    
public static voidsendFault(com.sun.xml.ws.api.addressing.WSEndpointReference faultTo, javax.xml.ws.EndpointReference replyTo, com.sun.xml.ws.api.SOAPVersion soapVer, TxFault fault, java.lang.String message, java.lang.String msgID)
Dispatch a fault, adding any necessary headers to 'fault' in the process.

param
faultTo
param
replyTo
param
soapVer
param
fault
param
message
param
msgID


        final WSEndpointReference to = faultTo != null ? faultTo : new WSEndpointReference(replyTo);

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

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

        final Dispatch<Source> d = s.createDispatch(port, to, Source.class, Service.Mode.PAYLOAD, owf, af);
        d.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
        d.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, fault.actionURI);
        
        d.invokeOneWay(new DOMSource(createFault(soapVer, fault, message)));
    
public static voidsendFault(javax.xml.ws.WebServiceContext wsContext, com.sun.xml.ws.api.SOAPVersion soapVer, TxFault fault, java.lang.String message)


        String msgID = WsaHelper.getMsgID(wsContext);
        EndpointReference replyTo = WsaHelper.getReplyTo(wsContext);
        WSEndpointReference faultTo = WsaHelper.getFaultTo(wsContext);

        sendFault(faultTo, replyTo, soapVer, fault, message, msgID);