use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class BareInInterceptorTest method setUpUsingHelloWorld.
private void setUpUsingHelloWorld() throws Exception {
String ns = "http://apache.org/hello_world_soap_http";
WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
service = factory.create();
endpointInfo = service.getServiceInfos().get(0).getEndpoint(new QName(ns, "SoapPort"));
endpoint = new EndpointImpl(bus, service, endpointInfo);
JAXBDataBinding db = new JAXBDataBinding();
db.setContext(JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class }));
service.setDataBinding(db);
operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);
message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
exchange.put(Service.class, service);
exchange.put(Endpoint.class, endpoint);
exchange.put(Binding.class, endpoint.getBinding());
}
use of org.apache.cxf.message.MessageImpl 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();
assertNotNull(outMsg);
@SuppressWarnings("unchecked") List<Header> headers = (List<Header>) outMsg.get(Header.HEADER_LIST);
assertEquals(1, headers.size());
assertEquals(TEST_HEADER_NAME, headers.get(0).getName());
}
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class JAXWSMethodInvokerTest method testProviderInterpretNullAsOneway.
@Test
public void testProviderInterpretNullAsOneway() throws Throwable {
NullableProviderService serviceObject = new NullableProviderService();
Method serviceMethod = NullableProviderService.class.getMethod("invoke", new Class[] { Source.class });
Exchange ex = new ExchangeImpl();
Message inMessage = new MessageImpl();
inMessage.setInterceptorChain(new PhaseInterceptorChain(new TreeSet<Phase>()));
ex.setInMessage(inMessage);
inMessage.setExchange(ex);
inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
// request-response with non-null response
ex.setOneWay(false);
MessageContentsList obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertEquals(1, obj.size());
assertNotNull(obj.get(0));
assertFalse(ex.isOneWay());
// oneway with non-null response
ex.setOneWay(true);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertNull(obj);
assertTrue(ex.isOneWay());
// request-response with null response, interpretNullAsOneway not set so
// default should be true
ex.setOneWay(false);
serviceObject.setNullable(true);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertNull(obj);
assertTrue(ex.isOneWay());
// request-response with null response, interpretNullAsOneway disabled
ex.setOneWay(false);
serviceObject.setNullable(true);
inMessage.put("jaxws.provider.interpretNullAsOneway", Boolean.FALSE);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertEquals(1, obj.size());
assertNull(obj.get(0));
assertFalse(ex.isOneWay());
// request-response with null response, interpretNullAsOneway explicitly enabled
ex.setOneWay(false);
serviceObject.setNullable(true);
inMessage.put("jaxws.provider.interpretNullAsOneway", Boolean.TRUE);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertNull(obj);
assertTrue(ex.isOneWay());
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class JAXWSMethodInvokerTest method testSuspendedException.
@Test
public void testSuspendedException() throws Throwable {
Exception originalException = new RuntimeException();
ContinuationService serviceObject = new ContinuationService(originalException);
Method serviceMethod = ContinuationService.class.getMethod("invoke", new Class[] {});
Exchange ex = new ExchangeImpl();
Message inMessage = new MessageImpl();
ex.setInMessage(inMessage);
inMessage.setExchange(ex);
inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
try {
jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] {}));
fail("Suspended invocation swallowed");
} catch (SuspendedInvocationException suspendedEx) {
assertSame(suspendedEx, serviceObject.getSuspendedException());
assertSame(originalException, suspendedEx.getRuntimeException());
}
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class WebServiceContextImplTest method testSetHttpRequestHeadersScope.
// CXF-3989
@Test
public void testSetHttpRequestHeadersScope() {
MessageImpl msg = new MessageImpl();
MessageContext context = new WrappedMessageContext(msg);
Map<String, List<String>> headers = new HashMap<>();
List<String> values = new ArrayList<>();
values.add("Value1");
headers.put("Header1", values);
context.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
context.setScope(MessageContext.HTTP_REQUEST_HEADERS, Scope.APPLICATION);
}
Aggregations