org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory Java Examples

The following examples show how to use org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory. 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: ApplicationTests.java    From SpringBootBucket with MIT License 6 votes vote down vote up
/**
 * 方式2. 动态调用方式
 */
@Test
public void cl2() {
    // 创建动态客户端
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(wsdlAddress);
    // 需要密码的情况需要加上用户名和密码
    // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));
    Object[] objects;
    try {
        // invoke("方法名",参数1,参数2,参数3....);
        objects = client.invoke("sayHello", "Leftso");
        System.out.println("返回类型:" + objects[0].getClass());
        System.out.println("返回数据:" + objects[0]);
    } catch (java.lang.Exception e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: ApplicationTests.java    From SpringBootBucket with MIT License 6 votes vote down vote up
/**
 * 方式3. 动态调用方式,返回对象User
 */
@Test
public void cl3() {
    // 创建动态客户端
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(wsdlAddress);
    Object[] objects;
    try {
        // invoke("方法名",参数1,参数2,参数3....);
        objects = client.invoke("getUser", "张三");
        System.out.println("返回类型:" + objects[0].getClass());
        System.out.println("返回数据:" + objects[0]);
        User user = (User) objects[0];
        System.out.println("返回对象User.name=" + user.getName());
    } catch (java.lang.Exception e) {
        e.printStackTrace();
    }
}
 
Example #3
Source File: CxfWebServiceClient.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public CxfWebServiceClient(String wsdl) {
  JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
      Enumeration<URL> xjcBindingUrls;
      try {
          xjcBindingUrls = Thread.currentThread().getContextClassLoader()
                  .getResources(CxfWSDLImporter.JAXB_BINDINGS_RESOURCE);
          if (xjcBindingUrls.hasMoreElements()) {
              final URL xjcBindingUrl = xjcBindingUrls.nextElement();
              if (xjcBindingUrls.hasMoreElements()) {
                  throw new ActivitiException("Several JAXB binding definitions found for activiti-cxf: "
                          + CxfWSDLImporter.JAXB_BINDINGS_RESOURCE);
              }
              this.client = dcf.createClient(wsdl, Arrays.asList(new String[] { xjcBindingUrl.toString() }));
              this.client.getRequestContext().put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
          } else {
              throw new ActivitiException("The JAXB binding definitions are not found for activiti-cxf: "
                      + CxfWSDLImporter.JAXB_BINDINGS_RESOURCE);
          }
      } catch (IOException e) {
          throw new ActivitiException("An error occurs creating a web-service client for WSDL '" + wsdl + "'.", e);
      }
}
 
Example #4
Source File: CxfWebServiceClient.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public CxfWebServiceClient(String wsdl) {
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Enumeration<URL> xjcBindingUrls;
    try {
        xjcBindingUrls = Thread.currentThread().getContextClassLoader()
                .getResources(CxfWSDLImporter.JAXB_BINDINGS_RESOURCE);
        if (xjcBindingUrls.hasMoreElements()) {
            final URL xjcBindingUrl = xjcBindingUrls.nextElement();
            if (xjcBindingUrls.hasMoreElements()) {
                throw new FlowableException("Several JAXB binding definitions found for flowable-cxf: "
                        + CxfWSDLImporter.JAXB_BINDINGS_RESOURCE);
            }
            this.client = dcf.createClient(wsdl, Arrays.asList(new String[] { xjcBindingUrl.toString() }));
            this.client.getRequestContext().put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
        } else {
            throw new FlowableException("The JAXB binding definitions are not found for flowable-cxf: "
                    + CxfWSDLImporter.JAXB_BINDINGS_RESOURCE);
        }
    } catch (IOException e) {
        throw new FlowableException("An error occurs creating a web-service client for WSDL '" + wsdl + "'.", e);
    }
}
 
Example #5
Source File: SOAPServiceTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
    * Tests WSDL generation from a URL.
    *
    * This is similar to another KEW test but it is good to have it as part of the KSB tests.  Note that the
    * {@link Client} modifies the current thread's class loader.
    *
    * @throws Exception for any errors connecting to the client
    */
@Test
public void testWsdlGeneration() throws Exception {
	ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();

       try {
           JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
           Client client = dcf.createClient(new URI(getWsdlUrl()).toString());
           client.getInInterceptors().add(new LoggingInInterceptor());
           client.getOutInterceptors().add(new LoggingOutInterceptor());
           Object[] results = client.invoke("echo", "testing");
           assertNotNull(results);
           assertEquals(1, results.length);
           assertEquals("testing", results[0]);
       } finally {
           Thread.currentThread().setContextClassLoader(originalClassLoader);
       }
}
 
Example #6
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 #7
Source File: JaxWsDynamicClientTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvocation() throws Exception {
    JaxWsDynamicClientFactory dcf =
        JaxWsDynamicClientFactory.newInstance();
    URL wsdlURL = new URL("http://localhost:" + PORT + "/NoBodyParts/NoBodyPartsService?wsdl");
    Client client = dcf.createClient(wsdlURL);
    byte[] bucketOfBytes =
        IOUtils.readBytesFromStream(getClass().getResourceAsStream("/wsdl/no_body_parts.wsdl"));
    Operation1 parameters = new Operation1();
    parameters.setOptionString("opt-ion");
    parameters.setTargetType("tar-get");
    Object[] rparts = client.invoke("operation1", parameters, bucketOfBytes);
    Operation1Response r = (Operation1Response)rparts[0];
    assertEquals(digest(bucketOfBytes), r.getStatus());

    ClientCallback callback = new ClientCallback();
    client.invoke(callback, "operation1", parameters, bucketOfBytes);
    rparts = callback.get();
    r = (Operation1Response)rparts[0];
    assertEquals(digest(bucketOfBytes), r.getStatus());
}
 
Example #8
Source File: UndertowDigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetWSDL() throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());

    MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);
    factory.createClient(ADDRESS + "?wsdl");
}
 
Example #9
Source File: HTTPSClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public final void testSuccessfulCall(String configuration,
                                     String address,
                                     URL url,
                                     boolean dynamicClient) throws Exception {
    setTheConfiguration(configuration);
    startServers();
    if (url == null) {
        url = SOAPService.WSDL_LOCATION;
    }

    //CXF-4037 - dynamic client isn't using the conduit settings to resolve schemas
    if (dynamicClient) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        JaxWsDynamicClientFactory.newInstance(BusFactory.getDefaultBus())
            .createClient(url.toExternalForm());
        Thread.currentThread().setContextClassLoader(loader);
    }



    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    BindingProvider provider = (BindingProvider)port;
    provider.getRequestContext().put(
          BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
          address);

    //for (int x = 0; x < 100000; x++) {
    assertEquals(port.greetMe("Kitty"), "Hello Kitty");
    //}


    stopServers();
}
 
Example #10
Source File: JettyBasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testGetWSDL() throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());

    MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);
    factory.createClient(ADDRESS + "?wsdl");
}
 
Example #11
Source File: JettyDigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testGetWSDL() throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());

    MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);
    factory.createClient(ADDRESS + "?wsdl");
}
 
Example #12
Source File: JaxWsDynamicClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testArgfiles() throws Exception {
    System.setProperty("org.apache.cxf.common.util.Compiler-fork", "true");
    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 #13
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 #14
Source File: UndertowBasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testGetWSDL() throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());

    MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);
    factory.createClient(ADDRESS + "?wsdl");
}
 
Example #15
Source File: WebservicesClient.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Object[] jaxws(String wsdl, String method, Object... objects) {
	Object[] result = null;
	try {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		result = client.invoke(method, objects);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return result;
}
 
Example #16
Source File: WebservicesClient.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Object[] jaxws(String wsdl, String method, Object... objects) {
	Object[] result = null;
	try {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		result = client.invoke(method, objects);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return result;
}
 
Example #17
Source File: WebservicesClient.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Object[] jaxws(String wsdl, String method, Object... objects) {
	Object[] result = null;
	try {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		result = client.invoke(method, objects);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return result;
}
 
Example #18
Source File: CXF5061Test.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testCxf5061() throws Exception {
    //using dcf to generate client from the wsdl which ensure the wsdl is valid
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    dcf.createClient(ADDRESS + "?wsdl");
}
 
Example #19
Source File: SoapClient.java    From jea with Apache License 2.0 4 votes vote down vote up
public SoapClient(URL wsdlUrl) {
	super(wsdlUrl);
	
	JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
       client = dcf.createClient(this.httpUrl);
}
 
Example #20
Source File: JaxWsFactoryUtils.java    From base-framework with Apache License 2.0 2 votes vote down vote up
/**
 * 获取JaxWs动态客服端工厂
 * 
 * @return {@link JaxWsDynamicClientFactory}
 */
public static JaxWsDynamicClientFactory getJaxWsDynamicClientFactory() {
	return jaxWsDynamicClientFactory;
}