Search in sources :

Example 16 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class WSSecurityClientTest method testUsernameTokenStreaming.

@Test
public void testUsernameTokenStreaming() throws Exception {
    final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, GREETER_SERVICE_QNAME);
    final Greeter greeter = svc.getPort(USERNAME_TOKEN_PORT_QNAME, Greeter.class);
    updateAddressPort(greeter, test.getPort());
    Client client = ClientProxy.getClient(greeter);
    Map<String, Object> props = new HashMap<>();
    props.put("action", "UsernameToken");
    props.put("user", "alice");
    props.put("passwordType", "PasswordText");
    WSS4JStaxOutInterceptor wss4jOut = new WSS4JStaxOutInterceptor(props);
    client.getOutInterceptors().add(wss4jOut);
    ((BindingProvider) greeter).getRequestContext().put("password", "password");
    try {
        greeter.greetMe("CXF");
        fail("should fail because of password text instead of digest");
    } catch (Exception ex) {
    // expected
    }
    client.getOutInterceptors().remove(wss4jOut);
    props.put("passwordType", "PasswordDigest");
    wss4jOut = new WSS4JStaxOutInterceptor(props);
    client.getOutInterceptors().add(wss4jOut);
    String s = greeter.greetMe("CXF");
    assertEquals("Hello CXF", s);
    client.getOutInterceptors().remove(wss4jOut);
    try {
        ((BindingProvider) greeter).getRequestContext().put("password", "foo");
        wss4jOut = new WSS4JStaxOutInterceptor(props);
        client.getOutInterceptors().add(wss4jOut);
        greeter.greetMe("CXF");
        fail("should fail");
    } catch (Exception ex) {
    // expected
    }
    client.getOutInterceptors().remove(wss4jOut);
    try {
        props.put("passwordType", "PasswordText");
        wss4jOut = new WSS4JStaxOutInterceptor(props);
        client.getOutInterceptors().add(wss4jOut);
        ((BindingProvider) greeter).getRequestContext().put("password", "password");
        greeter.greetMe("CXF");
        fail("should fail");
    } catch (Exception ex) {
    // expected
    }
    client.getOutInterceptors().remove(wss4jOut);
    ((java.io.Closeable) greeter).close();
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) HashMap(java.util.HashMap) Service(javax.xml.ws.Service) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Greeter(org.apache.hello_world_soap_http.Greeter) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 17 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class WSSecurityClientTest method testUsernameToken.

@Test
public void testUsernameToken() throws Exception {
    final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, GREETER_SERVICE_QNAME);
    final Greeter greeter = svc.getPort(USERNAME_TOKEN_PORT_QNAME, Greeter.class);
    updateAddressPort(greeter, test.getPort());
    Client client = ClientProxy.getClient(greeter);
    Map<String, Object> props = new HashMap<>();
    props.put("action", "UsernameToken");
    props.put("user", "alice");
    props.put("passwordType", "PasswordText");
    WSS4JOutInterceptor wss4jOut = new WSS4JOutInterceptor(props);
    client.getOutInterceptors().add(wss4jOut);
    ((BindingProvider) greeter).getRequestContext().put("password", "password");
    try {
        greeter.greetMe("CXF");
        fail("should fail because of password text instead of digest");
    } catch (Exception ex) {
    // expected
    }
    props.put("passwordType", "PasswordDigest");
    String s = greeter.greetMe("CXF");
    assertEquals("Hello CXF", s);
    try {
        ((BindingProvider) greeter).getRequestContext().put("password", "foo");
        greeter.greetMe("CXF");
        fail("should fail");
    } catch (Exception ex) {
    // expected
    }
    try {
        props.put("passwordType", "PasswordText");
        ((BindingProvider) greeter).getRequestContext().put("password", "password");
        greeter.greetMe("CXF");
        fail("should fail");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) greeter).close();
}
Also used : HashMap(java.util.HashMap) Service(javax.xml.ws.Service) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Greeter(org.apache.hello_world_soap_http.Greeter) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 18 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class WSSecurityClientTest method testTimestampSignEncrypt.

@Test
public void testTimestampSignEncrypt() throws Exception {
    Bus b = new SpringBusFactory().createBus("org/apache/cxf/systest/ws/security/client.xml");
    BusFactory.setDefaultBus(b);
    final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, GREETER_SERVICE_QNAME);
    final Greeter greeter = svc.getPort(TIMESTAMP_SIGN_ENCRYPT_PORT_QNAME, Greeter.class);
    updateAddressPort(greeter, test.getPort());
    // Add a No-Op JAX-WS SoapHandler to the dispatch chain to
    // verify that the SoapHandlerInterceptor can peacefully co-exist
    // with the explicitly configured SAAJOutInterceptor
    // 
    @SuppressWarnings("rawtypes") List<Handler> handlerChain = new ArrayList<>();
    Binding binding = ((BindingProvider) greeter).getBinding();
    TestOutHandler handler = new TestOutHandler();
    handlerChain.add(handler);
    binding.setHandlerChain(handlerChain);
    greeter.sayHi();
    assertTrue("expected Handler.handleMessage() to be called", handler.handleMessageCalledOutbound);
    assertFalse("expected Handler.handleFault() not to be called", handler.handleFaultCalledOutbound);
    ((java.io.Closeable) greeter).close();
    b.shutdown(true);
    BusFactory.setDefaultBus(getStaticBus());
}
Also used : Binding(javax.xml.ws.Binding) SOAPBinding(javax.xml.ws.soap.SOAPBinding) HTTPBinding(javax.xml.ws.http.HTTPBinding) Bus(org.apache.cxf.Bus) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.hello_world_soap_http.Greeter) Test(org.junit.Test)

Example 19 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class AsyncHTTPConduitTest method testInovationWithHCAddress.

@Test
public void testInovationWithHCAddress() throws Exception {
    String address = "hc://http://localhost:" + PORT + "/SoapContext/SoapPort";
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Greeter.class);
    factory.setAddress(address);
    Greeter greeter = factory.create(Greeter.class);
    String response = greeter.greetMe("test");
    assertEquals("Get a wrong response", "Hello test", response);
}
Also used : Greeter(org.apache.hello_world_soap_http.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Test(org.junit.Test)

Example 20 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class AsyncHTTPConduitTest method testInvocationWithTransportId.

@Test
public void testInvocationWithTransportId() throws Exception {
    String address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Greeter.class);
    factory.setAddress(address);
    factory.setTransportId("http://cxf.apache.org/transports/http/http-client");
    Greeter greeter = factory.create(Greeter.class);
    String response = greeter.greetMe("test");
    assertEquals("Get a wrong response", "Hello test", response);
}
Also used : Greeter(org.apache.hello_world_soap_http.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Test(org.junit.Test)

Aggregations

Greeter (org.apache.hello_world_soap_http.Greeter)104 Test (org.junit.Test)78 SOAPService (org.apache.hello_world_soap_http.SOAPService)55 URL (java.net.URL)47 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)24 BindingProvider (javax.xml.ws.BindingProvider)23 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)21 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)21 Service (javax.xml.ws.Service)19 Client (org.apache.cxf.endpoint.Client)17 Endpoint (javax.xml.ws.Endpoint)13 QName (javax.xml.namespace.QName)10 Bus (org.apache.cxf.Bus)10 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)10 ExecutorService (java.util.concurrent.ExecutorService)9 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)7 File (java.io.File)6 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)6 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6 InvocationHandler (java.lang.reflect.InvocationHandler)5