Search in sources :

Example 6 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RMSoapInInterceptor method unmarshalRMProperties.

/**
 * Decode the RM properties from protocol-specific headers.
 *
 * @param message the SOAP message
 * @return the RM properties
 */
public RMProperties unmarshalRMProperties(SoapMessage message) {
    RMProperties rmps = (RMProperties) message.get(RMContextUtils.getRMPropertiesKey(false));
    if (rmps == null) {
        rmps = new RMProperties();
    }
    List<Header> headers = message.getHeaders();
    if (headers != null) {
        decodeHeaders(message, headers, rmps);
    }
    return rmps;
}
Also used : Header(org.apache.cxf.headers.Header) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 7 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RMSoapInInterceptor method updateServiceModelInfo.

/**
 * When invoked inbound, check if the action indicates that this is one of the
 * RM protocol messages (CreateSequence, CreateSequenceResponse, TerminateSequence)
 * and if so, replace references to the application service model with references to
 * the RM service model.
 * The addressing protocol handler must have extracted the action beforehand.
 * @see org.apache.cxf.transport.ChainInitiationObserver
 *
 * @param message the message
 */
private void updateServiceModelInfo(SoapMessage message) throws Fault {
    AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
    AttributedURIType actionURI = null == maps ? null : maps.getAction();
    String action = null == actionURI ? null : actionURI.getValue().trim();
    LOG.fine("action: " + action);
    RMConstants consts;
    if (RM10Constants.ACTIONS.contains(action)) {
        consts = RM10Constants.INSTANCE;
    } else if (RM11Constants.ACTIONS.contains(action)) {
        consts = RM11Constants.INSTANCE;
    } else {
        return;
    }
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    rmps.exposeAs(consts.getWSRMNamespace());
    ProtocolVariation protocol = ProtocolVariation.findVariant(consts.getWSRMNamespace(), maps.getNamespaceURI());
    LOG.info("Updating service model info in exchange");
    RMManager manager = getManager(message);
    assert manager != null;
    RMEndpoint rme = null;
    try {
        rme = manager.getReliableEndpoint(message);
    } catch (RMException e) {
        throw new SoapFault(new org.apache.cxf.common.i18n.Message("CANNOT_PROCESS", LOG), e, message.getVersion().getSender());
    }
    Exchange exchange = message.getExchange();
    Endpoint ep = rme.getEndpoint(protocol);
    exchange.put(Endpoint.class, ep);
    exchange.put(Service.class, ep.getService());
    exchange.put(Binding.class, ep.getBinding());
    // Also set BindingOperationInfo as some operations (SequenceAcknowledgment) have
    // neither in nor out messages, and thus the WrappedInInterceptor cannot
    // determine the operation name.
    BindingInfo bi = ep.getEndpointInfo().getBinding();
    BindingOperationInfo boi = null;
    boolean isOneway = true;
    if (consts.getCreateSequenceAction().equals(action)) {
        if (RMContextUtils.isServerSide(message)) {
            boi = bi.getOperation(consts.getCreateSequenceOperationName());
            isOneway = false;
        } else {
            boi = bi.getOperation(consts.getCreateSequenceOnewayOperationName());
        }
    } else if (consts.getCreateSequenceResponseAction().equals(action)) {
        if (RMContextUtils.isServerSide(message)) {
            boi = bi.getOperation(consts.getCreateSequenceResponseOnewayOperationName());
        } else {
            boi = bi.getOperation(consts.getCreateSequenceOperationName());
            isOneway = false;
        }
    } else if (consts.getSequenceAckAction().equals(action)) {
        boi = bi.getOperation(consts.getSequenceAckOperationName());
    } else if (consts.getAckRequestedAction().equals(action)) {
        boi = bi.getOperation(consts.getAckRequestedOperationName());
    } else if (consts.getTerminateSequenceAction().equals(action)) {
        boi = bi.getOperation(consts.getTerminateSequenceOperationName());
    } else if (RM11Constants.INSTANCE.getTerminateSequenceResponseAction().equals(action)) {
        // TODO add server-side TSR handling
        boi = bi.getOperation(RM11Constants.INSTANCE.getTerminateSequenceOperationName());
        isOneway = false;
    } else if (consts.getCloseSequenceAction().equals(action)) {
        boi = bi.getOperation(consts.getCloseSequenceOperationName());
    } else if (RM11Constants.INSTANCE.getCloseSequenceResponseAction().equals(action)) {
        boi = bi.getOperation(RM11Constants.INSTANCE.getCloseSequenceOperationName());
        isOneway = false;
    }
    // make sure the binding information has been set
    if (boi == null) {
        LOG.fine("No BindingInfo for action " + action);
    } else {
        exchange.put(BindingOperationInfo.class, boi);
        exchange.setOneWay(isOneway);
    }
    if (!consts.getCreateSequenceResponseAction().equals(action) && !consts.getSequenceAckAction().equals(action) && !RM11Constants.INSTANCE.getTerminateSequenceResponseAction().equals(action) && !RM11Constants.INSTANCE.getCloseSequenceResponseAction().equals(action)) {
        LOG.fine("Changing requestor role from " + message.get(Message.REQUESTOR_ROLE) + " to false");
        Object originalRequestorRole = message.get(Message.REQUESTOR_ROLE);
        if (null != originalRequestorRole) {
            message.put(RMMessageConstants.ORIGINAL_REQUESTOR_ROLE, originalRequestorRole);
        }
        message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
    }
    // replace WrappedInInterceptor with BareInInterceptor if necessary
    // as RM protocol messages use parameter style BARE
    InterceptorChain chain = message.getInterceptorChain();
    ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
    boolean bareIn = false;
    boolean wrappedIn = false;
    while (it.hasNext() && !wrappedIn && !bareIn) {
        PhaseInterceptor<? extends Message> pi = (PhaseInterceptor<? extends Message>) it.next();
        if (BareInInterceptor.class.getName().equals(pi.getId())) {
            bareIn = true;
        }
    }
    if (!bareIn) {
        chain.add(new BareInInterceptor());
        LOG.fine("Added BareInInterceptor to chain.");
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) RMConstants(org.apache.cxf.ws.rm.RMConstants) RMEndpoint(org.apache.cxf.ws.rm.RMEndpoint) RMException(org.apache.cxf.ws.rm.RMException) RMEndpoint(org.apache.cxf.ws.rm.RMEndpoint) Endpoint(org.apache.cxf.endpoint.Endpoint) RMManager(org.apache.cxf.ws.rm.RMManager) BindingInfo(org.apache.cxf.service.model.BindingInfo) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) AbstractRMInterceptor(org.apache.cxf.ws.rm.AbstractRMInterceptor) AbstractSoapInterceptor(org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) RMProperties(org.apache.cxf.ws.rm.RMProperties) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation) Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain)

Example 8 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RMSoapOutInterceptor method encodeFault.

/**
 * Encode the SequenceFault in protocol-specific header.
 *
 * @param message the SOAP message.
 * @param sf the SequenceFault.
 */
public static void encodeFault(SoapMessage message, SequenceFault sf) {
    LOG.log(Level.FINE, "Encoding SequenceFault in SOAP header");
    try {
        Message inmsg = message.getExchange().getInMessage();
        RMProperties rmps = RMContextUtils.retrieveRMProperties(inmsg, false);
        AddressingProperties maps = RMContextUtils.retrieveMAPs(inmsg, false, false);
        ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI());
        Header header = protocol.getCodec().buildHeaderFault(sf);
        List<Header> headers = message.getHeaders();
        headers.add(header);
    } catch (JAXBException je) {
        LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je);
    }
}
Also used : Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Header(org.apache.cxf.headers.Header) JAXBException(javax.xml.bind.JAXBException) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) RMProperties(org.apache.cxf.ws.rm.RMProperties) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation)

Example 9 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RMSoapOutInterceptorTest method setupOutboundMessage.

private SoapMessage setupOutboundMessage() throws Exception {
    Exchange ex = new ExchangeImpl();
    Message message = new MessageImpl();
    SoapMessage soapMessage = new SoapMessage(message);
    RMProperties rmps = new RMProperties();
    rmps.exposeAs(RM10Constants.NAMESPACE_URI);
    RMContextUtils.storeRMProperties(soapMessage, rmps, true);
    AddressingProperties maps = new AddressingProperties();
    RMContextUtils.storeMAPs(maps, soapMessage, true, false);
    ex.setOutMessage(soapMessage);
    soapMessage.setExchange(ex);
    MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    SOAPMessage soap = factory.createMessage();
    QName bodyName = new QName("http://cxf.apache.org", "dummy", "d");
    soap.getSOAPBody().addBodyElement(bodyName);
    soapMessage.setContent(SOAPMessage.class, soap);
    return soapMessage;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) MessageImpl(org.apache.cxf.message.MessageImpl) SOAPMessage(javax.xml.soap.SOAPMessage) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) RMProperties(org.apache.cxf.ws.rm.RMProperties) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 10 with RMProperties

use of org.apache.cxf.ws.rm.RMProperties in project cxf by apache.

the class RetransmissionQueueImplTest method setUpSequenceType.

private SequenceType setUpSequenceType(Message message, String sid, Long messageNumber) {
    RMProperties rmps = createMock(RMProperties.class);
    if (message != null) {
        message.get(RMMessageConstants.RM_PROPERTIES_OUTBOUND);
        EasyMock.expectLastCall().andReturn(rmps);
    }
    properties.add(rmps);
    SequenceType sequence = createMock(SequenceType.class);
    if (message != null) {
        rmps.getSequence();
        EasyMock.expectLastCall().andReturn(sequence);
    }
    if (messageNumber != null) {
        EasyMock.expect(sequence.getMessageNumber()).andReturn(messageNumber).anyTimes();
    }
    Identifier id = createMock(Identifier.class);
    EasyMock.expect(sequence.getIdentifier()).andReturn(id).anyTimes();
    EasyMock.expect(id.getValue()).andReturn(sid).anyTimes();
    identifiers.add(id);
    sequences.add(sequence);
    return sequence;
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Aggregations

RMProperties (org.apache.cxf.ws.rm.RMProperties)25 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)12 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)11 Message (org.apache.cxf.message.Message)10 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 Test (org.junit.Test)6 Endpoint (org.apache.cxf.endpoint.Endpoint)5 MessageImpl (org.apache.cxf.message.MessageImpl)4 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)4 SoapFault (org.apache.cxf.binding.soap.SoapFault)3 Exchange (org.apache.cxf.message.Exchange)3 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)3 RMEndpoint (org.apache.cxf.ws.rm.RMEndpoint)3 RMException (org.apache.cxf.ws.rm.RMException)3 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 MessageFactory (javax.xml.soap.MessageFactory)2 SOAPMessage (javax.xml.soap.SOAPMessage)2