Search in sources :

Example 21 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class MessageToEventMapperTest method testMapEventRest.

@Test
public void testMapEventRest() throws IOException, EndpointException {
    QName portType = new QName("PORT_TYPE");
    EndpointInfo info = EasyMock.createMock(EndpointInfo.class);
    EasyMock.expect(info.getName()).andReturn(portType).anyTimes();
    EasyMock.expect(info.getAddress()).andReturn(null).anyTimes();
    EasyMock.replay(info);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(info).anyTimes();
    Map<String, String> samProperties = new HashMap<String, String>();
    EasyMock.expect(endpoint.get(EventFeature.SAM_PROPERTIES)).andReturn(samProperties).anyTimes();
    EasyMock.replay(endpoint);
    Message outMessage = EasyMock.createMock(Message.class);
    EasyMock.expect(outMessage.containsKey(Message.HTTP_REQUEST_METHOD)).andReturn(true).anyTimes();
    EasyMock.expect(outMessage.get(Message.HTTP_REQUEST_METHOD)).andReturn("POST").anyTimes();
    EasyMock.expect(outMessage.containsKey(Message.REQUEST_URI)).andReturn(true).anyTimes();
    EasyMock.expect(outMessage.get(Message.REQUEST_URI)).andReturn("REQUEST_URI").anyTimes();
    EasyMock.expect(outMessage.containsKey(Message.BASE_PATH)).andReturn(true).anyTimes();
    EasyMock.expect(outMessage.get(Message.BASE_PATH)).andReturn("REQUEST_URI").anyTimes();
    EasyMock.replay(outMessage);
    Exchange e = EasyMock.createMock(Exchange.class);
    EasyMock.expect(e.getOutMessage()).andReturn(outMessage).anyTimes();
    EasyMock.expect(e.getOutFaultMessage()).andReturn(null).anyTimes();
    EasyMock.expect(e.getInFaultMessage()).andReturn(null).anyTimes();
    EasyMock.expect(e.getBinding()).andReturn(null).anyTimes();
    EasyMock.expect(e.getEndpoint()).andReturn(endpoint).anyTimes();
    EasyMock.expect(e.get("org.apache.cxf.resource.operation.name")).andReturn("operationName").anyTimes();
    EasyMock.replay(e);
    AuthorizationPolicy authPolicy = EasyMock.createMock(AuthorizationPolicy.class);
    EasyMock.expect(authPolicy.getUserName()).andReturn("USERNAME").anyTimes();
    EasyMock.replay(authPolicy);
    CachedOutputStream cos = new CachedOutputStream();
    cos.write(1);
    cos.write(2);
    cos.write(3);
    Message message = EasyMock.createNiceMock(Message.class);
    EasyMock.expect(message.entrySet()).andReturn(null).anyTimes();
    EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(true).anyTimes();
    EasyMock.expect(message.getExchange()).andReturn(e).anyTimes();
    EasyMock.expect(message.get(Message.ENCODING)).andReturn("UTF-8").anyTimes();
    EasyMock.expect(message.getContent(CachedOutputStream.class)).andReturn(cos).anyTimes();
    EasyMock.expect(message.get("FlowId")).andReturn(FlowID).anyTimes();
    EasyMock.expect(message.get(CorrelationIdHelper.CORRELATION_ID_KEY)).andReturn("CORRELATION_ID_KEY").anyTimes();
    EasyMock.expect(message.get(Message.ACCEPT_CONTENT_TYPE)).andReturn("XML").anyTimes();
    EasyMock.expect(message.get(Message.CONTENT_TYPE)).andReturn("XML").anyTimes();
    EasyMock.expect(message.get(Message.RESPONSE_CODE)).andReturn(0).anyTimes();
    EasyMock.expect(message.get(SecurityContext.class)).andReturn(null).anyTimes();
    EasyMock.expect(message.get(AuthorizationPolicy.class)).andReturn(authPolicy).anyTimes();
    EasyMock.expect(message.get(CustomInfo.class)).andReturn(EasyMock.createMock(CustomInfo.class)).anyTimes();
    EasyMock.replay(message);
    MessageToEventMapper mapper = new MessageToEventMapper();
    mapper.setMaxContentLength(2);
    Event event = mapper.mapToEvent(message);
    Assert.assertEquals(EventTypeEnum.RESP_IN, event.getEventType());
    Assert.assertEquals("PORT_TYPE", event.getMessageInfo().getPortType());
    Assert.assertEquals("POST[/]", event.getMessageInfo().getOperationName());
    Assert.assertEquals("http://cxf.apache.org/transports/http", event.getMessageInfo().getTransportType());
    Assert.assertEquals(FlowID, event.getMessageInfo().getFlowId());
    Assert.assertNull(event.getMessageInfo().getMessageId());
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessageToEventMapper(org.talend.esb.sam.agent.eventproducer.MessageToEventMapper) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Endpoint(org.apache.cxf.endpoint.Endpoint) DefaultSecurityContext(org.apache.cxf.interceptor.security.DefaultSecurityContext) SecurityContext(org.apache.cxf.security.SecurityContext) CustomInfo(org.talend.esb.sam.agent.message.CustomInfo) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 22 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class FlowIdProducerTest method flowIdProducerOut2Test.

@Test
public void flowIdProducerOut2Test() {
    FlowIdProducerOut<Message> flowIdProducerOut = new FlowIdProducerOut<Message>();
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    Message inMessage = new MessageImpl();
    exchange.setInMessage(inMessage);
    message.setExchange(exchange);
    WeakReference<Message> wrPreviousMessage = EasyMock.createMock(WeakReference.class);
    EasyMock.expect(wrPreviousMessage.get()).andReturn(message);
    EasyMock.replay(wrPreviousMessage);
    message.put(PhaseInterceptorChain.PREVIOUS_MESSAGE, wrPreviousMessage);
    message.put(Message.REQUESTOR_ROLE, true);
    String flowId = FlowIdHelper.getFlowId(message);
    Assert.assertNull("FlowId should be null before FlowIdProducerOut handleMessage()", flowId);
    flowIdProducerOut.handleMessage(message);
    flowId = FlowIdHelper.getFlowId(message);
    Assert.assertNotNull("FlowId should not be null after FlowIdProducerOut handleMessage()", flowId);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 23 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class FlowIdProducerTest method flowIdProducerOutTest.

@Test
public void flowIdProducerOutTest() {
    FlowIdProducerOut<Message> flowIdProducerOut = new FlowIdProducerOut<Message>();
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    Message inMessage = new MessageImpl();
    exchange.setInMessage(inMessage);
    message.setExchange(exchange);
    String flowId = FlowIdHelper.getFlowId(message);
    Assert.assertNull("FlowId should be null before FlowIdProducerOut handleMessage()", flowId);
    flowIdProducerOut.handleMessage(message);
    flowId = FlowIdHelper.getFlowId(message);
    Assert.assertNotNull("FlowId should not be null after FlowIdProducerOut handleMessage()", flowId);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 24 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class CallbackActionInterceptor method handleAddressing.

private void handleAddressing(SoapMessage message) {
    final AddressingProperties maps = (AddressingProperties) message.getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
    if (maps == null) {
        return;
    }
    final EndpointReferenceType rpl = maps.getReplyTo();
    if (rpl == null) {
        return;
    }
    final AttributedURIType addr = rpl.getAddress();
    if (addr == null) {
        return;
    }
    final String replyTo = addr.getValue();
    final Exchange exchange = message.getExchange();
    if (exchange.getDestination() instanceof JMSDestination) {
        ContextUtils.storePartialResponseSent(message);
        if (!exchange.isOneWay()) {
            exchange.setOneWay(true);
        }
    } else {
        if (exchange.isOneWay()) {
            if (!Names.WSA_NONE_ADDRESS.equals(replyTo)) {
                // disable creation of "partial" response
                // by CXF decoupled response feature
                exchange.setOneWay(false);
            }
        } else {
            // and convert it afterwards to one-way.
            if (Names.WSA_NONE_ADDRESS.equals(replyTo)) {
                addr.setValue(Names.WSA_ANONYMOUS_ADDRESS);
            }
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) JMSDestination(org.apache.cxf.transport.jms.JMSDestination) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 25 with Exchange

use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.

the class RequestCallbackInInterceptor method handleMessage.

/**
 * {@inheritDoc}
 */
@Override
public void handleMessage(SoapMessage message) throws Fault {
    final Header callHeader = message.getHeader(RequestCallbackFeature.CALL_ID_HEADER_NAME);
    if (callHeader == null) {
        return;
    }
    final Exchange e = message.getExchange();
    if (!e.isOneWay()) {
        e.setOneWay(true);
    }
    final Header callbackHeader = message.getHeader(RequestCallbackFeature.CALLBACK_ID_HEADER_NAME);
    if (callbackHeader == null) {
        doHandleRequestSoapMessage(message, callHeader);
    } else {
        doHandleCallbackSoapMessage(message, callHeader, callbackHeader);
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Header(org.apache.cxf.headers.Header)

Aggregations

Exchange (org.apache.cxf.message.Exchange)338 Message (org.apache.cxf.message.Message)196 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)159 MessageImpl (org.apache.cxf.message.MessageImpl)144 Test (org.junit.Test)119 Endpoint (org.apache.cxf.endpoint.Endpoint)75 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)62 QName (javax.xml.namespace.QName)51 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)43 Bus (org.apache.cxf.Bus)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Conduit (org.apache.cxf.transport.Conduit)31 Fault (org.apache.cxf.interceptor.Fault)30 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)28 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)28 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Service (org.apache.cxf.service.Service)22 SOAPMessage (javax.xml.soap.SOAPMessage)21 List (java.util.List)19