org.apache.cxf.endpoint.Client Java Examples

The following examples show how to use org.apache.cxf.endpoint.Client. 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 File: SAPRegistryJAXWSTransport.java    From juddi with 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 #2
Source File: StaxRoundTripTest.java    From cxf with 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 #3
Source File: DOMToStaxRoundTripTest.java    From cxf with 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 #4
Source File: JAXWSClientMetricsTest.java    From cxf with 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 #5
Source File: BusShutdownTest.java    From cxf with 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 #6
Source File: ClientFactoryBeanTest.java    From cxf with 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 #7
Source File: WebserviceclientApplication.java    From spring-boot-study with 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 #8
Source File: StaxRoundTripTest.java    From cxf with 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 #9
Source File: CXF6655Test.java    From cxf with 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 #10
Source File: TransformFeatureTest.java    From cxf with 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 #11
Source File: StaxToDOMSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaml2() throws Exception {
    // Create + configure service
    Service service = createService();

    Map<String, Object> inProperties = new HashMap<>();
    inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
    final Map<QName, Object> customMap = new HashMap<>();
    CustomSamlValidator validator = new CustomSamlValidator();
    validator.setRequireSAML1Assertion(false);
    customMap.put(WSConstants.SAML_TOKEN, validator);
    customMap.put(WSConstants.SAML2_TOKEN, validator);
    inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
    inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
    service.getInInterceptors().add(inInterceptor);
    service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");

    // 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.SAML_TOKEN_UNSIGNED);
    properties.setActions(actions);
    properties.setSamlCallbackHandler(new SAML2CallbackHandler());

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

    assertEquals("test", echo.echo("test"));
}
 
Example #12
Source File: InterceptorFaultTest.java    From cxf with 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
    }
}
 
Example #13
Source File: PasswordPropertiesTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAsymmetricBinding() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();

    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = PasswordPropertiesTest.class.getResource("DoubleItPassword.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricPort");

    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }

    Client client = ClientProxy.getClient(port);
    client.getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "alice");
    client.getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    client.getRequestContext().put(SecurityConstants.SIGNATURE_PASSWORD, "password");
    client.getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "bob");
    client.getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");

    assertEquals(50, port.doubleIt(25));

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example #14
Source File: DOMToStaxRoundTripTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignatureTimestamp() 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.TIMESTAMP + " " + ConfigurationConstants.SIGNATURE
    );
    properties.put(
        ConfigurationConstants.SIGNATURE_PARTS,
        "{}{" + WSSConstants.NS_WSU10 + "}Timestamp;"
        + "{}{" + WSSConstants.NS_SOAP11 + "}Body;"
    );
    properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
    properties.put(ConfigurationConstants.USER, "myalias");

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

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

    // 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 File: UsernameTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testPasswordHashedReplay() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = UsernameTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    QName portQName = new QName(NAMESPACE, "DoubleItHashedPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (!test.isStreaming()) {
        Client cxfClient = ClientProxy.getClient(utPort);
        SecurityHeaderCacheInterceptor cacheInterceptor =
            new SecurityHeaderCacheInterceptor();
        cxfClient.getOutInterceptors().add(cacheInterceptor);

        // Make two invocations with the same UsernameToken
        assertEquals(50, utPort.doubleIt(25));
        try {
            utPort.doubleIt(25);
            fail("Failure expected on a replayed UsernameToken");
        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
            assertTrue(ex.getMessage().contains(WSSecurityException.UNIFIED_SECURITY_ERR));
        }
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example #17
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testPasswordHashedNoBindingReplay() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = UsernameTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    QName portQName = new QName(NAMESPACE, "DoubleItDigestNoBindingPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (!test.isStreaming() && PORT.equals(test.getPort())) {
        Client cxfClient = ClientProxy.getClient(utPort);
        SecurityHeaderCacheInterceptor cacheInterceptor =
            new SecurityHeaderCacheInterceptor();
        cxfClient.getOutInterceptors().add(cacheInterceptor);

        // Make two invocations with the same UsernameToken
        assertEquals(50, utPort.doubleIt(25));
        try {
            utPort.doubleIt(25);
            fail("Failure expected on a replayed UsernameToken");
        } catch (javax.xml.ws.soap.SOAPFaultException ex) {
            assertEquals(ex.getMessage(), WSSecurityException.UNIFIED_SECURITY_ERR);
        }
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example #18
Source File: ProtocolVariationsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRM10WSA200408() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);

    // same as default, but explicitly setting the WS-Addressing namespace
    Client client = ClientProxy.getClient(greeter);
    client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME);

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

    verifyTwowayNonAnonymous(Names200408.WSA_NAMESPACE_NAME, RM10Constants.INSTANCE);
}
 
Example #19
Source File: DOMToStaxRoundTripTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncryptUsernameToken() 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.setDecryptionCryptoProperties(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.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPTION
    );
    properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
    properties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
    properties.put(ConfigurationConstants.USER, "username");
    properties.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");

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

    assertEquals("test", echo.echo("test"));
}
 
Example #20
Source File: DOMToStaxSignatureIdentifierTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignatureIssuerSerial() 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, "IssuerSerial");

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

    assertEquals("test", echo.echo("test"));
}
 
Example #21
Source File: ClientServerTest.java    From cxf with 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 File: ClientServerPartialWsdlTest.java    From cxf with 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 #23
Source File: CircuitBreakerTargetSelector.java    From cxf with 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 #24
Source File: TransformFeatureTest.java    From cxf with 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 #25
Source File: JaxWsDynamicClientTest.java    From cxf with 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 File: WebServiceInjectionConfigurator.java    From tomee with 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 #27
Source File: DOMToStaxSignatureIdentifierTest.java    From cxf with 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 #28
Source File: StaxToDOMEncryptionIdentifierTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncryptIssuerSerial() 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_IssuerSerial
    );
    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 #29
Source File: JaxWsClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientProxyFactory() {
    JaxWsProxyFactoryBean cf = new JaxWsProxyFactoryBean();
    cf.setAddress("http://localhost:9000/test");
    Greeter greeter = cf.create(Greeter.class);
    /*  .n.b. don't call call create with an argument and change the SEI. */
    Greeter greeter2 = (Greeter) cf.create();
    Greeter greeter3 = (Greeter) cf.create();

    Client c = (Client)greeter;
    Client c2 = (Client)greeter2;
    Client c3 = (Client)greeter3;
    assertNotSame(c, c2);
    assertNotSame(c, c3);
    assertNotSame(c3, c2);
    assertNotSame(c.getEndpoint(), c2.getEndpoint());
    assertNotSame(c.getEndpoint(), c3.getEndpoint());
    assertNotSame(c3.getEndpoint(), c2.getEndpoint());

    c3.getInInterceptors();

    ((BindingProvider)greeter).getRequestContext().put("test", "manny");
    ((BindingProvider)greeter2).getRequestContext().put("test", "moe");
    ((BindingProvider)greeter3).getRequestContext().put("test", "jack");

    assertEquals("manny", ((BindingProvider)greeter).getRequestContext().get("test"));
    assertEquals("moe", ((BindingProvider)greeter2).getRequestContext().get("test"));
    assertEquals("jack", ((BindingProvider)greeter3).getRequestContext().get("test"));
}
 
Example #30
Source File: WebServiceInjectionTest.java    From tomee with 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())));
}