Search in sources :

Example 61 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class JAXWSMethodInvokerTest method testFaultHeadersCopy.

@Test
public void testFaultHeadersCopy() throws Throwable {
    ExceptionService serviceObject = new ExceptionService();
    Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[] {});
    Exchange ex = new ExchangeImpl();
    prepareInMessage(ex, true);
    Message msg = new MessageImpl();
    SoapMessage outMessage = new SoapMessage(msg);
    ex.setOutMessage(outMessage);
    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] {}));
        fail("Expected fault");
    } catch (Fault fault) {
        Message outMsg = ex.getOutMessage();
        Assert.assertNotNull(outMsg);
        @SuppressWarnings("unchecked") List<Header> headers = (List<Header>) outMsg.get(Header.HEADER_LIST);
        Assert.assertEquals(1, headers.size());
        Assert.assertEquals(TEST_HEADER_NAME, headers.get(0).getName());
    }
}
Also used : Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) MessageContentsList(org.apache.cxf.message.MessageContentsList) Fault(org.apache.cxf.interceptor.Fault) Method(java.lang.reflect.Method) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Exchange(org.apache.cxf.message.Exchange) Header(org.apache.cxf.headers.Header) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 62 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class LogicalMessageImplTest method testGetPayloadOfJAXB.

@Test
public void testGetPayloadOfJAXB() throws Exception {
    // using Dispatch
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
    Message message = new MessageImpl();
    Exchange e = new ExchangeImpl();
    message.setExchange(e);
    LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
    JAXBElement<AddNumbers> el = new ObjectFactory().createAddNumbers(req);
    LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
    lmi.setPayload(el, ctx);
    Object obj = lmi.getPayload(ctx);
    assertTrue(obj instanceof JAXBElement);
    JAXBElement<?> el2 = (JAXBElement<?>) obj;
    assertTrue(el2.getValue() instanceof AddNumbers);
    AddNumbers resp = (AddNumbers) el2.getValue();
    assertEquals(req.getArg0(), resp.getArg0());
    assertEquals(req.getArg1(), resp.getArg1());
}
Also used : Message(org.apache.cxf.message.Message) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Exchange(org.apache.cxf.message.Exchange) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) MessageImpl(org.apache.cxf.message.MessageImpl) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 63 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class SOAPHandlerInterceptorTest method testGetUnderstoodHeadersReturnsNull.

@Test
public void testGetUnderstoodHeadersReturnsNull() {
    @SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
    list.add(new SOAPHandler<SOAPMessageContext>() {

        public boolean handleMessage(SOAPMessageContext smc) {
            return true;
        }

        public boolean handleFault(SOAPMessageContext smc) {
            return true;
        }

        public Set<QName> getHeaders() {
            return null;
        }

        public void close(MessageContext messageContext) {
        }
    });
    HandlerChainInvoker invoker = new HandlerChainInvoker(list);
    IMocksControl control = createNiceControl();
    Binding binding = control.createMock(Binding.class);
    expect(binding.getHandlerChain()).andReturn(list).anyTimes();
    SoapMessage message = control.createMock(SoapMessage.class);
    Exchange exchange = control.createMock(Exchange.class);
    expect(message.getExchange()).andReturn(exchange).anyTimes();
    expect(message.keySet()).andReturn(new HashSet<>());
    expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
    control.replay();
    SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
    Set<QName> understood = li.getUnderstoodHeaders();
    assertNotNull(understood);
    assertTrue(understood.isEmpty());
}
Also used : Binding(javax.xml.ws.Binding) Set(java.util.Set) HashSet(java.util.HashSet) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) SOAPHandler(javax.xml.ws.handler.soap.SOAPHandler) Handler(javax.xml.ws.handler.Handler) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) Test(org.junit.Test)

Example 64 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class SOAPHandlerInterceptor method createProtocolMessageContext.

@Override
protected MessageContext createProtocolMessageContext(SoapMessage message) {
    SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);
    Exchange exch = message.getExchange();
    setupBindingOperationInfo(exch, sm);
    SOAPMessage msg = sm.getMessage();
    if (msg != null) {
        try {
            List<SOAPElement> params = new ArrayList<>();
            message.put(MessageContext.REFERENCE_PARAMETERS, params);
            SOAPHeader head = SAAJUtils.getHeader(msg);
            if (head != null) {
                Iterator<Node> it = CastUtils.cast(head.getChildElements());
                while (it != null && it.hasNext()) {
                    Node nd = it.next();
                    if (nd instanceof SOAPElement) {
                        SOAPElement el = (SOAPElement) nd;
                        if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter") && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")) || Boolean.parseBoolean(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) {
                            params.add(el);
                        }
                    }
                }
            }
            if (isRequestor(message) && msg.getSOAPPart().getEnvelope().getBody() != null && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
                return null;
            }
        } catch (SOAPException e) {
            throw new Fault(e);
        }
    }
    return sm;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Node(javax.xml.soap.Node) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) ArrayList(java.util.ArrayList) Fault(org.apache.cxf.interceptor.Fault) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 65 with Exchange

use of org.apache.cxf.message.Exchange in project cxf by apache.

the class ProviderFactoryTest method prepareMessage.

private Message prepareMessage(String contentType, String acceptType) {
    Message message = new MessageImpl();
    Map<String, List<String>> headers = new MetadataMap<String, String>();
    message.put(Message.PROTOCOL_HEADERS, headers);
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(message);
    if (acceptType != null) {
        headers.put("Accept", Collections.singletonList(acceptType));
        exchange.setOutMessage(new MessageImpl());
    } else {
        headers.put("Content-Type", Collections.singletonList(contentType));
    }
    message.put("Content-Type", contentType);
    message.setExchange(exchange);
    return message;
}
Also used : Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Message(org.apache.cxf.message.Message) List(java.util.List) ArrayList(java.util.ArrayList) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

Exchange (org.apache.cxf.message.Exchange)272 Message (org.apache.cxf.message.Message)151 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)131 MessageImpl (org.apache.cxf.message.MessageImpl)118 Test (org.junit.Test)93 Endpoint (org.apache.cxf.endpoint.Endpoint)66 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)50 QName (javax.xml.namespace.QName)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Bus (org.apache.cxf.Bus)30 Fault (org.apache.cxf.interceptor.Fault)27 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)26 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)25 Conduit (org.apache.cxf.transport.Conduit)25 MessageContentsList (org.apache.cxf.message.MessageContentsList)22 SOAPMessage (javax.xml.soap.SOAPMessage)19 XMLStreamReader (javax.xml.stream.XMLStreamReader)19 ServerProviderFactory (org.apache.cxf.jaxrs.provider.ServerProviderFactory)19