package client;
import java.util.ArrayList;
import java.util.List;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import t.ITest222;
import t.ITests;
import t.TestPojo;
public class Test {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//不行
public static void test(){
// JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// factory.setServiceClass(ITest222.class);
// factory.setAddress("http://192.168.1.26:9085/WS_AXIS_WSS/service/test222");
// ITest222 service = (ITest222) factory.create();
//
// service.insertFlowInfos();
// t.start();
int i = 0;
while(i<300){
//如果放在外面,都是相同的Thread对象,如果上一次的线程没运行结束,又要start一次,就会报错
//mq关停的两种方式的区别,延迟问题已解决
Thread t = new Thread(new Runnable(){
public void run() {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
// String wsUrl = "http://192.168.1.26:8089/WS_CXF/CxfTest?wsdl";
// String method = "test";
String wsUrl = "http://127.0.0.1:8081/TgsWebService/TgsFuncitonPort?wsdl";
String method = "insertPassedCar";
Client client = dcf.createClient(wsUrl);
Object[] res = null;
try {
res = client.invoke(method, "01","鲁C12322","2015-1-1 1:1:1","321323000000000001","3","321323000000","3","3","3","3","3","http://192.168.1.26/ZTEDATAD/北京中路与相文路/卡口/由东向西/2015012914/北京中路与相文路$20150129143404$由东向西$苏NDM803.jpg","2","2","2");
} catch (java.lang.Exception e) {
e.printStackTrace();
}
System.out.println("res: "+res[0]);
}
});
t.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* wsdl地址,接口和接口的路径
*/
public static void clientToXML(){
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ITests.class);
factory.setAddress("http://192.168.1.26:8089/WS_CXF/CxfTest");
ITests service = (ITests) factory.create();
TestPojo tp = new TestPojo();
tp.setAge("22岁");
tp.setHigh("185米");
tp.setName("lvxianchao");
List<TestPojo> list = new ArrayList<TestPojo>();
list.add(tp);
list.add(tp);
list.add(tp);
String str = service.test2(list);
System.out.println("str: "+str);
String str2 = service.test("lvxianchao");
System.out.println("str2: "+str2);
}
/**
* 只有wsdl地址的写法,还有方法名和参数
*/
public static void noImplClass(){
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
// String wsUrl = "http://192.168.1.26:8089/WS_CXF/CxfTest?wsdl";
// String method = "test";
String wsUrl = "http://192.168.1.26:8088/TgsWebService/TgsFuncitonPort?wsdl";
String method = "insertPassedCar";
Client client = dcf.createClient(wsUrl);
Object[] res = null;
try {
res = client.invoke(method, "lvxianchao");
} catch (java.lang.Exception e) {
e.printStackTrace();
}
System.out.println("res: "+res.length+"\n"+res[0]);
}
public static void main(String[] args) {
// clientToXML();
// noImplClass();
test();
}
}