Search in sources :

Example 6 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class ConverterTest method testFallbackConverter.

@Test
public void testFallbackConverter() throws Exception {
    CamelContext context = new DefaultCamelContext();
    Exchange exchange = new DefaultExchange(context);
    MessageContentsList list = new MessageContentsList();
    NodeListWrapper nl = new NodeListWrapper(new ArrayList<Element>());
    list.add(nl);
    exchange.getIn().setBody(list);
    Node node = exchange.getIn().getBody(Node.class);
    assertNull(node);
    File file = new File("src/test/resources/org/apache/camel/component/cxf/converter/test.xml");
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(file);
    document.getDocumentElement().normalize();
    List<Element> elements = new ArrayList<Element>();
    elements.add(document.getDocumentElement());
    nl = new NodeListWrapper(elements);
    list.clear();
    list.add(nl);
    exchange.getIn().setBody(list);
    node = exchange.getIn().getBody(Node.class);
    assertNotNull(node);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MessageContentsList(org.apache.cxf.message.MessageContentsList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) Test(org.junit.Test)

Example 7 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class ConverterTest method testToInputStream.

@Test
public void testToInputStream() throws Exception {
    CamelContext context = new DefaultCamelContext();
    Exchange exchange = new DefaultExchange(context);
    Response response = EasyMock.createMock(Response.class);
    InputStream is = EasyMock.createMock(InputStream.class);
    response.getEntity();
    EasyMock.expectLastCall().andReturn(is);
    EasyMock.replay(response);
    InputStream result = CxfConverter.toInputStream(response, exchange);
    assertEquals("We should get the inputStream here ", is, result);
    EasyMock.verify(response);
    EasyMock.reset(response);
    response.getEntity();
    EasyMock.expectLastCall().andReturn("Hello World");
    EasyMock.replay(response);
    result = CxfConverter.toInputStream(response, exchange);
    assertTrue("We should get the inputStream here ", result instanceof ByteArrayInputStream);
    EasyMock.verify(response);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 8 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class DefaultCxfBindingTest method testPopulateCxfSoapHeaderRequestFromExchange.

@Test
public void testPopulateCxfSoapHeaderRequestFromExchange() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    Map<String, Object> requestContext = new HashMap<>();
    String expectedSoapActionHeader = "urn:hello:world";
    exchange.getIn().setHeader("soapAction", expectedSoapActionHeader);
    cxfBinding.populateCxfRequestFromExchange(cxfExchange, exchange, requestContext);
    String actualSoapActionHeader = (String) requestContext.get(SoapBindingConstants.SOAP_ACTION);
    assertEquals(expectedSoapActionHeader, actualSoapActionHeader);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) HashMap(java.util.HashMap) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Example 9 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class DefaultCxfBindingTest method testPopupalteExchangeFromCxfResponse.

@Test
public void testPopupalteExchangeFromCxfResponse() {
    DefaultCxfBinding cxfBinding = new DefaultCxfBinding();
    cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
    Exchange exchange = new DefaultExchange(context);
    org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl();
    exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
    Map<String, Object> responseContext = new HashMap<String, Object>();
    responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200));
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
    headers.put("Content-Length", Arrays.asList("241"));
    responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
    org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
    cxfExchange.setInMessage(cxfMessage);
    Set<Attachment> attachments = new HashSet<Attachment>();
    AttachmentImpl attachment = new AttachmentImpl("att-1", new DataHandler(new FileDataSource("pom.xml")));
    attachment.setHeader("additional-header", "value 1");
    attachments.add(attachment);
    cxfMessage.setAttachments(attachments);
    cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext);
    Map<String, Object> camelHeaders = exchange.getOut().getHeaders();
    assertNotNull(camelHeaders);
    assertEquals(responseContext, camelHeaders.get(Client.RESPONSE_CONTEXT));
    Map<String, org.apache.camel.Attachment> camelAttachments = exchange.getOut().getAttachmentObjects();
    assertNotNull(camelAttachments);
    assertNotNull(camelAttachments.get("att-1"));
    assertEquals("value 1", camelAttachments.get("att-1").getHeader("additional-header"));
}
Also used : HashMap(java.util.HashMap) DefaultHeaderFilterStrategy(org.apache.camel.impl.DefaultHeaderFilterStrategy) Attachment(org.apache.cxf.message.Attachment) DataHandler(javax.activation.DataHandler) FileDataSource(javax.activation.FileDataSource) List(java.util.List) HashSet(java.util.HashSet) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.cxf.message.Message) TreeMap(java.util.TreeMap) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) AttachmentImpl(org.apache.cxf.attachment.AttachmentImpl) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 10 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class CxfProducerRouterTest method testInvokingSimpleServerWithPayLoadDataFormat.

@Test
public void testInvokingSimpleServerWithPayLoadDataFormat() throws Exception {
    Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    senderExchange.getIn().setBody(REQUEST_PAYLOAD);
    // We need to specify the operation name to help CxfProducer to look up the BindingOperationInfo
    senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
    Exchange exchange = template.send("direct:EndpointC", senderExchange);
    org.apache.camel.Message out = exchange.getOut();
    String response = out.getBody(String.class);
    assertTrue("It should has the echo message", response.indexOf("echo " + TEST_MESSAGE) > 0);
    assertTrue("It should has the echoResponse tag", response.indexOf("echoResponse") > 0);
    senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
    senderExchange.getIn().setBody(REQUEST_PAYLOAD);
    // Don't specify operation information here
    exchange = template.send("direct:EndpointC", senderExchange);
    assertNotNull("Expect exception here.", exchange.getException());
    assertTrue(exchange.getException() instanceof IllegalArgumentException);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Test(org.junit.Test)

Aggregations

DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Exchange (org.apache.camel.Exchange)381 Test (org.junit.Test)254 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)127 CamelContext (org.apache.camel.CamelContext)54 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 HashMap (java.util.HashMap)33 Message (org.apache.camel.Message)32 Before (org.junit.Before)32 Tx (org.nhindirect.common.tx.model.Tx)31 ESMClass (org.jsmpp.bean.ESMClass)30 Processor (org.apache.camel.Processor)22 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)22 Expression (org.apache.camel.Expression)21 File (java.io.File)20 DefaultMessage (org.apache.camel.impl.DefaultMessage)20 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 URL (java.net.URL)16 Date (java.util.Date)16