Search in sources :

Example 91 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class TrustManagerTest method testInvalidServerCertX509TrustManager.

@org.junit.Test
public void testInvalidServerCertX509TrustManager() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TrustManagerTest.class.getResource("client-trust.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);
    updateAddressPort(port, PORT);
    String invalidPrincipalName = "CN=Bethal2,OU=Bethal,O=ApacheTest,L=Syracuse,C=US";
    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager = new ServerCertX509TrustManager(invalidPrincipalName);
    TrustManager[] trustManagers = new TrustManager[1];
    trustManagers[0] = trustManager;
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);
    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    try {
        port.greetMe("Kitty");
        fail("Failure expected on an invalid principal name");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) URL(java.net.URL) CertificateException(java.security.cert.CertificateException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) X509TrustManager(javax.net.ssl.X509TrustManager) Greeter(org.apache.hello_world.Greeter) Client(org.apache.cxf.endpoint.Client)

Example 92 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project BIMserver by opensourceBIM.

the class SoapChannel method connect.

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();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) PublicInterface(org.bimserver.shared.interfaces.PublicInterface) HashMap(java.util.HashMap) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean)

Example 93 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project uavstack by uavorg.

the class CECXFClient method configHttpConduit.

private void configHttpConduit(Object port) {
    // 设置客户端的配置信息,超时等.
    Client proxy = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    HTTPClientPolicy policy = new HTTPClientPolicy();
    // 连接服务器超时时间
    policy.setConnectionTimeout(this.connectTimeout);
    // 等待服务器响应超时时间
    policy.setReceiveTimeout(this.receiveTimeout);
    conduit.setClient(policy);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

Example 94 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit 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 95 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit 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

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8