use of javax.xml.ws.BindingProvider in project cxf by apache.
the class WSAFaultToClientServerTest method testOneWayFaultTo.
@Test
public void testOneWayFaultTo() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPServiceAddressing");
Greeter greeter = new SOAPService(wsdl, serviceName).getPort(Greeter.class, new AddressingFeature());
EndpointReferenceType faultTo = new EndpointReferenceType();
AddressingProperties addrProperties = new AddressingProperties();
AttributedURIType epr = new AttributedURIType();
String faultToAddress = "http://localhost:" + FaultToEndpointServer.FAULT_PORT + "/faultTo";
epr.setValue(faultToAddress);
faultTo.setAddress(epr);
addrProperties.setFaultTo(faultTo);
BindingProvider provider = (BindingProvider) greeter;
Map<String, Object> requestContext = provider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + FaultToEndpointServer.PORT + "/jaxws/greeter");
requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
greeter.greetMeOneWay("test");
// wait for the fault request
int i = 2;
while (HelloHandler.getFaultRequestPath() == null && i > 0) {
Thread.sleep(500);
i--;
}
assertTrue("FaultTo request fpath isn't expected", "/faultTo".equals(HelloHandler.getFaultRequestPath()));
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class WSAFaultToClientServerTest method testTwoWayFaultTo.
@Test
public void testTwoWayFaultTo() throws Exception {
ByteArrayOutputStream input = setupInLogging();
AddNumbersPortType port = getTwoWayPort();
// setup a real decoupled endpoint that will process the fault correctly
HTTPConduit c = (HTTPConduit) ClientProxy.getClient(port).getConduit();
c.getClient().setDecoupledEndpoint("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
EndpointReferenceType faultTo = new EndpointReferenceType();
AddressingProperties addrProperties = new AddressingProperties();
AttributedURIType epr = new AttributedURIType();
epr.setValue("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
faultTo.setAddress(epr);
addrProperties.setFaultTo(faultTo);
BindingProvider provider = (BindingProvider) port;
Map<String, Object> requestContext = provider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + FaultToEndpointServer.PORT + "/jaxws/add");
requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
try {
port.addNumbers(-1, -2);
fail("Exception is expected");
} catch (Exception e) {
// do nothing
}
String in = new String(input.toByteArray());
// System.out.println(in);
assertTrue("The response from faultTo endpoint is expected and actual response is " + in, in.indexOf("Address: http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere") > -1);
assertTrue("WS addressing header is expected", in.indexOf("http://www.w3.org/2005/08/addressing") > -1);
assertTrue("Fault deatil is expected", in.indexOf("Negative numbers cant be added") > -1);
((Closeable) port).close();
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class WSAFromJavaTest method testUnmatchedActions.
@Test
public void testUnmatchedActions() throws Exception {
AddNumberImpl port = getPort();
BindingProvider bp = (BindingProvider) port;
java.util.Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://cxf.apache.org/input4");
try {
// CXF-2035
port.addNumbers3(-1, -1);
} catch (Exception e) {
assertTrue(e.getMessage().contains("Unexpected wrapper"));
}
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class WSAFromJavaTest method testAddNumbersJaxWsContext.
@Test
public void testAddNumbersJaxWsContext() throws Exception {
ByteArrayOutputStream output = setupOutLogging();
AddNumberImpl port = getPort();
BindingProvider bp = (BindingProvider) port;
java.util.Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "cxf");
try {
assertEquals(3, port.addNumbers(1, 2));
fail("Should have thrown an ActionNotSupported exception");
} catch (SOAPFaultException ex) {
// expected
}
assertLogContains(output.toString(), "//wsa:Action", "cxf");
assertTrue(output.toString(), output.toString().indexOf("SOAPAction=\"cxf\"") != -1);
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class WSAFromJavaTest method testFaultFromNonAddressService.
@Test
public void testFaultFromNonAddressService() throws Exception {
new LoggingFeature().initialize(this.getBus());
AddNumberImpl port = getPort();
java.util.Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/AddNumberImplPort-noaddr");
long start = System.currentTimeMillis();
port.addNumbers(1, 2);
try {
port.addNumbers3(-1, -1);
} catch (Exception ex) {
// ignore, expected
}
long end = System.currentTimeMillis();
assertTrue((end - start) < 50000);
}
Aggregations