Search in sources :

Example 46 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project tesb-rt-se by Talend.

the class MonitoringServiceFullTest method testSendEvents.

// @Before
// public void setUp() throws Exception {
// executeSqlScript("create.sql", true);
// }
@Test
public void testSendEvents() throws PutEventsFault, MalformedURLException, URISyntaxException {
    Client client = ClientProxy.getClient(monitoringService);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy clientConfig = new HTTPClientPolicy();
    clientConfig.setReceiveTimeout(100000);
    conduit.setClient(clientConfig);
    jdbcTemplate.update("delete from EVENTS");
    List<EventType> events = new ArrayList<EventType>();
    EventType eventType = new EventType();
    eventType.setEventType(EventEnumType.REQ_OUT);
    URL messageContentFile = this.getClass().getResource("/testmessage.xml").toURI().toURL();
    eventType.setContent(new DataHandler(messageContentFile));
    CustomInfoType ciType = new CustomInfoType();
    CustomInfoType.Item prop1 = new CustomInfoType.Item();
    prop1.setKey("mykey1");
    prop1.setValue("myValue1");
    ciType.getItem().add(prop1);
    CustomInfoType.Item prop2 = new CustomInfoType.Item();
    prop2.setKey("mykey2");
    prop2.setValue("myValue2");
    ciType.getItem().add(prop2);
    eventType.setCustomInfo(ciType);
    MessageInfoType mit = new MessageInfoType();
    mit.setFlowId("uuid");
    eventType.setMessageInfo(mit);
    events.add(eventType);
    String result = monitoringService.putEvents(events);
    Assert.assertEquals("success", result);
    long id = jdbcTemplate.queryForObject("select id from EVENTS", Long.class);
    Event readEvent = eventRepository.readEvent(id);
    Assert.assertEquals(EventTypeEnum.REQ_OUT, readEvent.getEventType());
    Map<String, String> customInfo = readEvent.getCustomInfo();
    Assert.assertEquals("myValue1", customInfo.get("mykey1"));
    Assert.assertEquals("myValue2", customInfo.get("mykey2"));
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) CustomInfoType(org.talend.esb.sam._2011._03.common.CustomInfoType) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Event(org.talend.esb.sam.common.event.Event) Client(org.apache.cxf.endpoint.Client) MessageInfoType(org.talend.esb.sam._2011._03.common.MessageInfoType) Test(org.junit.Test)

Example 47 with HTTPConduit

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

the class NetSuiteClientService method setHttpClientPolicy.

protected void setHttpClientPolicy(PortT port, HTTPClientPolicy httpClientPolicy) {
    Client proxy = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    conduit.setClient(httpClientPolicy);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Client(org.apache.cxf.endpoint.Client)

Example 48 with HTTPConduit

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

the class AmbariClientBuilder method build.

/**
 * Build a client proxy, for a specific proxy type.
 *
 * @param proxyType proxy type class
 * @return client proxy stub
 */
protected <T> T build(Class<T> proxyType) {
    String address = generateAddress();
    T rootResource;
    // We want to ensure that the shared bean isn't set concurrently in multiple callers
    synchronized (AmbariClientBuilder.class) {
        JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
        bean.setAddress(address);
        if (username != null) {
            bean.setUsername(username);
            bean.setPassword(password);
        }
        if (enableLogging) {
            bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
        }
        rootResource = bean.create(proxyType);
    }
    boolean isTlsEnabled = address.startsWith("https://");
    ClientConfiguration config = WebClient.getConfig(rootResource);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    if (isTlsEnabled) {
        TLSClientParameters tlsParams = new TLSClientParameters();
        if (!validateCerts) {
            tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
        } else if (trustManagers != null) {
            tlsParams.setTrustManagers(trustManagers);
        }
        tlsParams.setDisableCNCheck(!validateCn);
        conduit.setTlsClientParameters(tlsParams);
    }
    HTTPClientPolicy policy = conduit.getClient();
    policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
    policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
    return rootResource;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) LoggingFeature(org.apache.cxf.feature.LoggingFeature) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 49 with HTTPConduit

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

the class AmbariClientBuilder method closeClient.

/**
 * Closes the transport level conduit in the client. Reopening a new connection, requires creating a new client
 * object using the build() method in this builder.
 *
 * @param root The resource returned by the build() method of this builder class
 */
public static void closeClient(ApiRootResource root) {
    ClientConfiguration config = WebClient.getConfig(root);
    HTTPConduit conduit = config.getHttpConduit();
    if (conduit == null) {
        throw new IllegalArgumentException("Client is not using the HTTP transport");
    }
    conduit.close();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 50 with HTTPConduit

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

the class WebServiceCommand method applyAuthorization.

protected void applyAuthorization(String userName, String password, Client client) {
    if (userName != null && password != null) {
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
        authorizationPolicy.setUserName(userName);
        authorizationPolicy.setPassword(password);
        authorizationPolicy.setAuthorizationType("Basic");
        httpConduit.setAuthorization(authorizationPolicy);
    } else {
        logger.warn("UserName and Password must be provided to set the authorization policy.");
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy)

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