use of org.apache.cxf.message.Message in project camel by apache.
the class DefaultCxfMessageMapper method createCxfMessageFromCamelExchange.
public Message createCxfMessageFromCamelExchange(Exchange camelExchange, HeaderFilterStrategy headerFilterStrategy) {
org.apache.cxf.message.Message answer = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, camelExchange, false);
org.apache.camel.Message camelMessage = camelExchange.getIn();
String requestContentType = getRequestContentType(camelMessage);
String acceptContentTypes = camelMessage.getHeader("Accept", String.class);
if (acceptContentTypes == null) {
acceptContentTypes = "*/*";
}
String enc = getCharacterEncoding(camelMessage);
String requestURI = getRequestURI(camelMessage);
String path = getPath(camelMessage);
String basePath = getBasePath(camelExchange);
String verb = getVerb(camelMessage);
String queryString = getQueryString(camelMessage);
answer.put(org.apache.cxf.message.Message.REQUEST_URI, requestURI);
answer.put(org.apache.cxf.message.Message.BASE_PATH, basePath);
answer.put(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, verb);
answer.put(org.apache.cxf.message.Message.PATH_INFO, path);
answer.put(org.apache.cxf.message.Message.CONTENT_TYPE, requestContentType);
answer.put(org.apache.cxf.message.Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
answer.put(org.apache.cxf.message.Message.ENCODING, enc);
answer.put(org.apache.cxf.message.Message.QUERY_STRING, queryString);
HttpServletRequest request = (HttpServletRequest) camelMessage.getHeader(Exchange.HTTP_SERVLET_REQUEST);
answer.put(CXF_HTTP_REQUEST, request);
if (request != null) {
setSecurityContext(answer, request);
}
Object response = camelMessage.getHeader(Exchange.HTTP_SERVLET_RESPONSE);
answer.put(CXF_HTTP_RESPONSE, response);
LOG.trace("Processing {}, requestContentType = {}, acceptContentTypes = {}, encoding = {}, path = {}, basePath = {}, verb = {}", new Object[] { camelExchange, requestContentType, acceptContentTypes, enc, path, basePath, verb });
return answer;
}
use of org.apache.cxf.message.Message in project camel by apache.
the class CamelDestinationTest method testRoundTripDestinationWithFault.
@Test
public void testRoundTripDestinationWithFault() throws Exception {
inMessage = null;
EndpointInfo conduitEpInfo = new EndpointInfo();
conduitEpInfo.setAddress("camel://direct:Producer");
// set up the conduit send to be true
CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
final Message outMessage = new MessageImpl();
endpointInfo.setAddress("camel://direct:EndpointA");
final CamelDestination destination = setupCamelDestination(endpointInfo, true);
destination.setCheckException(true);
// set up MessageObserver for handling the conduit message
MessageObserver observer = new MessageObserver() {
public void onMessage(Message m) {
try {
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
verifyReceivedMessage(m, "HelloWorld");
//verifyHeaders(m, outMessage);
// setup the message for
Conduit backConduit;
backConduit = getBackChannel(destination, m);
// wait for the message to be got from the conduit
Message replyMessage = new MessageImpl();
replyMessage.setContent(Exception.class, new RuntimeCamelException());
sendoutMessage(backConduit, replyMessage, true, "HelloWorld Fault");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
error.expectedMessageCount(1);
//this call will active the camelDestination
destination.setMessageObserver(observer);
// set is one way false for get response from destination
// need to use another thread to send the request message
sendoutMessage(conduit, outMessage, false, "HelloWorld");
// wait for the message to be got from the destination,
// create the thread to handler the Destination incoming message
verifyReceivedMessage(inMessage, "HelloWorld Fault");
error.assertIsSatisfied();
destination.shutdown();
}
use of org.apache.cxf.message.Message in project camel by apache.
the class CamelTransportTestSupport method setupCamelConduit.
protected CamelConduit setupCamelConduit(EndpointInfo endpointInfo, boolean send, boolean decoupled) {
if (decoupled) {
// setup the reference type
} else {
target = EasyMock.createMock(EndpointReferenceType.class);
}
CamelConduit camelConduit = new CamelConduit(context, bus, endpointInfo, target);
if (send) {
// setMessageObserver
observer = new MessageObserver() {
public void onMessage(Message m) {
inMessage = m;
}
};
camelConduit.setMessageObserver(observer);
}
return camelConduit;
}
use of org.apache.cxf.message.Message in project camel by apache.
the class CxfMessageHelperTest method testGetCxfInMessage.
// setup the default context for testing
@Test
public void testGetCxfInMessage() throws Exception {
HeaderFilterStrategy headerFilterStrategy = new CxfHeaderFilterStrategy();
org.apache.camel.Exchange exchange = new DefaultExchange(context);
// String
exchange.getIn().setBody("hello world");
org.apache.cxf.message.Message message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
// test message
InputStream is = message.getContent(InputStream.class);
assertNotNull("The input stream should not be null", is);
assertEquals("Don't get the right message", toString(is), "hello world");
// DOMSource
URL request = this.getClass().getResource("RequestBody.xml");
File requestFile = new File(request.toURI());
FileInputStream inputStream = new FileInputStream(requestFile);
XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(inputStream);
DOMSource source = new DOMSource(StaxUtils.read(xmlReader));
exchange.getIn().setBody(source);
message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
is = message.getContent(InputStream.class);
assertNotNull("The input stream should not be null", is);
assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
// File
exchange.getIn().setBody(requestFile);
message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
is = message.getContent(InputStream.class);
assertNotNull("The input stream should not be null", is);
assertEquals("Don't get the right message", toString(is), REQUEST_STRING);
// transport header's case insensitiveness
// String
exchange.getIn().setBody("hello world");
exchange.getIn().setHeader("soapAction", "urn:hello:world");
message = CxfMessageHelper.getCxfInMessage(headerFilterStrategy, exchange, false);
// test message
Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
// verify there is no duplicate
assertNotNull("The headers must be present", headers);
assertTrue("There must be one header entry", headers.size() == 1);
// verify the soapaction can be retrieved in case-insensitive ways
verifyHeader(headers, "soapaction", "urn:hello:world");
verifyHeader(headers, "SoapAction", "urn:hello:world");
verifyHeader(headers, "SOAPAction", "urn:hello:world");
}
use of org.apache.cxf.message.Message in project camel by apache.
the class CamelConduitTest method testPrepareSend.
@Test
public void testPrepareSend() throws Exception {
endpointInfo.setAddress("camel://direct:Producer");
CamelConduit conduit = setupCamelConduit(endpointInfo, false, false);
Message message = new MessageImpl();
try {
conduit.prepare(message);
} catch (Exception ex) {
ex.printStackTrace();
}
verifyMessageContent(message);
}
Aggregations