use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ContextPropertiesMappingTest method testCreateWebServiceContext.
@Test
public void testCreateWebServiceContext() {
Exchange exchange = new ExchangeImpl();
Message inMessage = new MessageImpl();
Message outMessage = new MessageImpl();
inMessage.putAll(message);
exchange.setInMessage(inMessage);
exchange.setOutMessage(outMessage);
MessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);
Object requestHeader = ctx.get(MessageContext.HTTP_REQUEST_HEADERS);
assertNotNull("the request header should not be null", requestHeader);
assertEquals("we should get the request header", requestHeader, HEADER);
Object responseHeader = ctx.get(MessageContext.HTTP_RESPONSE_HEADERS);
assertNull("the response header should be null", responseHeader);
Object outMessageHeader = outMessage.get(Message.PROTOCOL_HEADERS);
assertEquals("the outMessage PROTOCOL_HEADERS should be update", responseHeader, outMessageHeader);
Object inAttachments = ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
assertNotNull("inbound attachments object must be initialized", inAttachments);
assertTrue("inbound attachments must be in a Map", inAttachments instanceof Map);
assertTrue("no inbound attachments expected", ((Map<?, ?>) inAttachments).isEmpty());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class SOAPLoggingTest method testSoap.
@Test
public void testSoap() {
DefaultLogEventMapper mapper = new DefaultLogEventMapper();
Message message = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
ServiceInfo service = new ServiceInfo();
BindingInfo info = new BindingInfo(service, "bindingId");
SoapBinding value = new SoapBinding(info);
exchange.put(Binding.class, value);
OperationInfo opInfo = new OperationInfo();
opInfo.setName(new QName("http://my", "Operation"));
BindingOperationInfo boi = new BindingOperationInfo(info, opInfo);
exchange.put(BindingOperationInfo.class, boi);
message.setExchange(exchange);
LogEvent event = mapper.map(message, Collections.emptySet());
Assert.assertEquals("{http://my}Operation", event.getOperationName());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JsonpInterceptorTest method testJsonWithPadding.
@Test
public void testJsonWithPadding() throws Exception {
Message message = new MessageImpl();
message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_JSON);
message.setExchange(new ExchangeImpl());
message.put(Message.QUERY_STRING, JsonpInInterceptor.CALLBACK_PARAM + "=" + "myCallback");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
message.setContent(OutputStream.class, bos);
// Process the message
in.handleMessage(message);
preStream.handleMessage(message);
postStream.handleMessage(message);
assertEquals("myCallback();", bos.toString());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class DOM4JProviderTest method createMessage.
private Message createMessage(ProviderFactory factory) {
Message m = new MessageImpl();
m.put("org.apache.cxf.http.case_insensitive_queries", false);
Exchange e = new ExchangeImpl();
m.setExchange(e);
e.setInMessage(m);
Endpoint endpoint = EasyMock.createMock(Endpoint.class);
endpoint.getEndpointInfo();
EasyMock.expectLastCall().andReturn(null).anyTimes();
endpoint.get(Application.class.getName());
EasyMock.expectLastCall().andReturn(null);
endpoint.size();
EasyMock.expectLastCall().andReturn(0).anyTimes();
endpoint.isEmpty();
EasyMock.expectLastCall().andReturn(true).anyTimes();
endpoint.get(ServerProviderFactory.class.getName());
EasyMock.expectLastCall().andReturn(factory).anyTimes();
EasyMock.replay(endpoint);
e.put(Endpoint.class, endpoint);
return m;
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JMSDestinationTest method testRoundTripDestination.
private Message testRoundTripDestination(boolean createSecurityContext) throws Exception {
EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
JMSConduit conduit = setupJMSConduitWithObserver(ei);
conduit.getJmsConfig().setCreateSecurityContext(createSecurityContext);
final Message outMessage = createMessage();
final JMSDestination destination = setupJMSDestination(ei);
// set up MessageObserver for handling the conduit message
MessageObserver observer = new MessageObserver() {
public void onMessage(Message m) {
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
verifyReceivedMessage(m);
verifyHeaders(m, outMessage);
// setup the message for
Conduit backConduit;
try {
backConduit = destination.getBackChannel(m);
// wait for the message to be got from the conduit
Message replyMessage = new MessageImpl();
sendOneWayMessage(backConduit, replyMessage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
destination.setMessageObserver(observer);
sendMessageSync(conduit, outMessage);
// wait for the message to be got from the destination,
// create the thread to handler the Destination incoming message
verifyReceivedMessage(waitForReceiveInMessage());
// wait for a while for the jms session recycling
// Send a second message to check for an issue
// Where the session was closed the second time
sendMessageSync(conduit, outMessage);
Message inMessage = waitForReceiveInMessage();
verifyReceivedMessage(inMessage);
// wait for a while for the jms session recycling
// Thread.sleep(1000L);
conduit.close();
destination.shutdown();
return inMessage;
}
Aggregations