public LocalTestServer(HttpRequestHandler handler) { try { setUp(); HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new ResponseDate()) .add(new ResponseServer(LocalServerTestBase.ORIGIN)) .add(new ResponseContent()) .add(new ResponseConnControl()) .add(new RequestBasicAuth()) .add(new ResponseBasicUnauthorized()).build(); this.serverBootstrap.setHttpProcessor(httpproc); this.serverBootstrap.registerHandler("*", handler); host = start(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override protected HttpProcessor getBasicHttpProcessor() { List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); requestInterceptors.add(new RequestDecompressingInterceptor()); List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); responseInterceptors.add(new ResponseCompressingInterceptor()); responseInterceptors.add(new ResponseBasicUnauthorized()); ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); return httpproc; }
@Override protected HttpProcessor getBasicHttpProcessor() { List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>(); requestInterceptors.add(new RequestBasicAuth()); List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>(); responseInterceptors.add(new ResponseContent()); responseInterceptors.add(new ResponseBasicUnauthorized()); ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); return httpproc; }
@Before @Override public void setUp() throws Exception { super.setUp(); final HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new ResponseDate()) .add(new ResponseServer(LocalServerTestBase.ORIGIN)) .add(new ResponseContent()) .add(new ResponseConnControl()) .add(new RequestBasicAuth()) .add(new ResponseBasicUnauthorized()).build(); this.serverBootstrap.setHttpProcessor(httpproc); }
@Test public void testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue() throws Exception { final HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new ResponseDate()) .add(new ResponseServer(LocalServerTestBase.ORIGIN)) .add(new ResponseContent()) .add(new ResponseConnControl()) .add(new RequestBasicAuth()) .add(new ResponseBasicUnauthorized()).build(); this.serverBootstrap.setHttpProcessor(httpproc) .setExpectationVerifier(new AuthExpectationVerifier()) .registerHandler("*", new AuthHandler()); final HttpHost target = start(); final RequestConfig config = RequestConfig.custom() .setExpectContinueEnabled(true) .build(); final HttpPut httpput = new HttpPut("/"); httpput.setConfig(config); httpput.setEntity(new InputStreamEntity( new ByteArrayInputStream( new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ), -1)); final HttpClientContext context = HttpClientContext.create(); final TestCredentialsProvider credsProvider = new TestCredentialsProvider( new UsernamePasswordCredentials("test", "test")); context.setCredentialsProvider(credsProvider); final HttpResponse response = this.httpclient.execute(target, httpput, context); final HttpEntity entity = response.getEntity(); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertNotNull(entity); }