Package org.apache.wink.client

Examples of org.apache.wink.client.ClientConfig


    public void testReadTimeout() {
        server.setMockResponseCode(200);
        // set the server to delay the response by 5 seconds.
        server.setDelayResponse(5000);

        ClientConfig config = new ClientConfig();
        // set the read timeout to be 2 seconds
        config.readTimeout(2000);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        long before = System.currentTimeMillis();
        try {
            // the client should "read timeout" after 2 seconds
View Full Code Here


    }

    public void testApplication() {
        server.setMockResponseCode(200);
        server.setDelayResponse(0);
        ClientConfig conf = new ClientConfig();

        // Create new JAX-RS Application
        Application app = new Application() {
            @Override
            public Set<Class<?>> getClasses() {
                HashSet<Class<?>> set = new HashSet<Class<?>>();
                set.add(FooProvider.class);
                return set;
            }
        };

        conf.applications(app);

        RestClient client = new RestClient(conf);
        Resource resource = client.resource(serviceURL + "/testResourcePut");
        Foo response =
            resource.contentType("text/plain").accept("text/plain").post(Foo.class,
View Full Code Here

        }
        return null;
    }

    private RestClient createRestClient() {
        ClientConfig config = new ClientConfig();

        // configureBasicAuth(config, userName, password);

        config.applications(new Application() {

            @Override
            public Set<Class<?>> getClasses() {
                return Collections.emptySet();
            }
View Full Code Here

    @RunAsClient
    public void simpleClientToServerCall() throws URISyntaxException, MalformedURLException {
        Assert.assertNotNull(url);
        String resourcePath = TEST_SERVLET_PATH + TestController.PATH;

        RestClient restClient = new RestClient(new ClientConfig());

        URL resourceURL = new URL(url.toExternalForm() + resourcePath);
        Resource resource = restClient.resource(resourceURL.toURI());

        // invoke GET on the resource and check the result
View Full Code Here

        }
        return null;
    }

    private RestClient createRestClient(HttpClient httpClient) {
        ClientConfig config = new ApacheHttpClientConfig(httpClient);

        // configureBasicAuth(config, userName, password);

        config.applications(new Application() {

            @Override
            public Set<Class<?>> getClasses() {
                return Collections.emptySet();
            }

            @Override
            public Set<Object> getSingletons() {
                Set<Object> providers = new HashSet<Object>();
                providers.add(new DataBindingJAXRSReader(registry));
                providers.add(new DataBindingJAXRSWriter(registry));
                return providers;
            }

        });
       
        config.readTimeout(binding.getReadTimeout());
        RestClient client = new RestClient(config);
       
        // Default to GET for RPC
        httpMethod = HttpMethod.GET;
View Full Code Here

        if (asyncHttpClient != null) {
            return asyncHttpClient;
        }

        // cast is safe because we're on the client
        ClientConfig config = (ClientConfig) request.getAttribute(WinkConfiguration.class);

        AsyncHttpClientConfig.Builder c = new AsyncHttpClientConfig.Builder();
        c.setConnectionTimeoutInMs(config.getConnectTimeout());
        c.setRequestTimeoutInMs(config.getReadTimeout());
        c.setFollowRedirects(config.isFollowRedirects());

        // setup proxy
        if (config.getProxyHost() != null) {
            c.setProxyServer(new ProxyServer(config.getProxyHost(), config.getProxyPort()));
        }

        return new AsyncHttpClient(c.build());
    }
View Full Code Here

        if (this.httpclient != null) {
            return this.httpclient;
        }

        // cast is safe because we're on the client
        ClientConfig config = (ClientConfig)request.getAttribute(WinkConfiguration.class);
        BasicHttpParams params = new BasicHttpParams();
        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.valueOf(config
            .getConnectTimeout()));
        params.setParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.valueOf(config
            .getReadTimeout()));
        params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.valueOf(config
            .isFollowRedirects()));
        if (config.isFollowRedirects()) {
            params.setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
        }
        // setup proxy
        if (config.getProxyHost() != null) {
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(),
                                                                            config.getProxyPort()));
        }

        HttpClient httpclient = new DefaultHttpClient(params);

        if (config.getBypassHostnameVerification()) {
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);

            SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
            sf.setHostnameVerifier(new X509HostnameVerifier() {
View Full Code Here

    private HttpURLConnection openConnection(ClientRequest request) throws IOException {
        URL url = request.getURI().toURL();
        HttpURLConnection connection = null;
        // we're on the client so this is a safe cast
        ClientConfig config = (ClientConfig)request.getAttribute(WinkConfiguration.class);

        // setup proxy
        if (config.getProxyHost() != null) {
            Proxy proxy =
                new Proxy(Proxy.Type.HTTP, new InetSocketAddress(config.getProxyHost(), config
                    .getProxyPort()));
            connection = (HttpURLConnection)url.openConnection(proxy);
        } else {
            connection = (HttpURLConnection)url.openConnection();
        }
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod(request.getMethod());

        connection.setConnectTimeout(config.getConnectTimeout());
        connection.setReadTimeout(config.getReadTimeout());
        connection.setInstanceFollowRedirects(config.isFollowRedirects());

        return connection;
    }
View Full Code Here

            BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/jaxbresource";
        }
    }

    public void setUp() throws Exception {
        ClientConfig config = new ClientConfig();
        client = new RestClient(config);
    }
View Full Code Here

    public RestClient getDefaultClient() {
        return new RestClient();
    }

    public RestClient getReadTimeoutClient() {
        ClientConfig config = new ClientConfig();
        config.readTimeout(20000);
        return new RestClient(config);
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.client.ClientConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.