Java Code Examples for org.apache.cxf.transport.http.HTTPConduit#getClient()

The following examples show how to use org.apache.cxf.transport.http.HTTPConduit#getClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpConduitConfigurationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void verifyConduit(HTTPConduit conduit) {
    AuthorizationPolicy authp = conduit.getAuthorization();
    assertNotNull(authp);
    assertEquals("Betty", authp.getUserName());
    assertEquals("password", authp.getPassword());
    TLSClientParameters tlscps = conduit.getTlsClientParameters();
    assertNotNull(tlscps);
    assertTrue(tlscps.isDisableCNCheck());
    assertEquals(3600000, tlscps.getSslCacheTimeout());

    KeyManager[] kms = tlscps.getKeyManagers();
    assertTrue(kms != null && kms.length == 1);
    assertTrue(kms[0] instanceof X509KeyManager);

    TrustManager[] tms = tlscps.getTrustManagers();
    assertTrue(tms != null && tms.length == 1);
    assertTrue(tms[0] instanceof X509TrustManager);

    FiltersType csfs = tlscps.getCipherSuitesFilter();
    assertNotNull(csfs);
    assertEquals(1, csfs.getInclude().size());
    assertEquals(1, csfs.getExclude().size());
    HTTPClientPolicy clientPolicy = conduit.getClient();
    assertEquals(10240, clientPolicy.getChunkLength());
}
 
Example 2
Source File: OnvifDevice.java    From onvif with Apache License 2.0 5 votes vote down vote up
public JaxWsProxyFactoryBean getServiceProxy(BindingProvider servicePort, String serviceAddr) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.getHandlers();

    if (serviceAddr != null) proxyFactory.setAddress(serviceAddr);
    proxyFactory.setServiceClass(servicePort.getClass());

    SoapBindingConfiguration config = new SoapBindingConfiguration();

    config.setVersion(Soap12.getInstance());
    proxyFactory.setBindingConfig(config);
    Client deviceClient = ClientProxy.getClient(servicePort);

    if (verbose) {
      // these logging interceptors are depreciated, but should be fine for debugging/development
      // use.
      proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
      proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    }

    HTTPConduit http = (HTTPConduit) deviceClient.getConduit();
    if (securityHandler != null) proxyFactory.getHandlers().add(securityHandler);
    HTTPClientPolicy httpClientPolicy = http.getClient();
    httpClientPolicy.setConnectionTimeout(36000);
    httpClientPolicy.setReceiveTimeout(32000);
    httpClientPolicy.setAllowChunking(false);

    return proxyFactory;
  }
 
Example 3
Source File: AmbariClientBuilder.java    From components with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    // Synchronized on the class to correlate with the scope of clientStaticResources
    // 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;
}
 
Example 4
Source File: ConnectionHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
    if (force || "HP-UX".equals(System.getProperty("os.name"))
        || "Windows XP".equals(System.getProperty("os.name"))) {
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit hc = (HTTPConduit)client.getConduit();
        HTTPClientPolicy cp = hc.getClient();
        cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
    }
}
 
Example 5
Source File: ProtocolVariationsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initDecoupledEndpoint(Client c) {
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledCount++) + "/decoupled_endpoint";

    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
 
Example 6
Source File: SequenceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initDecoupledEndpoint(Client c) {
    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledCount++) + "/decoupled_endpoint";

    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
 
Example 7
Source File: ConnectionHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
    if (force || "HP-UX".equals(System.getProperty("os.name"))
        || "Windows XP".equals(System.getProperty("os.name"))) {
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit hc = (HTTPConduit)client.getConduit();
        HTTPClientPolicy cp = hc.getClient();
        cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
    }
}
 
Example 8
Source File: HTTPSConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void verifyBethalClient(Greeter bethal) {
    Client client = ClientProxy.getClient(bethal);

    HTTPConduit http =
        (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = http.getClient();
    assertTrue("the httpClientPolicy's autoRedirect should be 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);
}
 
Example 9
Source File: InterceptorFaultTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint)
    throws NumberFormatException, MalformedURLException {

    SpringBusFactory bf = new SpringBusFactory();

    controlBus = bf.createBus();
    BusFactory.setDefaultBus(controlBus);

    ControlService cs = new ControlService();
    control = cs.getControlPort();
    updateAddressPort(control, PORT);

    assertTrue("Failed to start greeter", control.startGreeter(cfgResource));

    greeterBus = bf.createBus(cfgResource);
    BusFactory.setDefaultBus(greeterBus);
    LOG.fine("Initialised greeter bus with configuration: " + cfgResource);

    if (null == comparator) {
        comparator = new PhaseComparator();
    }
    if (null == inPhases) {
        inPhases = new ArrayList<>();
        inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases());
        Collections.sort(inPhases, comparator);
    }
    if (null == postUnMarshalPhase) {
        postUnMarshalPhase = getPhase(Phase.POST_UNMARSHAL);
    }

    GreeterService gs = new GreeterService();

    greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");

    if (!useDecoupledEndpoint) {
        return;
    }

    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpointPort++;
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledEndpointPort)
        + "/decoupled_endpoint";

    Client c = ClientProxy.getClient(greeter);
    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
 
Example 10
Source File: AbstractServerPersistenceTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecovery() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    LOG.fine("Created bus " + bus + " with default cfg");
    ControlService cs = new ControlService();
    Control control = cs.getControlPort();
    ConnectionHelper.setKeepAliveConnection(control, false, true);
    updateAddressPort(control, getPort());

    assertTrue("Failed to start greeter", control.startGreeter(SERVER_LOSS_CFG));
    LOG.fine("Started greeter server.");

    System.setProperty("db.name", getPrefix() + "-recovery");
    greeterBus = new SpringBusFactory().createBus(CFG);
    System.clearProperty("db.name");
    LOG.fine("Created bus " + greeterBus + " with cfg : " + CFG);
    BusFactory.setDefaultBus(greeterBus);

    // avoid early client resends
    greeterBus.getExtension(RMManager.class).getConfiguration()
        .setBaseRetransmissionInterval(Long.valueOf(60000));
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, getPort());

    LOG.fine("Created greeter client.");

    ConnectionHelper.setKeepAliveConnection(greeter, false, true);

    Client c = ClientProxy.getClient(greeter);
    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint("http://localhost:" + getDecoupledPort() + "/decoupled_endpoint");

    out = new OutMessageRecorder();
    in = new InMessageRecorder();

    greeterBus.getOutInterceptors().add(out);
    greeterBus.getInInterceptors().add(in);

    LOG.fine("Configured greeter client.");

    Response<GreetMeResponse>[] responses = cast(new Response[4]);

    responses[0] = greeter.greetMeAsync("one");
    responses[1] = greeter.greetMeAsync("two");
    responses[2] = greeter.greetMeAsync("three");

    verifyMissingResponse(responses);
    control.stopGreeter(SERVER_LOSS_CFG);
    LOG.fine("Stopped greeter server");

    out.getOutboundMessages().clear();
    in.getInboundMessages().clear();

    control.startGreeter(CFG);
    String nl = System.getProperty("line.separator");
    LOG.fine("Restarted greeter server" + nl + nl);

    verifyServerRecovery(responses);
    responses[3] = greeter.greetMeAsync("four");

    verifyRetransmissionQueue();
    verifyAcknowledgementRange(1, 4);

    out.getOutboundMessages().clear();
    in.getInboundMessages().clear();

    greeterBus.shutdown(true);

    control.stopGreeter(CFG);
    bus.shutdown(true);
}
 
Example 11
Source File: JAXWSEnvironment.java    From dropwizard-jaxws with Apache License 2.0 4 votes vote down vote up
/**
 * JAX-WS client factory
 * @param clientBuilder ClientBuilder.
 * @param <T> Service interface type.
 * @return JAX-WS client proxy.
 */
public <T> T getClient(ClientBuilder<T> clientBuilder) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setServiceClass(clientBuilder.getServiceClass());
    proxyFactory.setAddress(clientBuilder.getAddress());

    // JAX-WS handlers
    if (clientBuilder.getHandlers() != null) {
        for (Handler h : clientBuilder.getHandlers()) {
            proxyFactory.getHandlers().add(h);
        }
    }

    // ClientProxyFactoryBean bindingId
    if (clientBuilder.getBindingId() != null) {
        proxyFactory.setBindingId(clientBuilder.getBindingId());
    }

    // CXF interceptors
    if (clientBuilder.getCxfInInterceptors() != null) {
        proxyFactory.getInInterceptors().addAll(clientBuilder.getCxfInInterceptors());
    }
    if (clientBuilder.getCxfInFaultInterceptors() != null) {
        proxyFactory.getInFaultInterceptors().addAll(clientBuilder.getCxfInFaultInterceptors());
    }
    if (clientBuilder.getCxfOutInterceptors() != null) {
        proxyFactory.getOutInterceptors().addAll(clientBuilder.getCxfOutInterceptors());
    }
    if (clientBuilder.getCxfOutFaultInterceptors() != null) {
        proxyFactory.getOutFaultInterceptors().addAll(clientBuilder.getCxfOutFaultInterceptors());
    }

    T proxy = clientBuilder.getServiceClass().cast(proxyFactory.create());

    // MTOM support
    if (clientBuilder.isMtomEnabled()) {
        BindingProvider bp = (BindingProvider)proxy;
        SOAPBinding binding = (SOAPBinding)bp.getBinding();
        binding.setMTOMEnabled(true);
    }

    HTTPConduit http = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
    HTTPClientPolicy client = http.getClient();
    client.setConnectionTimeout(clientBuilder.getConnectTimeout());
    client.setReceiveTimeout(clientBuilder.getReceiveTimeout());

    return proxy;
}