Java Code Examples for org.apache.cxf.endpoint.Client

The following examples show how to use org.apache.cxf.endpoint.Client. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-boot-study   Source File: WebserviceclientApplication.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {
    SpringApplication.run(WebserviceclientApplication.class, args);

    JaxWsDynamicClientFactory dcflient=JaxWsDynamicClientFactory.newInstance();

    Client client=dcflient.createClient("http://localhost:8080/ws/user?wsdl");
    try{
        Object[] objects=client.invoke("getUserById","1");
        System.out.println("getUserById 调用结果:"+objects[0].toString());

        Object[] objectall=client.invoke("getUsers");
        System.out.println("getUsers调用部分结果:"+objectall[0].toString());

    }catch (Exception e){
        e.printStackTrace();
    }
}
 
Example 2
Source Project: cxf   Source File: JAXWSClientMetricsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void usingClientProxyStopIsCalledForUnsupportedOperation() throws Exception {
    final JaxWsClientFactoryBean factory = new JaxWsClientFactoryBean();
    factory.setAddress("local://services/Book");
    factory.setServiceClass(IBookWebService.class);
    factory.setFeatures(Arrays.asList(new MetricsFeature(provider)));
    
    try {
        final Client client = factory.create();
        expectedException.expect(UncheckedException.class);
        client.invoke("getBooks");
    } finally {
        Mockito.verifyNoInteractions(endpointContext);
        Mockito.verifyNoInteractions(operationContext);
        Mockito.verifyNoInteractions(resourceContext);
    }
}
 
Example 3
Source Project: cxf   Source File: ClientFactoryBeanTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbExtraClass() throws Exception {

    ClientFactoryBean cfBean = new ClientFactoryBean();
    cfBean.setAddress("http://localhost/Hello");
    cfBean.setBus(getBus());
    cfBean.setServiceClass(HelloService.class);
    Map<String, Object> props = cfBean.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
              new Class[] {GreetMe.class, GreetMeOneWay.class});
    cfBean.setProperties(props);
    Client client = cfBean.create();
    assertNotNull(client);
    Class<?>[] extraClass = ((JAXBDataBinding)cfBean.getServiceFactory().getDataBinding())
        .getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], GreetMe.class);
    assertEquals(extraClass[1], GreetMeOneWay.class);
}
 
Example 4
Source Project: cxf   Source File: StaxRoundTripTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(WSSConstants.TIMESTAMP);
    properties.setActions(actions);

    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 5
Source Project: juddi   Source File: SAPRegistryJAXWSTransport.java    License: Apache License 2.0 6 votes vote down vote up
public UDDISecurityPortType getUDDISecurityService(String endpointURL) throws TransportException {

		if (securityService==null) {
			try {
				if (endpointURL==null)  {
					UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName);
					endpointURL = manager.getClientConfig().getUDDINode(nodeName).getSecurityUrl();
				}
				UDDIService service = new UDDIService();
				securityService = service.getUDDISecurityPort();
				Map<String, Object> requestContext = ((BindingProvider) securityService).getRequestContext();
				requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
				setCredentials(requestContext);

				XMLDeclarationWritingInterceptor xmldwi = new XMLDeclarationWritingInterceptor();				
				Client cxfClient = ClientProxy.getClient(securityService);
				cxfClient.getInInterceptors().add(xmldwi);

			} catch (Exception e) {
				throw new TransportException(e.getMessage(), e);
			}
		}
		return securityService;
	}
 
Example 6
Source Project: cxf   Source File: CXF6655Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectionWithProxy() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/", "HelloService");
    HelloService service = new HelloService(null, serviceName);
    assertNotNull(service);
    Hello hello = service.getHelloPort();

    Client client = ClientProxy.getClient(hello);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    HTTPConduit http = (HTTPConduit)client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(0);
    httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
    httpClientPolicy.setProxyServer("localhost");
    httpClientPolicy.setProxyServerPort(PROXY_PORT);
    http.setClient(httpClientPolicy);

    ((BindingProvider)hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                     "http://localhost:" + PORT + "/hello");
    assertEquals("getSayHi", hello.sayHi("SayHi"));

}
 
Example 7
Source Project: cxf   Source File: BusShutdownTest.java    License: Apache License 2.0 6 votes vote down vote up
private void doWork(URL wsdlUrl, String address) {
    SOAPService service = new SOAPService(wsdlUrl);
    assertNotNull(service);
    Greeter greeter = service.getSoapPort();

    // overwrite client address
    InvocationHandler handler = Proxy.getInvocationHandler(greeter);
    BindingProvider bp = (BindingProvider)handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                               address);
    Client client = ClientProxy.getClient(greeter);
    HTTPConduit c = (HTTPConduit)client.getConduit();
    c.setClient(new HTTPClientPolicy());
    c.getClient().setConnection(ConnectionType.CLOSE);

    // invoke twoway call
    greeter.sayHi();
}
 
Example 8
Source Project: cxf   Source File: DOMToStaxRoundTripTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<>();
    properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 9
Source Project: cxf   Source File: StaxRoundTripTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestampConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inConfig = new HashMap<>();
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 10
Source Project: cxf   Source File: JavaFirstSchemaValidationTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> T createClient(String port, Class<T> serviceClass, SchemaValidationType type,
        Feature ... features) {
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(serviceClass);


    clientFactory.setAddress(getAddress(port, serviceClass));

    if (features != null) {
        Collections.addAll(clientFactory.getFeatures(), features);
    }

    @SuppressWarnings("unchecked")
    T newClient = (T)clientFactory.create();

    Client proxy = ClientProxy.getClient(newClient);

    if (type != null) {
        proxy.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, type);
    }

    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    // give me longer debug times
    HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
    clientPolicy.setConnectionTimeout(1000000);
    clientPolicy.setReceiveTimeout(1000000);
    conduit.setClient(clientPolicy);

    return newClient;
}
 
Example 11
Source Project: cxf   Source File: StaxToDOMRoundTripTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(XMLSecurityConstants.ENCRYPTION);
    properties.setActions(actions);
    properties.setEncryptionUser("myalias");
    properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);

    Properties cryptoProperties =
        CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
    properties.setEncryptionCryptoProperties(cryptoProperties);
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 12
Source Project: cxf   Source File: JaxWsProxyFactoryBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
public void destroy() throws Exception {
    if (obj != null) {
        if (obj instanceof Closeable) {
            ((Closeable)obj).close();
        } else {
            Client c = ClientProxy.getClient(obj);
            c.destroy();
        }
        obj = null;
    }
}
 
Example 13
Source Project: cxf   Source File: BeanPostProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void verifyServices() throws Exception {
    JaxWsClientFactoryBean cf = new JaxWsClientFactoryBean();
    cf.setAddress("local://services/Alger");
    cf.setServiceClass(IWebServiceRUs.class);
    Client client = cf.create();
    String response = (String)client.invoke("consultTheOracle")[0];
    assertEquals("All your bases belong to us.", response);
    Service service = WebServiceRUs.getService();
    assertEquals(JAXBDataBinding.class, service.getDataBinding().getClass());
}
 
Example 14
Source Project: cxf   Source File: StaxToDOMEncryptionIdentifierTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncryptDirectReference() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION);
    inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    WSSSecurityProperties properties = new WSSSecurityProperties();
    List<WSSConstants.Action> actions = new ArrayList<>();
    actions.add(XMLSecurityConstants.ENCRYPTION);
    properties.setActions(actions);
    properties.setEncryptionUser("myalias");
    properties.setEncryptionKeyIdentifier(
        WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE
    );
    properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);

    Properties cryptoProperties =
        CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
    properties.setEncryptionCryptoProperties(cryptoProperties);
    properties.setCallbackHandler(new TestPwdCallback());
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 15
Source Project: cxf   Source File: ProtocolVariationsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRM10WSA15Decoupled() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", true);

    // WS-RM 1.0, but using the WS-A 1.0 namespace
    Client client = ClientProxy.getClient(greeter);
    client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names.WSA_NAMESPACE_NAME);

    assertEquals("ONE", greeter.greetMe("one"));
    assertEquals("TWO", greeter.greetMe("two"));
    assertEquals("THREE", greeter.greetMe("three"));

    verifyTwowayNonAnonymous(Names.WSA_NAMESPACE_NAME, RM10Constants.INSTANCE);
}
 
Example 16
Source Project: cxf   Source File: DOMToStaxSignatureIdentifierTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSignatureX509() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    Properties cryptoProperties =
        CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
    inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<>();
    properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
    properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    properties.put(ConfigurationConstants.USER, "myalias");
    properties.put(ConfigurationConstants.SIG_KEY_ID, "X509KeyIdentifier");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 17
Source Project: cxf   Source File: AegisClientServerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicClient() throws Exception {
    DynamicClientFactory dcf = DynamicClientFactory.newInstance();
    Client client = dcf.createClient("http://localhost:" + PORT + "/jaxwsAndAegisSports?wsdl&dynamic");

    Object r = client.invoke("getAttributeBean")[0];
    Method getAddrPlainString = r.getClass().getMethod("getAttrPlainString");
    String s = (String)getAddrPlainString.invoke(r);

    assertEquals("attrPlain", s);
}
 
Example 18
Source Project: cxf   Source File: ProtocolVariationsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidWSAOnReceive() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);

    // WS-RM 1.0 using the WS-A 1.0 namespace
    Client client = ClientProxy.getClient(greeter);
    client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI);
    client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME);

    // rewrite the outgoing message's WS-A namespace to an invalid one
    TransformOutInterceptor trans = new TransformOutInterceptor();
    Map<String, String> outElements = new HashMap<>();
    outElements.put("{" + Names200408.WSA_NAMESPACE_NAME + "}*", "{http://cxf.apache.org/invalid}*");
    trans.setOutTransformElements(outElements);

    client.getOutInterceptors().add(trans);
    try {
        greeter.greetMe("one");
        fail("invalid wsa header accepted");
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof SoapFault);
        // verify a partial error text match to exclude an unexpected exception
        // (see WSA_REQUIRED_EXC in Messages.properties)
        final String text = "WS-Addressing is required";
        assertTrue(e.getCause().getMessage() != null
            && e.getCause().getMessage().indexOf(text) >= 0);
    }
}
 
Example 19
Source Project: cxf   Source File: StaxToDOMSamlTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSaml1SignedSenderVouchesConfig() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(
        ConfigurationConstants.ACTION,
        ConfigurationConstants.SAML_TOKEN_UNSIGNED + " " + ConfigurationConstants.SIGNATURE
    );
    inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);

    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> outConfig = new HashMap<>();
    outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED);
    outConfig.put(ConfigurationConstants.SAML_CALLBACK_REF, new SAML1CallbackHandler());
    outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new PasswordCallbackHandler());
    outConfig.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
    WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);

    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 20
Source Project: onvif   Source File: OnvifDevice.java    License: Apache License 2.0 5 votes vote down vote up
public JaxWsProxyFactoryBean getServiceProxy(BindingProvider servicePort, String serviceAddr) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.getHandlers();

    if (serviceAddr != null) proxyFactory.setAddress(serviceAddr);
    proxyFactory.setServiceClass(servicePort.getClass());

    SoapBindingConfiguration config = new SoapBindingConfiguration();

    config.setVersion(Soap12.getInstance());
    proxyFactory.setBindingConfig(config);
    Client deviceClient = ClientProxy.getClient(servicePort);

    if (verbose) {
      // these logging interceptors are depreciated, but should be fine for debugging/development
      // use.
      proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
      proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    }

    HTTPConduit http = (HTTPConduit) deviceClient.getConduit();
    if (securityHandler != null) proxyFactory.getHandlers().add(securityHandler);
    HTTPClientPolicy httpClientPolicy = http.getClient();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setReceiveTimeout(32000);
    httpClientPolicy.setAllowChunking(false);

    return proxyFactory;
  }
 
Example 21
Source Project: cxf   Source File: ClientServerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBase64() throws Exception  {
    URL wsdl = getClass().getResource("/wsdl/others/dynamic_client_base64.wsdl");
    assertNotNull(wsdl);
    String wsdlUrl = null;
    wsdlUrl = wsdl.toURI().toString();
    CXFBusFactory busFactory = new CXFBusFactory();
    Bus bus = busFactory.createBus();
    DynamicClientFactory dynamicClientFactory = DynamicClientFactory.newInstance(bus);
    Client client = dynamicClientFactory.createClient(wsdlUrl);
    assertNotNull(client);
}
 
Example 22
Source Project: tomee   Source File: WebServiceInjectionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void checkConfiguration() {
    // assertEquals("ok", api.test()); // local call so skip it but check config which is actually the only interesting thing
    final Client client = ClientProxy.getClient(api);
    testPort(client);

    testPort(ClientProxy.getClient(service.getMyWsApi()));
    testPortWithFeature(ClientProxy.getClient(service.getMyWsApi(new AddressingFeature())));
}
 
Example 23
Source Project: cxf   Source File: DOMToStaxSignatureIdentifierTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSignatureDirectReference() throws Exception {
    // Create + configure service
    Service service = createService();

    WSSSecurityProperties inProperties = new WSSSecurityProperties();
    inProperties.setCallbackHandler(new TestPwdCallback());
    Properties cryptoProperties =
        CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
    inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
    WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
    service.getInInterceptors().add(inhandler);

    // Create + configure client
    Echo echo = createClientProxy();

    Client client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());

    Map<String, Object> properties = new HashMap<>();
    properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
    properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    properties.put(ConfigurationConstants.USER, "myalias");
    properties.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
    client.getOutInterceptors().add(ohandler);

    assertEquals("test", echo.echo("test"));
}
 
Example 24
Source Project: tomee   Source File: WebServiceInjectionConfigurator.java    License: Apache License 2.0 5 votes vote down vote up
private void configure(final Client client, final Properties properties) {
    if (properties == null) {
        return;
    }

    for (final String suffix : asList("", client.getEndpoint().getEndpointInfo().getName().toString() + ".")) {
        // here (ie at runtime) we have no idea which services were linked to the app
        // so using tomee.xml ones for now (not that shocking since we externalize the config with this class)
        configureInterceptors(client, CXF_JAXWS_CLIENT_PREFIX + suffix, lazyServiceInfoList(properties), properties);
    }
}
 
Example 25
Source Project: cxf   Source File: JaxWsDynamicClientTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testArrayList() throws Exception {
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(new URL("http://localhost:"
                                             + PORT1 + "/ArrayService?wsdl"));

    String[] values = new String[] {"foobar", "something" };
    List<String> list = Arrays.asList(values);

    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.invoke("init", list);
}
 
Example 26
Source Project: cxf   Source File: CircuitBreakerTargetSelector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onSuccess(InvocationContext context) {
    super.onSuccess(context);

    final Map<String, Object> requestContext =
        CastUtils.cast((Map<?, ?>)context.getContext().get(Client.REQUEST_CONTEXT));

    if (requestContext != null) {
        final String address = (String)requestContext.get(Message.ENDPOINT_ADDRESS);
        getCircuitBreaker(address).markSuccess();
    }
}
 
Example 27
Source Project: cxf   Source File: ClientServerPartialWsdlTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCXF4676Partial1() throws Exception {
    DynamicClientFactory dcf = DynamicClientFactory.newInstance();
    Client client = dcf.createClient("http://localhost:"
        + PORT + "/AddNumbersImplPartial1Service?wsdl", serviceName1, portName1);
    updateAddressPort(client, PORT);
    Object[] result = client.invoke("addTwoNumbers", 10, 20);
    assertNotNull("no response received from service", result);
    assertEquals(30, result[0]);
}
 
Example 28
Source Project: cxf   Source File: TransformFeatureTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClientOutTransformation() {
    Service service = Service.create(SERVICE_NAME);
    String endpoint = "http://localhost:" + PORT + "/EchoContext/EchoPort";
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

    Echo port = service.getPort(PORT_NAME, Echo.class);
    Client client = ClientProxy.getClient(port);
    XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(XSLT_REQUEST_PATH);
    client.getOutInterceptors().add(outInterceptor);
    String response = port.echo("test");
    assertTrue("Request was not transformed", response.contains(TRANSFORMED_CONSTANT));
}
 
Example 29
Source Project: cxf   Source File: TransformFeatureTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClientInTransformation() {
    Service service = Service.create(SERVICE_NAME);
    String endpoint = "http://localhost:" + PORT + "/EchoContext/EchoPort";
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

    Echo port = service.getPort(PORT_NAME, Echo.class);
    Client client = ClientProxy.getClient(port);
    XSLTInInterceptor inInterceptor = new XSLTInInterceptor(XSLT_RESPONSE_PATH);
    client.getInInterceptors().add(inInterceptor);
    String response = port.echo("test");
    assertTrue(response.contains(TRANSFORMED_CONSTANT));
}
 
Example 30
Source Project: cxf   Source File: InterceptorFaultTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRobustFailWithoutAddressingInUserLogicalPhase() throws Exception {

    setupGreeter("org/apache/cxf/systest/interceptor/no-addr.xml", false);

    control.setRobustInOnlyMode(true);

    // behaviour is identicial for all phases
    FaultLocation location = new org.apache.cxf.greeter_control.types.ObjectFactory()
        .createFaultLocation();
    location.setPhase("user-logical");

    control.setFaultLocation(location);

    try {
        // writer to grab the content of soap fault.
        // robust is not yet used at client's side, but I think it should
        StringWriter writer = new StringWriter();
        ((Client)greeter).getInInterceptors()
            .add(new LoggingInInterceptor(new PrintWriterEventSender(new PrintWriter(writer))));
        // it should tell CXF to convert one-way robust out faults into real SoapFaultException
        ((Client)greeter).getEndpoint().put(Message.ROBUST_ONEWAY, true);
        greeter.greetMeOneWay("oneway");
        fail("Oneway operation unexpectedly succeded for phase " + location.getPhase());
    } catch (SOAPFaultException ex) {
        //expected
    }
}