Search in sources :

Example 66 with BindingProvider

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()));
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) AddressingFeature(javax.xml.ws.soap.AddressingFeature) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) QName(javax.xml.namespace.QName) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Greeter(org.apache.hello_world_soap_http.Greeter) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) Test(org.junit.Test)

Example 67 with BindingProvider

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();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Closeable(java.io.Closeable) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BindingProvider(javax.xml.ws.BindingProvider) Test(org.junit.Test)

Example 68 with BindingProvider

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"));
    }
}
Also used : AddNumberImpl(org.apache.cxf.systest.ws.addr_fromjava.client.AddNumberImpl) BindingProvider(javax.xml.ws.BindingProvider) AddNumbersException_Exception(org.apache.cxf.systest.ws.addr_fromjava.client.AddNumbersException_Exception) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 69 with BindingProvider

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);
}
Also used : AddNumberImpl(org.apache.cxf.systest.ws.addr_fromjava.client.AddNumberImpl) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BindingProvider(javax.xml.ws.BindingProvider) Test(org.junit.Test)

Example 70 with BindingProvider

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);
}
Also used : AddNumberImpl(org.apache.cxf.systest.ws.addr_fromjava.client.AddNumberImpl) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) BindingProvider(javax.xml.ws.BindingProvider) AddNumbersException_Exception(org.apache.cxf.systest.ws.addr_fromjava.client.AddNumbersException_Exception) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)147 URL (java.net.URL)87 Test (org.junit.Test)74 Service (javax.xml.ws.Service)65 QName (javax.xml.namespace.QName)41 WebServiceException (javax.xml.ws.WebServiceException)24 Greeter (org.apache.hello_world_soap_http.Greeter)23 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)18 Bus (org.apache.cxf.Bus)17 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)15 InvocationHandler (java.lang.reflect.InvocationHandler)14 SOAPService (org.apache.hello_world_soap_http.SOAPService)14 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)12 STSClient (org.apache.cxf.ws.security.trust.STSClient)11 Greeter (org.apache.cxf.greeter_control.Greeter)10 GreeterService (org.apache.cxf.greeter_control.GreeterService)10 SOAPBinding (javax.xml.ws.soap.SOAPBinding)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)9 Client (org.apache.cxf.endpoint.Client)9 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)8