Search in sources :

Example 1 with FaultDetailHeader

use of com.sun.xml.ws.message.FaultDetailHeader in project metro-jax-ws by eclipse-ee4j.

the class WsaServerTube method processRequest.

@Override
@NotNull
public NextAction processRequest(Packet request) {
    Message msg = request.getMessage();
    if (msg == null) {
        return doInvoke(next, request);
    }
    // hmm?
    // expose bunch of addressing related properties for advanced applications
    request.addSatellite(new WsaPropertyBag(addressingVersion, soapVersion, request));
    // Store request ReplyTo and FaultTo in requestPacket.invocationProperties
    // so that they can be used after responsePacket is received.
    // These properties are used if a fault is thrown from the subsequent Pipe/Tubes.
    MessageHeaders hl = request.getMessage().getHeaders();
    String msgId;
    try {
        replyTo = AddressingUtils.getReplyTo(hl, addressingVersion, soapVersion);
        faultTo = AddressingUtils.getFaultTo(hl, addressingVersion, soapVersion);
        msgId = AddressingUtils.getMessageID(hl, addressingVersion, soapVersion);
    } catch (InvalidAddressingHeaderException e) {
        LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText() + ", Problem header:" + e.getProblemHeader() + ", Reason: " + e.getSubsubcode(), e);
        // problematic header must be removed since it can fail during Fault message processing
        hl.remove(e.getProblemHeader());
        SOAPFault soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
        // WS-A fault processing for one-way methods
        if ((wsdlPort != null) && request.getMessage().isOneWay(wsdlPort)) {
            Packet response = request.createServerResponse(null, wsdlPort, null, binding);
            return doReturnWith(response);
        }
        Message m = Messages.create(soapFault);
        if (soapVersion == SOAPVersion.SOAP_11) {
            FaultDetailHeader s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
            m.getHeaders().add(s11FaultDetailHeader);
        }
        Packet response = request.createServerResponse(m, wsdlPort, null, binding);
        return doReturnWith(response);
    }
    // defaulting
    if (replyTo == null) {
        replyTo = addressingVersion.anonymousEpr;
    }
    if (faultTo == null) {
        faultTo = replyTo;
    }
    // Save a copy into the packet such that we can save it with that
    // packet if we're going to deliver the response at a later time
    // (async from the request).
    request.put(WsaPropertyBag.WSA_REPLYTO_FROM_REQUEST, replyTo);
    request.put(WsaPropertyBag.WSA_FAULTTO_FROM_REQUEST, faultTo);
    request.put(WsaPropertyBag.WSA_MSGID_FROM_REQUEST, msgId);
    wbo = getWSDLBoundOperation(request);
    isAnonymousRequired = isAnonymousRequired(wbo);
    Packet p = validateInboundHeaders(request);
    // then do no further processing
    if (p.getMessage() == null) {
        return doReturnWith(p);
    }
    // if we find an error in addressing header, just turn around the direction here
    if (p.getMessage().isFault()) {
        // we'll never use them
        if (isEarlyBackchannelCloseAllowed && !(isAnonymousRequired) && !faultTo.isAnonymous() && request.transportBackChannel != null) {
            request.transportBackChannel.close();
        }
        return processResponse(p);
    }
    // we'll never use them
    if (isEarlyBackchannelCloseAllowed && !(isAnonymousRequired) && !replyTo.isAnonymous() && !faultTo.isAnonymous() && request.transportBackChannel != null) {
        request.transportBackChannel.close();
    }
    return doInvoke(next, p);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) Message(com.sun.xml.ws.api.message.Message) FaultDetailHeader(com.sun.xml.ws.message.FaultDetailHeader) SOAPFault(jakarta.xml.soap.SOAPFault) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders) NotNull(com.sun.istack.NotNull)

Example 2 with FaultDetailHeader

use of com.sun.xml.ws.message.FaultDetailHeader in project metro-jax-ws by eclipse-ee4j.

the class WsaTube method validateInboundHeaders.

/**
 * Validates the inbound message. If an error is found, create
 * a fault message and returns that. Otherwise
 * it will pass through the parameter 'packet' object to the return value.
 */
protected Packet validateInboundHeaders(Packet packet) {
    SOAPFault soapFault;
    FaultDetailHeader s11FaultDetailHeader;
    try {
        checkMessageAddressingProperties(packet);
        return packet;
    } catch (InvalidAddressingHeaderException e) {
        LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText() + ", Problem header:" + e.getProblemHeader() + ", Reason: " + e.getSubsubcode(), e);
        soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
        s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
    } catch (MissingAddressingHeaderException e) {
        LOGGER.log(Level.WARNING, addressingVersion.getMapRequiredText() + ", Problem header:" + e.getMissingHeaderQName(), e);
        soapFault = helper.newMapRequiredFault(e);
        s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getMissingHeaderQName());
    }
    if (soapFault != null) {
        // WS-A fault processing for one-way methods
        if ((wsdlPort != null) && packet.getMessage().isOneWay(wsdlPort)) {
            return packet.createServerResponse(null, wsdlPort, null, binding);
        }
        Message m = Messages.create(soapFault);
        if (soapVersion == SOAPVersion.SOAP_11) {
            m.getHeaders().add(s11FaultDetailHeader);
        }
        return packet.createServerResponse(m, wsdlPort, null, binding);
    }
    return packet;
}
Also used : InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) MissingAddressingHeaderException(com.sun.xml.ws.addressing.model.MissingAddressingHeaderException) Message(com.sun.xml.ws.api.message.Message) FaultDetailHeader(com.sun.xml.ws.message.FaultDetailHeader) SOAPFault(jakarta.xml.soap.SOAPFault)

Aggregations

InvalidAddressingHeaderException (com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException)2 Message (com.sun.xml.ws.api.message.Message)2 FaultDetailHeader (com.sun.xml.ws.message.FaultDetailHeader)2 SOAPFault (jakarta.xml.soap.SOAPFault)2 NotNull (com.sun.istack.NotNull)1 MissingAddressingHeaderException (com.sun.xml.ws.addressing.model.MissingAddressingHeaderException)1 MessageHeaders (com.sun.xml.ws.api.message.MessageHeaders)1 Packet (com.sun.xml.ws.api.message.Packet)1