Package org.apache.wink.client

Examples of org.apache.wink.client.ClientConfig


     * BASIC AUTH
     */
   
    public void testNoBasicAuthHandler() throws Exception {
        server.getMockHttpServerResponses().get(0).setMockResponseCode(401);
        RestClient client = new RestClient(new ClientConfig());
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(401, response.getStatusCode())// should have challenged us due to lack of credentials
    }
View Full Code Here


    }
   
    public void testBasicAuthHandlerNoAuthRequired() throws Exception {
        // try with BasicAuthSecurityHandler, but return 200 from server for first response; BasicAuthSecurityHandler should allow flow through
        server.getMockHttpServerResponses().get(0).setMockResponseCode(200);
        ClientConfig config = new ClientConfig();
        BasicAuthSecurityHandler basicAuthSecurityHandler = new BasicAuthSecurityHandler();
        basicAuthSecurityHandler.setUserName("username");
        basicAuthSecurityHandler.setPassword("password");
        config.handlers(basicAuthSecurityHandler);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(200, response.getStatusCode());
    }
View Full Code Here

        MockHttpServer.MockHttpServerResponse response1 = new MockHttpServer.MockHttpServerResponse();
        response1.setMockResponseCode(401);
        MockHttpServer.MockHttpServerResponse response2 = new MockHttpServer.MockHttpServerResponse();
        response2.setMockResponseCode(401);
        server.setMockHttpServerResponses(response1, response2);
        ClientConfig config = new ClientConfig();
        BasicAuthSecurityHandler basicAuthSecurityHandler = new BasicAuthSecurityHandler();
        basicAuthSecurityHandler.setUserName("username");
        basicAuthSecurityHandler.setPassword("password");
        config.handlers(basicAuthSecurityHandler);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        try {
            @SuppressWarnings("unused")
            ClientResponse response = resource.get();
View Full Code Here

        MockHttpServer.MockHttpServerResponse response1 = new MockHttpServer.MockHttpServerResponse();
        response1.setMockResponseCode(401);
        MockHttpServer.MockHttpServerResponse response2 = new MockHttpServer.MockHttpServerResponse();
        response2.setMockResponseCode(200);
        server.setMockHttpServerResponses(response1, response2);
        ClientConfig config = new ClientConfig();
        BasicAuthSecurityHandler basicAuthSecurityHandler = new BasicAuthSecurityHandler();
        basicAuthSecurityHandler.setUserName("username");
        basicAuthSecurityHandler.setPassword("password");
        config.handlers(basicAuthSecurityHandler);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(200, response.getStatusCode());
    }
View Full Code Here

     * PROXY AUTH
     */
   
    public void testNoProxyAuthHandler() throws Exception {
        server.getMockHttpServerResponses().get(0).setMockResponseCode(407);
        RestClient client = new RestClient(new ClientConfig());
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(407, response.getStatusCode())// should have challenged us due to lack of credentials
    }
View Full Code Here

    }
   
    public void testProxyAuthHandlerNoAuthRequired() throws Exception {
        // try with ProxyAuthSecurityHandler, but return 200 from server for first response; ProxyAuthSecurityHandler should allow flow through
        server.getMockHttpServerResponses().get(0).setMockResponseCode(200);
        ClientConfig config = new ClientConfig();
        ProxyAuthSecurityHandler proxyAuthSecurityHandler = new ProxyAuthSecurityHandler();
        proxyAuthSecurityHandler.setUserName("username");
        proxyAuthSecurityHandler.setPassword("password");
        config.handlers(proxyAuthSecurityHandler);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(200, response.getStatusCode());
    }
View Full Code Here

        MockHttpServer.MockHttpServerResponse response1 = new MockHttpServer.MockHttpServerResponse();
        response1.setMockResponseCode(407);
        MockHttpServer.MockHttpServerResponse response2 = new MockHttpServer.MockHttpServerResponse();
        response2.setMockResponseCode(407);
        server.setMockHttpServerResponses(response1, response2);
        ClientConfig config = new ClientConfig();
        ProxyAuthSecurityHandler proxyAuthSecurityHandler = new ProxyAuthSecurityHandler();
        proxyAuthSecurityHandler.setUserName("username");
        proxyAuthSecurityHandler.setPassword("password");
        config.handlers(proxyAuthSecurityHandler);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        try {
            @SuppressWarnings("unused")
            ClientResponse response = resource.get();
View Full Code Here

        MockHttpServer.MockHttpServerResponse response1 = new MockHttpServer.MockHttpServerResponse();
        response1.setMockResponseCode(407);
        MockHttpServer.MockHttpServerResponse response2 = new MockHttpServer.MockHttpServerResponse();
        response2.setMockResponseCode(200);
        server.setMockHttpServerResponses(response1, response2);
        ClientConfig config = new ClientConfig();
        ProxyAuthSecurityHandler proxyAuthSecurityHandler = new ProxyAuthSecurityHandler();
        proxyAuthSecurityHandler.setUserName("username");
        proxyAuthSecurityHandler.setPassword("password");
        config.handlers(proxyAuthSecurityHandler);
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(200, response.getStatusCode());
    }
View Full Code Here

        MockHttpServer.MockHttpServerResponse response2 = new MockHttpServer.MockHttpServerResponse();
        response2.setMockResponseCode(401);
        MockHttpServer.MockHttpServerResponse response3 = new MockHttpServer.MockHttpServerResponse();
        response3.setMockResponseCode(200);
        server.setMockHttpServerResponses(response1, response2, response3);
        ClientConfig config = new ClientConfig();
        BasicAuthSecurityHandler basicAuthSecurityHandler = new BasicAuthSecurityHandler();
        basicAuthSecurityHandler.setUserName("basicuser");
        basicAuthSecurityHandler.setPassword("basicpassword");
        ProxyAuthSecurityHandler proxyAuthSecurityHandler = new ProxyAuthSecurityHandler();
        proxyAuthSecurityHandler.setUserName("username");
        proxyAuthSecurityHandler.setPassword("password");
        config.handlers(proxyAuthSecurityHandler, basicAuthSecurityHandler)// proxy first, then basic, of course
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(200, response.getStatusCode());
    }
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);
        return httpclient;
    }
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.