Search in sources :

Example 1 with BareInInterceptor

use of org.apache.cxf.wsdl.interceptors.BareInInterceptor in project cxf by apache.

the class CorbaBindingFactory method createBinding.

public Binding createBinding(BindingInfo bindingInfo) {
    CorbaBinding binding = new CorbaBinding();
    binding.getInFaultInterceptors().add(new CorbaStreamFaultInInterceptor());
    binding.getOutFaultInterceptors().add(new CorbaStreamFaultOutInterceptor());
    binding.getOutInterceptors().add(new BareOutInterceptor());
    binding.getOutInterceptors().add(new CorbaStreamOutInterceptor());
    binding.getInInterceptors().add(new BareInInterceptor());
    binding.getInInterceptors().add(new CorbaStreamInInterceptor());
    binding.setBindingInfo(bindingInfo);
    return binding;
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) CorbaStreamInInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamInInterceptor) CorbaStreamFaultInInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultInInterceptor) CorbaStreamFaultOutInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultOutInterceptor) CorbaStreamOutInterceptor(org.apache.cxf.binding.corba.interceptors.CorbaStreamOutInterceptor) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor)

Example 2 with BareInInterceptor

use of org.apache.cxf.wsdl.interceptors.BareInInterceptor in project cxf by apache.

the class RPCInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message)) {
        LOG.fine("RPCInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    if (!StaxUtils.toNextElement(xmlReader)) {
        message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
    }
    String opName = xmlReader.getLocalName();
    if (isRequestor(message) && opName.endsWith("Response")) {
        opName = opName.substring(0, opName.length() - 8);
    }
    final BindingOperationInfo operation;
    if (message.getExchange().getBindingOperationInfo() == null) {
        operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
        if (operation == null) {
            // it's doc-lit-bare
            new BareInInterceptor().handleMessage(message);
            return;
        }
        setMessage(message, operation);
    } else {
        operation = message.getExchange().getBindingOperationInfo();
        if (!operation.getName().getLocalPart().equals(opName)) {
            String sa = (String) message.get(SoapBindingConstants.SOAP_ACTION);
            throw new Fault("SOAP_ACTION_MISMATCH_OP", LOG, null, sa, opName);
        }
    }
    MessageInfo msg;
    DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
    if (!isRequestor(message)) {
        msg = operation.getOperationInfo().getInput();
    } else {
        msg = operation.getOperationInfo().getOutput();
    }
    message.put(MessageInfo.class, msg);
    MessageContentsList parameters = new MessageContentsList();
    StaxUtils.nextEvent(xmlReader);
    boolean hasNext = true;
    Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
    while (itr.hasNext()) {
        MessagePartInfo part = itr.next();
        if (hasNext) {
            hasNext = StaxUtils.toNextElement(xmlReader);
        }
        if (hasNext) {
            QName qn = xmlReader.getName();
            if (qn.equals(SOAP12_RESULT)) {
                // just ignore this.   The parts should work correctly.
                try {
                    while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                        xmlReader.next();
                    }
                    xmlReader.next();
                } catch (XMLStreamException e) {
                // ignore
                }
                StaxUtils.toNextElement(xmlReader);
                qn = xmlReader.getName();
            }
            // WSI-BP states that RPC/Lit part accessors should be completely unqualified
            // However, older toolkits (Axis 1.x) are qualifying them.   We'll go
            // ahead and just match on the localpart.   The RPCOutInterceptor
            // will always generate WSI-BP compliant messages so it's unknown if
            // the non-WSI-BP toolkits will be able to understand the CXF
            // generated messages if they are expecting it to be qualified.
            Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
            while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
                part = partItr.next();
            }
            // only check the localpart as explained above
            if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
            }
            try {
                parameters.put(part, dr.read(part, xmlReader));
            } catch (Fault f) {
                if (!isRequestor(message)) {
                    f.setFaultCode(Fault.FAULT_CODE_CLIENT);
                }
                throw f;
            }
        }
    }
    message.setContent(List.class, parameters);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor)

Example 3 with BareInInterceptor

use of org.apache.cxf.wsdl.interceptors.BareInInterceptor 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;
    final RMEndpoint rme;
    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 4 with BareInInterceptor

use of org.apache.cxf.wsdl.interceptors.BareInInterceptor in project cxf by apache.

the class BareInInterceptorTest method testInterceptorInbound1.

@Test
public void testInterceptorInbound1() throws Exception {
    setUpUsingDocLit();
    BareInInterceptor interceptor = new BareInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/sayHiDocLitBareReq.xml")));
    message.put(Message.INBOUND_MESSAGE, Message.INBOUND_MESSAGE);
    interceptor.handleMessage(message);
    assertNull(message.getContent(Exception.class));
    List<?> parameters = message.getContent(List.class);
    assertEquals(1, parameters.size());
    Object obj = parameters.get(0);
    assertTrue(obj instanceof TradePriceData);
    TradePriceData greet = (TradePriceData) obj;
    assertTrue(1.0 == greet.getTickerPrice());
    assertEquals("CXF", greet.getTickerSymbol());
}
Also used : TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) Test(org.junit.Test)

Example 5 with BareInInterceptor

use of org.apache.cxf.wsdl.interceptors.BareInInterceptor in project cxf by apache.

the class BareInInterceptorTest method testInterceptorOutbound.

@Test
public void testInterceptorOutbound() throws Exception {
    setUpUsingHelloWorld();
    BareInInterceptor interceptor = new BareInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/GreetMeDocLiteralResp.xml")));
    message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    interceptor.handleMessage(message);
    List<?> parameters = message.getContent(List.class);
    assertEquals(1, parameters.size());
    Object obj = parameters.get(0);
    assertTrue(obj instanceof GreetMeResponse);
    GreetMeResponse greet = (GreetMeResponse) obj;
    assertEquals("TestSOAPOutputPMessage", greet.getResponseType());
}
Also used : GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) Test(org.junit.Test)

Aggregations

BareInInterceptor (org.apache.cxf.wsdl.interceptors.BareInInterceptor)7 Test (org.junit.Test)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 CorbaStreamFaultInInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultInInterceptor)1 CorbaStreamFaultOutInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamFaultOutInterceptor)1 CorbaStreamInInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamInInterceptor)1 CorbaStreamOutInterceptor (org.apache.cxf.binding.corba.interceptors.CorbaStreamOutInterceptor)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 AbstractSoapInterceptor (org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 Fault (org.apache.cxf.interceptor.Fault)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)1 Exchange (org.apache.cxf.message.Exchange)1 Message (org.apache.cxf.message.Message)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1