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);
}
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);
}
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);
}
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"));
}
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);
}
Aggregations