Java Code Examples for org.apache.cxf.jaxws.JaxWsProxyFactoryBean#setAddress()

The following examples show how to use org.apache.cxf.jaxws.JaxWsProxyFactoryBean#setAddress() . 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: MtomTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setupForTest(boolean enableClientMTOM) throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    aegisBinding.setMtomEnabled(enableClientMTOM);
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setDataBinding(aegisBinding);
    proxyFac.setAddress("http://localhost:" + PORT + "/mtom");

    JaxWsProxyFactoryBean jaxwsFac = new JaxWsProxyFactoryBean();
    jaxwsFac.setDataBinding(new AegisDatabinding());
    jaxwsFac.setAddress("http://localhost:" + PORT + "/jaxWsMtom");

    Map<String, Object> props = new HashMap<>();
    if (enableClientMTOM) {
        props.put("mtom-enabled", Boolean.TRUE);
    }
    proxyFac.setProperties(props);

    client = proxyFac.create(MtomTestService.class);
    jaxwsClient = jaxwsFac.create(MtomTestService.class);
    impl = (MtomTestImpl)applicationContext.getBean("mtomImpl");
}
 
Example 2
Source File: Client.java    From servicemix with Apache License 2.0 6 votes vote down vote up
public void sendRequest() throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:8181/cxf/HelloWorldSecurity");
    HelloWorld client = (HelloWorld) factory.create();
    
    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put("action", "UsernameToken");

    //add a CustomerSecurityInterceptor for client side to init wss4j staff
    //retrieve and set user/password,  users can easily add this interceptor
    //through spring configuration also
    ClientProxy.getClient(client).getOutInterceptors().add(new CustomerSecurityInterceptor());
    ClientProxy.getClient(client).getOutInterceptors().add(new WSS4JOutInterceptor());
    String ret = client.sayHi("ffang");
    System.out.println(ret);
}
 
Example 3
Source File: JaxwsBasicAuthTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseBasicAuthFromClient() throws Exception {
    // setup the feature by using JAXWS front-end API
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    // set a fake address to kick off the failover feature
    factory.setAddress("http://localhost:" + PORT + "/SoapContext/GreeterPort");
    factory.setServiceClass(Greeter.class);
    Greeter proxy = factory.create(Greeter.class);

    Client clientProxy = ClientProxy.getClient(proxy);
    HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit();
    conduit.getAuthorization().setAuthorizationType("Basic");
    conduit.getAuthorization().setUserName("user");
    conduit.getAuthorization().setPassword("test");
    
    final BindingProvider bindingProvider = (BindingProvider) proxy;
    bindingProvider.getRequestContext().put("encode.basicauth.with.iso8859", true);

    String response = proxy.greetMe("cxf");
    assertThat("CXF is protected: cxf", equalTo(response));
}
 
Example 4
Source File: SoapJmsSpecTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGzip() throws Exception {
    URL wsdl = getWSDLURL(WSDL);
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(JMSGreeterPortType.class);
    factory.setWsdlURL(wsdl.toExternalForm());
    factory.getFeatures().add(cff);
    factory.getFeatures().add(new GZIPFeature());
    factory.setAddress("jms:queue:test.cxf.jmstransport.queue6");
    JMSGreeterPortType greeter = (JMSGreeterPortType)markForClose(factory.create());

    for (int idx = 0; idx < 5; idx++) {

        greeter.greetMeOneWay("test String");

        String greeting = greeter.greetMe("Milestone-" + idx);
        Assert.assertEquals("Hello Milestone-" + idx, greeting);

        String reply = greeter.sayHi();
        Assert.assertEquals("Bonjour", reply);
    }
}
 
Example 5
Source File: AegisClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexMapResult() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();
    Map<String, Map<Integer, Integer>> result = service.testComplexMapResult();
    assertEquals(result.size(), 1);
    assertTrue(result.containsKey("key1"));
    assertNotNull(result.get("key1"));
    assertEquals(result.toString(), "{key1={1=3}}");
}
 
Example 6
Source File: SoapChannel.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void connect(TokenHolder tokenHolder) {
	for (Class<? extends PublicInterface> interface1 : interfaces) {
		JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
		cpfb.setServiceClass(interface1);
		cpfb.setAddress(address + "/" + interface1.getSimpleName());
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put("mtom-enabled", Boolean.TRUE);
		cpfb.setProperties(properties);
		
		PublicInterface serviceInterface = (PublicInterface) cpfb.create();
		
		client = ClientProxy.getClient(serviceInterface);
		HTTPConduit http = (HTTPConduit) client.getConduit();
		http.getClient().setConnectionTimeout(360000);
		http.getClient().setAllowChunking(false);
		http.getClient().setReceiveTimeout(320000);
		
		if (!useSoapHeaderSessions) {
			((BindingProvider) serviceInterface).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
		}
		add(interface1.getName(), serviceInterface);
	}
	tokenHolder.registerTokenChangeListener(this);
	notifyOfConnect();
}
 
Example 7
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInovationWithNettyAddress() throws Exception {
    String address = "netty://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);
}
 
Example 8
Source File: UDPTransportTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBroadcastUDP() throws Exception {
    // Disable the test on Redhat Enterprise Linux which doesn't enable the UDP broadcast by default
    if ("Linux".equals(System.getProperties().getProperty("os.name"))
        && System.getProperties().getProperty("os.version").indexOf("el") > 0) {
        System.out.println("Skipping broadcast test for REL");
        return;
    }

    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    int count = 0;
    while (interfaces.hasMoreElements()) {
        NetworkInterface networkInterface = interfaces.nextElement();
        if (!networkInterface.isUp() || networkInterface.isLoopback()) {
            continue;
        }
        count++;
    }
    if (count == 0) {
        //no non-loopbacks, cannot do broadcasts
        System.out.println("Skipping broadcast test");
        return;
    }

    JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
    fact.setAddress("udp://:" + PORT + "/foo");
    Greeter g = fact.create(Greeter.class);
    assertEquals("Hello World", g.greetMe("World"));

    ((java.io.Closeable)g).close();
}
 
Example 9
Source File: WebServiceIntegrationTestConfiguration.java    From tutorial-soap-spring-boot-cxf with MIT License 5 votes vote down vote up
@Bean
public WeatherService weatherServiceIntegrationTestClient() {
    JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
    jaxWsProxyFactory.setServiceClass(WeatherService.class);
    jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL);
    return (WeatherService) jaxWsProxyFactory.create();
}
 
Example 10
Source File: RemoteTestHarness.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
/**
 * Creates a published endpoint from the passed in serviceImplementation and also returns a proxy implementation
 * of the passed in interface for clients to use to hit the created endpoint.
 */
public <T> T publishEndpointAndReturnProxy(Class<T> jaxWsAnnotatedInterface, T serviceImplementation) {
    if (jaxWsAnnotatedInterface.isInterface() &&
            jaxWsAnnotatedInterface.getAnnotation(WebService.class) != null &&
            jaxWsAnnotatedInterface.isInstance(serviceImplementation)) {

        String endpointUrl = getAvailableEndpointUrl();
        LOG.info("Publishing service to: " + endpointUrl);
        endpoint = Endpoint.publish(endpointUrl, serviceImplementation);

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(jaxWsAnnotatedInterface);
        factory.setAddress(endpointUrl);

        T serviceProxy = (T) factory.create();

        /* Add the ImmutableCollectionsInInterceptor to mimic interceptors added in the KSB */
        Client cxfClient = ClientProxy.getClient(serviceProxy);
        cxfClient.getInInterceptors().add(new ImmutableCollectionsInInterceptor());

        return serviceProxy;
    } else {
        throw new IllegalArgumentException("Passed in interface class type must be annotated with @WebService " +
                "and object reference must be an implementing class of that interface.");

    }
}
 
Example 11
Source File: WebServiceIntegrationTestConfiguration.java    From tutorial-soap-spring-boot-cxf with MIT License 5 votes vote down vote up
@Bean
public WeatherService weatherServiceIntegrationTestClient() {
    JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
    jaxWsProxyFactory.setServiceClass(WeatherService.class);
    jaxWsProxyFactory.setAddress("http://localhost:8080" + WebServiceConfiguration.BASE_URL + WebServiceConfiguration.SERVICE_URL);
    return (WeatherService) jaxWsProxyFactory.create();
}
 
Example 12
Source File: WeatherServiceTestConfiguration.java    From cxf-spring-cloud-netflix-docker with MIT License 5 votes vote down vote up
@Bean
public WeatherService weatherServiceClient() {
    JaxWsProxyFactoryBean jaxWsFactory = new JaxWsProxyFactoryBean();
    jaxWsFactory.setServiceClass(WeatherService.class);
    jaxWsFactory.setAddress(buildUrl());
    return (WeatherService) jaxWsFactory.create();
}
 
Example 13
Source File: SimpleEventingIntegrationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to create a client for the testing Subscription Manager
 * which is located at local://SimpleSubscriptionManager.
 * You have to specify the reference parameters you obtained from the Event Source
 * when your subscription was created.
 *
 * @return a JAX-WS client set up for managing the subscription you had created using the Event Source
 */
public SubscriptionManagerEndpoint createSubscriptionManagerClient(ReferenceParametersType refs) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(SubscriptionManagerEndpoint.class);
    factory.setAddress(URL_SUBSCRIPTION_MANAGER);
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    ReferenceParametersAddingHandler handler = new ReferenceParametersAddingHandler(refs);
    factory.getHandlers().add(handler);
    return (SubscriptionManagerEndpoint)factory.create();
}
 
Example 14
Source File: ClientDemo.java    From spring-cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setAddress("http://localhost:8080/ws-server-1.0/api/hello");
    factory.setServiceClass(HelloWorld.class);

    HelloWorld client = (HelloWorld) factory.create();
    String response = client.sayHi("hi, you beautiful world!");
    System.out.println("Response from server: " + response);
}
 
Example 15
Source File: TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static Resource createResourceClient(EndpointReferenceType ref) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Resource.class);
    factory.setAddress(ref.getAddress().getValue());
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    addrProps.setTo(ref);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 16
Source File: LeaveWebServiceBusinessTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 不需要总经理审批
 * @throws ParseException
 */
@Test
public void testFalse() throws ParseException {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.setServiceClass(LeaveWebService.class);
    factory.setAddress(LeaveWebserviceUtil.WEBSERVICE_URL);
    LeaveWebService leaveWebService = (LeaveWebService) factory.create();
    boolean audit = leaveWebService.generalManagerAudit("2013-01-01 09:00", "2013-01-04 17:30");
    assertFalse(audit);
}
 
Example 17
Source File: CxfClientPluginIT.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    Endpoint.publish("http://localhost:" + port + "/cxf/helloWorld", new HelloWorldImpl());
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:" + port + "/cxf/helloWorld");
    client = (HelloWorld) factory.create();

    transactionMarker();
}
 
Example 18
Source File: AegisClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testReturnQualifiedPair() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();
    Pair<Integer, String> ret = service.getReturnQualifiedPair(111, "ffang");
    assertEquals(Integer.valueOf(111), ret.getFirst());
    assertEquals("ffang", ret.getSecond());
}
 
Example 19
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 20
Source File: JAXWSEnvironment.java    From dropwizard-jaxws with Apache License 2.0 4 votes vote down vote up
/**
 * JAX-WS client factory
 * @param clientBuilder ClientBuilder.
 * @param <T> Service interface type.
 * @return JAX-WS client proxy.
 */
public <T> T getClient(ClientBuilder<T> clientBuilder) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setServiceClass(clientBuilder.getServiceClass());
    proxyFactory.setAddress(clientBuilder.getAddress());

    // JAX-WS handlers
    if (clientBuilder.getHandlers() != null) {
        for (Handler h : clientBuilder.getHandlers()) {
            proxyFactory.getHandlers().add(h);
        }
    }

    // ClientProxyFactoryBean bindingId
    if (clientBuilder.getBindingId() != null) {
        proxyFactory.setBindingId(clientBuilder.getBindingId());
    }

    // CXF interceptors
    if (clientBuilder.getCxfInInterceptors() != null) {
        proxyFactory.getInInterceptors().addAll(clientBuilder.getCxfInInterceptors());
    }
    if (clientBuilder.getCxfInFaultInterceptors() != null) {
        proxyFactory.getInFaultInterceptors().addAll(clientBuilder.getCxfInFaultInterceptors());
    }
    if (clientBuilder.getCxfOutInterceptors() != null) {
        proxyFactory.getOutInterceptors().addAll(clientBuilder.getCxfOutInterceptors());
    }
    if (clientBuilder.getCxfOutFaultInterceptors() != null) {
        proxyFactory.getOutFaultInterceptors().addAll(clientBuilder.getCxfOutFaultInterceptors());
    }

    T proxy = clientBuilder.getServiceClass().cast(proxyFactory.create());

    // MTOM support
    if (clientBuilder.isMtomEnabled()) {
        BindingProvider bp = (BindingProvider)proxy;
        SOAPBinding binding = (SOAPBinding)bp.getBinding();
        binding.setMTOMEnabled(true);
    }

    HTTPConduit http = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
    HTTPClientPolicy client = http.getClient();
    client.setConnectionTimeout(clientBuilder.getConnectTimeout());
    client.setReceiveTimeout(clientBuilder.getReceiveTimeout());

    return proxy;
}