Search in sources :

Example 1 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project midpoint by Evolveum.

the class Action method createModelPort.

protected ModelPortType createModelPort() {
    ModelService modelService = new ModelService();
    ModelPortType port = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) port;
    Client client = ClientProxy.getClient(port);
    Endpoint endpoint = client.getEndpoint();
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = http.getClient();
    if (httpClientPolicy == null) {
        httpClientPolicy = new HTTPClientPolicy();
        http.setClient(httpClientPolicy);
    }
    httpClientPolicy.setConnectionTimeout(10000);
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, params.getUrl().toString());
    requestContext.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    requestContext.put(WSHandlerConstants.USER, params.getUsername());
    requestContext.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    ClientPasswordHandler handler = new ClientPasswordHandler();
    handler.setPassword(params.getInsertedPassword());
    requestContext.put(WSHandlerConstants.PW_CALLBACK_REF, handler);
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(requestContext);
    endpoint.getOutInterceptors().add(wssOut);
    if (params.isVerbose()) {
        endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
        endpoint.getInInterceptors().add(new LoggingInInterceptor());
    }
    return port;
}
Also used : ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) BindingProvider(javax.xml.ws.BindingProvider) ModelService(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Endpoint(org.apache.cxf.endpoint.Endpoint) ClientPasswordHandler(com.evolveum.midpoint.cli.ninja.util.ClientPasswordHandler) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client)

Example 2 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project midpoint by Evolveum.

the class AbstractTestForExchangeConnector method createModelPort.

public ModelPortType createModelPort(String[] args) {
    String endpointUrl = DEFAULT_ENDPOINT_URL;
    if (args.length > 0) {
        endpointUrl = args[0];
    }
    System.out.println("Endpoint URL: " + endpointUrl);
    // uncomment this if you want to use Fiddler or any other proxy
    //        ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));
    ModelService modelService = new ModelService();
    ModelPortType modelPort = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) modelPort;
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setReceiveTimeout(300000L);
    http.setClient(httpClientPolicy);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.USER, ADM_USERNAME);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);
    return modelPort;
}
Also used : HashMap(java.util.HashMap) ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) BindingProvider(javax.xml.ws.BindingProvider) ModelService(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 3 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project camel by apache.

the class ServiceNowClient method configureHttpClientPolicy.

private static void configureHttpClientPolicy(CamelContext context, ServiceNowConfiguration configuration, WebClient client) throws Exception {
    HTTPClientPolicy httpPolicy = configuration.getHttpClientPolicy();
    if (httpPolicy == null) {
        String host = configuration.getProxyHost();
        Integer port = configuration.getProxyPort();
        if (host != null && port != null) {
            httpPolicy = new HTTPClientPolicy();
            httpPolicy.setProxyServer(host);
            httpPolicy.setProxyServerPort(port);
        }
    }
    if (httpPolicy != null) {
        WebClient.getConfig(client).getHttpConduit().setClient(httpPolicy);
    }
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Example 4 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy 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 5 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class HTTPSConduitTest method verifyBethalClient.

// we just verify the configurations are loaded successfully
private void verifyBethalClient(Greeter bethal) {
    Client client = ClientProxy.getClient(bethal);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = http.getClient();
    assertEquals("the httpClientPolicy's autoRedirect should be true", true, httpClientPolicy.isAutoRedirect());
    TLSClientParameters tlsParameters = http.getTlsClientParameters();
    assertNotNull("the http conduit's tlsParameters should not be null", tlsParameters);
    // If we set any name, but Edward, Mary, or George,
    // and a password of "password" we will get through
    // Bethal.
    AuthorizationPolicy authPolicy = http.getAuthorization();
    assertEquals("Set the wrong user name from the configuration", "Betty", authPolicy.getUserName());
    assertEquals("Set the wrong pass word form the configuration", "password", authPolicy.getPassword());
    configureProxy(ClientProxy.getClient(bethal));
    String answer = bethal.sayHi();
    answer = bethal.sayHi();
    answer = bethal.sayHi();
    answer = bethal.sayHi();
    answer = bethal.sayHi();
    assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
    // With HTTPS, it will just be a CONNECT to the proxy and all the
    // data is encrypted.  Thus, the proxy cannot distinquish the requests
    assertProxyRequestCount(0);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

Aggregations

HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)68 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)47 Client (org.apache.cxf.endpoint.Client)29 Test (org.junit.Test)19 URL (java.net.URL)12 IOException (java.io.IOException)8 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)8 Bus (org.apache.cxf.Bus)7 ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)7 QName (javax.xml.namespace.QName)6 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)6 Greeter (org.apache.hello_world.Greeter)5 SOAPService (org.apache.hello_world.services.SOAPService)5 Map (java.util.Map)4 BindingProvider (javax.xml.ws.BindingProvider)4 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)4 TestService (com.creditease.monitorframework.fat.client.TestService)3 TestService_Service (com.creditease.monitorframework.fat.client.TestService_Service)3 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3