Search in sources :

Example 1 with InvalidAddressingHeaderException

use of com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.

the class W3CWsaServerTube method checkAnonymousSemantics.

@Override
protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
    String replyToValue = null;
    String faultToValue = null;
    if (replyTo != null)
        replyToValue = replyTo.getAddress();
    if (faultTo != null)
        faultToValue = faultTo.getAddress();
    WSDLBoundOperation.ANONYMOUS responseRequirement = getResponseRequirement(wbo);
    switch(responseRequirement) {
        case prohibited:
            if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri))
                throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, W3CAddressingConstants.ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
            if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri))
                throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, W3CAddressingConstants.ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
            break;
        case required:
            if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri))
                throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, W3CAddressingConstants.ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
            if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri))
                throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, W3CAddressingConstants.ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
            break;
        default:
    }
}
Also used : InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)

Example 2 with InvalidAddressingHeaderException

use of com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException 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 3 with InvalidAddressingHeaderException

use of com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.

the class WsaTube method checkCardinality.

/**
 * Checks the cardinality of WS-Addressing headers on an inbound {@link Packet}. This method
 * checks for the cardinality if WS-Addressing is engaged (detected by the presence of wsa:Action
 * header) or wsdl:required=true.
 *
 * @param packet The inbound packet.
 * @throws WebServiceException if:
 * <ul>
 * <li>there is an error reading ReplyTo or FaultTo</li>
 * <li>WS-Addressing is required and {@link Message} within <code>packet</code> is null</li>
 * <li>WS-Addressing is required and no headers are found in the {@link Message}</li>
 * <li>an uknown WS-Addressing header is present</li>
 * </ul>
 */
protected void checkCardinality(Packet packet) {
    Message message = packet.getMessage();
    if (message == null) {
        if (addressingRequired)
            throw new WebServiceException(AddressingMessages.NULL_MESSAGE());
        else
            return;
    }
    Iterator<Header> hIter = message.getHeaders().getHeaders(addressingVersion.nsUri, true);
    if (!hIter.hasNext()) {
        // no WS-A headers are found
        if (addressingRequired)
            // if WS-A is required, then throw an exception looking for wsa:Action header
            throw new MissingAddressingHeaderException(addressingVersion.actionTag, packet);
        else
            // else no need to process
            return;
    }
    boolean foundFrom = false;
    boolean foundTo = false;
    boolean foundReplyTo = false;
    boolean foundFaultTo = false;
    boolean foundAction = false;
    boolean foundMessageId = false;
    boolean foundRelatesTo = false;
    QName duplicateHeader = null;
    while (hIter.hasNext()) {
        Header h = hIter.next();
        // check if the Header is in current role
        if (!isInCurrentRole(h, binding)) {
            continue;
        }
        String local = h.getLocalPart();
        if (local.equals(addressingVersion.fromTag.getLocalPart())) {
            if (foundFrom) {
                duplicateHeader = addressingVersion.fromTag;
                break;
            }
            foundFrom = true;
        } else if (local.equals(addressingVersion.toTag.getLocalPart())) {
            if (foundTo) {
                duplicateHeader = addressingVersion.toTag;
                break;
            }
            foundTo = true;
        } else if (local.equals(addressingVersion.replyToTag.getLocalPart())) {
            if (foundReplyTo) {
                duplicateHeader = addressingVersion.replyToTag;
                break;
            }
            foundReplyTo = true;
            try {
                // verify that the header is in a good shape
                h.readAsEPR(addressingVersion);
            } catch (XMLStreamException e) {
                throw new WebServiceException(AddressingMessages.REPLY_TO_CANNOT_PARSE(), e);
            }
        } else if (local.equals(addressingVersion.faultToTag.getLocalPart())) {
            if (foundFaultTo) {
                duplicateHeader = addressingVersion.faultToTag;
                break;
            }
            foundFaultTo = true;
            try {
                // verify that the header is in a good shape
                h.readAsEPR(addressingVersion);
            } catch (XMLStreamException e) {
                throw new WebServiceException(AddressingMessages.FAULT_TO_CANNOT_PARSE(), e);
            }
        } else if (local.equals(addressingVersion.actionTag.getLocalPart())) {
            if (foundAction) {
                duplicateHeader = addressingVersion.actionTag;
                break;
            }
            foundAction = true;
        } else if (local.equals(addressingVersion.messageIDTag.getLocalPart())) {
            if (foundMessageId) {
                duplicateHeader = addressingVersion.messageIDTag;
                break;
            }
            foundMessageId = true;
        } else if (local.equals(addressingVersion.relatesToTag.getLocalPart())) {
            foundRelatesTo = true;
        } else if (local.equals(addressingVersion.faultDetailTag.getLocalPart())) {
        // TODO: should anything be done here ?
        // TODO: fault detail element - only for SOAP 1.1
        } else {
            System.err.println(AddressingMessages.UNKNOWN_WSA_HEADER());
        }
    }
    // check for invalid cardinality first before checking for mandatory headers
    if (duplicateHeader != null) {
        throw new InvalidAddressingHeaderException(duplicateHeader, addressingVersion.invalidCardinalityTag);
    }
    // WS-A is engaged if wsa:Action header is found
    boolean engaged = foundAction;
    // response messages (for oneway and request/response MEP only)
    if (engaged || addressingRequired) {
        // Check for mandatory headers always (even for Protocol messages).
        // If it breaks any interop scenarios, Remove the comments.
        /*
            WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
            // no need to check for for non-application messages
            if (wbo == null)
                return;
            */
        checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo, foundFaultTo, foundMessageId, foundRelatesTo);
    }
}
Also used : InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) Message(com.sun.xml.ws.api.message.Message) WebServiceException(jakarta.xml.ws.WebServiceException) Header(com.sun.xml.ws.api.message.Header) FaultDetailHeader(com.sun.xml.ws.message.FaultDetailHeader) MissingAddressingHeaderException(com.sun.xml.ws.addressing.model.MissingAddressingHeaderException) XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName)

Example 4 with InvalidAddressingHeaderException

use of com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.

the class WSEndpointReference method parse.

/**
 * Parses inside EPR and mark all reference parameters.
 */
private void parse() throws XMLStreamException {
    // TODO: validate the EPR structure.
    // check for non-existent Address, that sort of things.
    StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
    // parser should be either at the start element or the start document
    if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT) {
        xsr.nextTag();
    }
    assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
    String rootLocalName = xsr.getLocalName();
    if (!xsr.getNamespaceURI().equals(version.nsUri)) {
        throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(version.nsUri, xsr.getNamespaceURI()));
    }
    this.rootElement = new QName(xsr.getNamespaceURI(), rootLocalName);
    // since often EPR doesn't have a reference parameter, create array lazily
    List<Header> marks = null;
    while (xsr.nextTag() == XMLStreamReader.START_ELEMENT) {
        String localName = xsr.getLocalName();
        if (version.isReferenceParameter(localName)) {
            XMLStreamBuffer mark;
            while ((mark = xsr.nextTagAndMark()) != null) {
                if (marks == null) {
                    marks = new ArrayList<>();
                }
                // TODO: need a different header for member submission version
                marks.add(version.createReferenceParameterHeader(mark, xsr.getNamespaceURI(), xsr.getLocalName()));
                XMLStreamReaderUtil.skipElement(xsr);
            }
        } else if (localName.equals("Address")) {
            if (address != null) {
                throw new InvalidAddressingHeaderException(new QName(version.nsUri, rootLocalName), AddressingVersion.fault_duplicateAddressInEpr);
            }
            address = xsr.getElementText().trim();
        } else {
            XMLStreamReaderUtil.skipElement(xsr);
        }
    }
    if (marks == null) {
        this.referenceParameters = EMPTY_ARRAY;
    } else {
        this.referenceParameters = marks.toArray(new Header[0]);
    }
    if (address == null) {
        throw new InvalidAddressingHeaderException(new QName(version.nsUri, rootLocalName), version.fault_missingAddressInEpr);
    }
}
Also used : InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) WebServiceException(jakarta.xml.ws.WebServiceException) Header(com.sun.xml.ws.api.message.Header) QName(javax.xml.namespace.QName) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) StreamReaderBufferProcessor(com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor)

Example 5 with InvalidAddressingHeaderException

use of com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException 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)5 Message (com.sun.xml.ws.api.message.Message)3 FaultDetailHeader (com.sun.xml.ws.message.FaultDetailHeader)3 MissingAddressingHeaderException (com.sun.xml.ws.addressing.model.MissingAddressingHeaderException)2 Header (com.sun.xml.ws.api.message.Header)2 SOAPFault (jakarta.xml.soap.SOAPFault)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 QName (javax.xml.namespace.QName)2 NotNull (com.sun.istack.NotNull)1 MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)1 XMLStreamBuffer (com.sun.xml.stream.buffer.XMLStreamBuffer)1 StreamReaderBufferProcessor (com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor)1 MessageHeaders (com.sun.xml.ws.api.message.MessageHeaders)1 Packet (com.sun.xml.ws.api.message.Packet)1 WSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)1 XMLStreamException (javax.xml.stream.XMLStreamException)1