Search in sources :

Example 1 with TestService_Service

use of com.creditease.monitorframework.fat.client.TestService_Service in project uavstack by uavorg.

the class DoTestJaxWSHook method main.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) {
    ConsoleLogger cl = new ConsoleLogger("test");
    cl.setDebugable(true);
    UAVServer.instance().setLog(cl);
    UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
    Map config = new HashMap();
    Map adapts = JSONHelper.toObject("{\"org.apache.cxf.frontend.ClientProxy\":{\"getClient\":{args:[\"java.lang.Object\"],target:0}}}", Map.class);
    config.put("adapts", adapts);
    JaxWSHookProxy jp = new JaxWSHookProxy("test", config);
    jp.doInstallDProxy(null, "test");
    TestService_Service s = new TestService_Service();
    TestService ts = s.getTestServicePort();
    // 设置客户端的配置信息,超时等.
    Client proxy = ClientProxy.getClient(ts);
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    HTTPClientPolicy policy = new HTTPClientPolicy();
    // 连接服务器超时时间
    policy.setConnectionTimeout(30000);
    // 等待服务器响应超时时间
    policy.setReceiveTimeout(30000);
    conduit.setClient(policy);
    ts.echo();
    try {
        ts.echoFault();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Dispatch<SOAPMessage> d = s.createDispatch(new QName("http://service.fat.monitorframework.creditease.com/", "TestServicePort"), SOAPMessage.class, Mode.MESSAGE);
    try {
        SOAPMessage msg = MessageFactory.newInstance().createMessage();
        d.invoke(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("--------------->CECXFClient");
    CECXFClient client = new CECXFClient(TestService_Service.class, TestService.class, TestService_Service.TestServicePort);
    client.setConnectTimeout(30000);
    client.setReceiveTimeout(30000);
    try {
        client.invoke("echo", null);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) QName(javax.xml.namespace.QName) SOAPMessage(javax.xml.soap.SOAPMessage) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) CECXFClient(com.creditease.monitorframework.fat.client.CECXFClient) Client(org.apache.cxf.endpoint.Client) CECXFClient(com.creditease.monitorframework.fat.client.CECXFClient) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TestService_Service

use of com.creditease.monitorframework.fat.client.TestService_Service in project uavstack by uavorg.

the class CXFClientE2ETest method doGet.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest request,
 *      javax.servlet.http.HttpServletResponse response)
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String test = request.getParameter("test");
    if (test == null || "good".equals(test)) {
        TestService_Service service = new TestService_Service();
        TestService ts = service.getPort(TestService.class);
        ts.echo();
    } else if ("fault".equals(test)) {
        TestService_Service service = new TestService_Service();
        TestService ts = service.getPort(TestService.class);
        ts.echoFault();
    } else if ("async1".equals(test)) {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(TestService_Service.WSDL_LOCATION);
        try {
            client.invokeWrapped(new ClientCallback() {

                @Override
                public void handleResponse(Map<String, Object> ctx, Object[] res) {
                    super.handleResponse(ctx, res);
                }

                @Override
                public void handleException(Map<String, Object> ctx, Throwable ex) {
                    super.handleException(ctx, ex);
                }
            }, "echo");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if ("async0".equals(test)) {
        Service sr = Service.create(TestService_Service.WSDL_LOCATION, TestService_Service.SERVICE);
        JAXBContext jc = null;
        try {
            jc = JAXBContext.newInstance("com.creditease.monitorframework.fat.client");
        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Dispatch d = sr.createDispatch(TestService_Service.TestServicePort, jc, Mode.PAYLOAD);
        d.invokeAsync(null, new AsyncHandler() {

            @Override
            public void handleResponse(Response res) {
                if (res.isDone()) {
                    try {
                        System.out.println(res.get());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
Also used : JaxWsDynamicClientFactory(org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory) ClientCallback(org.apache.cxf.endpoint.ClientCallback) AsyncHandler(javax.xml.ws.AsyncHandler) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) JAXBException(javax.xml.bind.JAXBException) Service(javax.xml.ws.Service) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) Dispatch(javax.xml.ws.Dispatch) JAXBContext(javax.xml.bind.JAXBContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ExecutionException(java.util.concurrent.ExecutionException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.xml.ws.Response) Client(org.apache.cxf.endpoint.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with TestService_Service

use of com.creditease.monitorframework.fat.client.TestService_Service in project uavstack by uavorg.

the class WSService method test.

@GET
@Path("test")
public String test() {
    TestService_Service s = new TestService_Service();
    TestService ts = s.getTestServicePort();
    // 设置客户端的配置信息,超时等.
    Client proxy = ClientProxy.getClient(ts);
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    HTTPClientPolicy policy = new HTTPClientPolicy();
    // 连接服务器超时时间
    policy.setConnectionTimeout(30000);
    // 等待服务器响应超时时间
    policy.setReceiveTimeout(30000);
    conduit.setClient(policy);
    ts.echo();
    return "web service perfect";
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with TestService_Service

use of com.creditease.monitorframework.fat.client.TestService_Service in project uavstack by uavorg.

the class ChainService method circleTest.

@GET
@Path("circle_test")
public String circleTest(@QueryParam("time") int time) throws SQLException {
    if (time == 10) {
        return "";
    }
    // 首先进行redis读写操作
    System.out.println("Jedis OPS======================================================");
    Jedis jedis = new Jedis("localhost", 6379);
    jedis.set("foo", "bar");
    jedis.get("foo");
    jedis.close();
    // 进行服务之间交互
    CloseableHttpClient client = HttpClients.createDefault();
    HttpUriRequest http = new HttpGet("http://localhost:8080/com.creditease.uav.monitorframework.buildFat/rs/http/httpclienttest");
    try {
        HttpResponse resp1 = client.execute(http);
        System.out.println(resp1.getStatusLine());
        client.close();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // ws调用begin
    TestService_Service s = new TestService_Service();
    TestService ts = s.getTestServicePort();
    // 设置客户端的配置信息,超时等.
    Client proxy = ClientProxy.getClient(ts);
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    HTTPClientPolicy policy = new HTTPClientPolicy();
    // 连接服务器超时时间
    policy.setConnectionTimeout(30000);
    // 等待服务器响应超时时间
    policy.setReceiveTimeout(30000);
    conduit.setClient(policy);
    ts.echo();
    // ws调用end
    // mysql调用
    Connection c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/testdb", "root", "root");
    System.out.println("Statement -------------------->");
    Statement st = c.createStatement();
    st.execute("insert into mytest values (1,'zz',23)");
    st.close();
    System.out.println("PreparedStatement -------------------->");
    PreparedStatement ps = c.prepareStatement("insert into mytest values (?,?,?)");
    ps.setInt(1, 1);
    ps.setString(2, "zz");
    ps.setInt(3, 23);
    ps.execute();
    ps.close();
    ps = c.prepareStatement("select name from mytest where id=?");
    ps.setInt(1, 1);
    ps.executeQuery();
    ps.close();
    ps = c.prepareStatement("update mytest set age=24 where id=?");
    ps.setInt(1, 1);
    ps.executeUpdate();
    ps.close();
    ps = c.prepareStatement("delete from mytest where id=?");
    ps.setInt(1, 1);
    ps.executeUpdate();
    ps.close();
    c.close();
    // mongo
    MongoClient mongoClient = new MongoClient();
    mongoClient.listDatabaseNames().first();
    MongoDatabase db = mongoClient.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    MongoCollection<Document> collection = db.getCollection("test");
    collection.listIndexes().first();
    Document doc = new Document("name", "Amarcord Pizzeria").append("contact", new Document("phone", "264-555-0193").append("email", "amarcord.pizzeria@example.net").append("location", Arrays.asList(-73.88502, 40.749556))).append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
    collection.insertOne(doc);
    collection.find().first();
    mongoClient.close();
    // 进行服务之间交互
    CloseableHttpClient client2 = HttpClients.createDefault();
    time++;
    HttpUriRequest http2 = new HttpGet("http://localhost:8080/com.creditease.uav.monitorframework.buildFat/rs/chain/circle_test" + "?time=" + time);
    try {
        HttpResponse resp1 = client2.execute(http2);
        System.out.println(resp1.getStatusLine());
        client2.close();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // dubbo调用begin
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
    IMyDubboService mds = (IMyDubboService) wac.getBean("myDubboServiceC");
    mds.sayHello("zz");
    return "circle test perfect";
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) HttpGet(org.apache.http.client.methods.HttpGet) Connection(java.sql.Connection) HttpResponse(org.apache.http.HttpResponse) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) Document(org.bson.Document) ClientProtocolException(org.apache.http.client.ClientProtocolException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Jedis(redis.clients.jedis.Jedis) MongoClient(com.mongodb.MongoClient) IMyDubboService(com.creditease.monitorframework.fat.dubbo.IMyDubboService) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Client(org.apache.cxf.endpoint.Client) MongoClient(com.mongodb.MongoClient) MongoDatabase(com.mongodb.client.MongoDatabase) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

TestService (com.creditease.monitorframework.fat.client.TestService)4 TestService_Service (com.creditease.monitorframework.fat.client.TestService_Service)4 Client (org.apache.cxf.endpoint.Client)4 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)3 IOException (java.io.IOException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)1 CECXFClient (com.creditease.monitorframework.fat.client.CECXFClient)1 IMyDubboService (com.creditease.monitorframework.fat.dubbo.IMyDubboService)1 MongoClient (com.mongodb.MongoClient)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 ServletException (javax.servlet.ServletException)1