use of org.apache.cxf.message.Exchange in project cxf by apache.
the class JAXWSMethodInvokerTest method testFaultHeadersCopy.
@Test
public void testFaultHeadersCopy() throws Throwable {
ExceptionService serviceObject = new ExceptionService();
Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[] {});
Exchange ex = new ExchangeImpl();
prepareInMessage(ex, true);
Message msg = new MessageImpl();
SoapMessage outMessage = new SoapMessage(msg);
ex.setOutMessage(outMessage);
JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
try {
jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] {}));
fail("Expected fault");
} catch (Fault fault) {
Message outMsg = ex.getOutMessage();
Assert.assertNotNull(outMsg);
@SuppressWarnings("unchecked") List<Header> headers = (List<Header>) outMsg.get(Header.HEADER_LIST);
Assert.assertEquals(1, headers.size());
Assert.assertEquals(TEST_HEADER_NAME, headers.get(0).getName());
}
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class LogicalMessageImplTest method testGetPayloadOfJAXB.
@Test
public void testGetPayloadOfJAXB() throws Exception {
// using Dispatch
JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
Message message = new MessageImpl();
Exchange e = new ExchangeImpl();
message.setExchange(e);
LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
JAXBElement<AddNumbers> el = new ObjectFactory().createAddNumbers(req);
LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
lmi.setPayload(el, ctx);
Object obj = lmi.getPayload(ctx);
assertTrue(obj instanceof JAXBElement);
JAXBElement<?> el2 = (JAXBElement<?>) obj;
assertTrue(el2.getValue() instanceof AddNumbers);
AddNumbers resp = (AddNumbers) el2.getValue();
assertEquals(req.getArg0(), resp.getArg0());
assertEquals(req.getArg1(), resp.getArg1());
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class SOAPHandlerInterceptorTest method testGetUnderstoodHeadersReturnsNull.
@Test
public void testGetUnderstoodHeadersReturnsNull() {
@SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
list.add(new SOAPHandler<SOAPMessageContext>() {
public boolean handleMessage(SOAPMessageContext smc) {
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
return true;
}
public Set<QName> getHeaders() {
return null;
}
public void close(MessageContext messageContext) {
}
});
HandlerChainInvoker invoker = new HandlerChainInvoker(list);
IMocksControl control = createNiceControl();
Binding binding = control.createMock(Binding.class);
expect(binding.getHandlerChain()).andReturn(list).anyTimes();
SoapMessage message = control.createMock(SoapMessage.class);
Exchange exchange = control.createMock(Exchange.class);
expect(message.getExchange()).andReturn(exchange).anyTimes();
expect(message.keySet()).andReturn(new HashSet<>());
expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
control.replay();
SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
Set<QName> understood = li.getUnderstoodHeaders();
assertNotNull(understood);
assertTrue(understood.isEmpty());
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class SOAPHandlerInterceptor method createProtocolMessageContext.
@Override
protected MessageContext createProtocolMessageContext(SoapMessage message) {
SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);
Exchange exch = message.getExchange();
setupBindingOperationInfo(exch, sm);
SOAPMessage msg = sm.getMessage();
if (msg != null) {
try {
List<SOAPElement> params = new ArrayList<>();
message.put(MessageContext.REFERENCE_PARAMETERS, params);
SOAPHeader head = SAAJUtils.getHeader(msg);
if (head != null) {
Iterator<Node> it = CastUtils.cast(head.getChildElements());
while (it != null && it.hasNext()) {
Node nd = it.next();
if (nd instanceof SOAPElement) {
SOAPElement el = (SOAPElement) nd;
if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter") && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")) || Boolean.parseBoolean(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) {
params.add(el);
}
}
}
}
if (isRequestor(message) && msg.getSOAPPart().getEnvelope().getBody() != null && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
return null;
}
} catch (SOAPException e) {
throw new Fault(e);
}
}
return sm;
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class ProviderFactoryTest method prepareMessage.
private Message prepareMessage(String contentType, String acceptType) {
Message message = new MessageImpl();
Map<String, List<String>> headers = new MetadataMap<String, String>();
message.put(Message.PROTOCOL_HEADERS, headers);
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(message);
if (acceptType != null) {
headers.put("Accept", Collections.singletonList(acceptType));
exchange.setOutMessage(new MessageImpl());
} else {
headers.put("Content-Type", Collections.singletonList(contentType));
}
message.put("Content-Type", contentType);
message.setExchange(exchange);
return message;
}
Aggregations