當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequestHandler類代碼示例

本文整理匯總了Java中org.apache.http.protocol.HttpRequestHandler的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequestHandler類的具體用法?Java HttpRequestHandler怎麽用?Java HttpRequestHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpRequestHandler類屬於org.apache.http.protocol包,在下文中一共展示了HttpRequestHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
/**
 * Starts the HTTP server.
 *
 * @return the listening port.
 */
static int start () throws IOException
{

   server = ServerBootstrap.bootstrap ().registerHandler ("*",
         new HttpRequestHandler ()
         {

            @Override
            public void handle (HttpRequest request, HttpResponse response,
                  HttpContext context)
                  throws HttpException, IOException
            {

               response.setStatusCode (HttpStatus.SC_OK);
               response.setEntity (new StringEntity ("0123456789"));
            }
         })
         .create ();
   server.start ();

   return server.getLocalPort ();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:28,代碼來源:TestInterruptibleHttpClient.java

示例2: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Before
@Override
public void setUp() throws Exception {
    localServer = ServerBootstrap.bootstrap().
            setHttpProcessor(getBasicHttpProcessor()).
            setConnectionReuseStrategy(getConnectionReuseStrategy()).
            setResponseFactory(getHttpResponseFactory()).
            setExpectationVerifier(getHttpExpectationVerifier()).
            setSslContext(getSSLContext()).
            registerHandler("/content", new HttpRequestHandler() {
                @Override
                public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
                    String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
                    
                    assertEquals(CONTENT_TYPE, contentType);

                    response.setEntity(new StringEntity(contentType, "ASCII"));
                    response.setStatusCode(HttpStatus.SC_OK);
                }
            }).create();
    localServer.start();

    super.setUp();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:25,代碼來源:HttpProducerContentTypeTest.java

示例3: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Before
@Override
public void setUp() throws Exception {
    localServer = ServerBootstrap.bootstrap().
            setHttpProcessor(getBasicHttpProcessor()).
            setConnectionReuseStrategy(getConnectionReuseStrategy()).
            setResponseFactory(getHttpResponseFactory()).
            setExpectationVerifier(getHttpExpectationVerifier()).
            setSslContext(getSSLContext()).
            registerHandler("/", new HttpRequestHandler() {
                public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        // ignore
                    }
                    response.setStatusCode(HttpStatus.SC_OK);
                    response.setEntity(new StringEntity("" + counter.incrementAndGet()));
                }
            }).create();
    localServer.start();

    super.setUp();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:25,代碼來源:HttpConcurrentTest.java

示例4: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Before
@Override
public void setUp() throws Exception {
    localServer = ServerBootstrap.bootstrap().
            setHttpProcessor(getBasicHttpProcessor()).
            setConnectionReuseStrategy(getConnectionReuseStrategy()).
            setResponseFactory(getHttpResponseFactory()).
            setExpectationVerifier(getHttpExpectationVerifier()).
            setSslContext(getSSLContext()).
            registerHandler("/myapp", new HttpRequestHandler() {
                @Override
                public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
                    String uri = request.getRequestLine().getUri();
                    assertEquals("/myapp?from=me&to=foo&to=bar", uri);

                    response.setHeader("bar", "yes");
                    response.addHeader("foo", "123");
                    response.addHeader("foo", "456");
                    response.setEntity(new StringEntity("OK", "ASCII"));
                    response.setStatusCode(HttpStatus.SC_OK);
                }
            }).create();
    localServer.start();

    super.setUp();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:27,代碼來源:HttpProducerTwoParametersWithSameKeyTest.java

示例5: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Before @Override
public void setUp() throws Exception {
    super.setUp();
    this.serverBootstrap.registerHandler("/", new HttpRequestHandler() {

        @Override
        public void handle(
                final HttpRequest request,
                final HttpResponse response,
                final HttpContext context) throws HttpException, IOException {
            response.addHeader(AUTH.WWW_AUTH, AuthSchemes.SPNEGO);
            response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
        }

    });
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:17,代碼來源:TestWindowsNegotiateScheme.java

示例6: makeHttpHandler

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
public static HttpRequestHandler makeHttpHandler(final int statusCode, final String body,
                                                 final List<String> requestBodies) {
    return new HttpRequestHandler() {
        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            response.setStatusCode(statusCode);
            response.setEntity(new StringEntity(body));

            if (request instanceof HttpEntityEnclosingRequest) {
                HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
                requestBodies.add(EntityUtils.toString(entity));
            } else {
                requestBodies.add("");
            }
        }
    };
}
 
開發者ID:uber,項目名稱:phabricator-jenkins-plugin,代碼行數:18,代碼來源:TestUtils.java

示例7: LocalTestServer

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
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);
    }
}
 
開發者ID:yahoo,項目名稱:gondola,代碼行數:18,代碼來源:LocalTestServer.java

示例8: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    BasicConfigurator.configure();
    
    server = new LocalTestServer(null, null);

    server.register("/hitme/*", new HttpRequestHandler() {
        @Override
        public void handle(HttpRequest req, HttpResponse resp, HttpContext ctx)
                throws HttpException, IOException 
        {
            resp.setStatusCode(200);
            resp.setEntity(new StringEntity("Hello World"));
        }
    });
    
    server.start();
    
    client = new HttpClient();
}
 
開發者ID:memphis-iis,項目名稱:gluten,代碼行數:21,代碼來源:HttpClientTest.java

示例9: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Override
@Before
public void setUp() throws Exception {
    OAuthTokenService.INSTANCE.clearToken();

    HttpRequestHandler tokenHandler = new TokenHandler();
    HttpRequestHandler resourceHandler = new ResourceHandler();

    testServer = new LocalTestServer(null, null);
    testServer.register("/v3/rest/*", resourceHandler);
    testServer.register("/v3/token", tokenHandler);
    testServer.start();

    port = testServer.getServicePort();
    host = testServer.getServiceHostName();

    // System.out.println("LocalTestServer available via http://" + host + ":" + port);

    params = new HashMap<String, String>();
    params.put("username", userName);
    params.put("password", password);
    params.put("scope", scope);
    params.put("grant_type", grantType);

    client = MasheryClientBuilder.masheryClient().withHost(host).withProtocol("http").withPort(port).withApiKey(apiKey).withApiSecret(apiSecret).withTokenRequestParams(params).build();
}
 
開發者ID:afklm,項目名稱:mashery-sdk,代碼行數:27,代碼來源:MasheryClientTest.java

示例10: setUp

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Before
public void setUp() throws Exception {

    handler = mock(HttpRequestHandler.class);

    server = new LocalTestServer(null, null);
    server.register("/*", handler);
    server.start();

    // report how to access the server
    System.out.println("LocalTestServer available at " + server.getServiceAddress());
    primaryServiceAddress = server.getServiceAddress().getHostName() + ":" + server.getServiceAddress().getPort();
    secondaryServiceAddress = server.getServiceAddress().getAddress().getHostAddress() + ":" + server.getServiceAddress().getPort();

    impl = new Sosumi("http://" + primaryServiceAddress, "user", "pass");

}
 
開發者ID:tomasca,項目名稱:sosumi-java,代碼行數:18,代碼來源:SosumiTest.java

示例11: register

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
public void register(String pattern, final HttpRequestHandler handler) {
	if (server != null) {
		throw new RuntimeException("Cannot register hander when server is running");
	}
	serverBootstrap.registerHandler(pattern, new HttpRequestHandler() {

		@Override
		public void handle(HttpRequest request, HttpResponse response, HttpContext context)
			throws HttpException, IOException {
			// wrap the original handler to track the request
			String uri = request.getRequestLine().getUri();
			requestUris.add(uri.contains("?") ? uri.substring(0, uri.indexOf("?")) : uri);
			// never cache during tests
			response.addHeader("Cache-Control", "no-cache");
			handler.handle(request, response, context);
		}
	});
}
 
開發者ID:BellaDati,項目名稱:belladati-sdk-java,代碼行數:19,代碼來源:RequestTrackingServer.java

示例12: registerHandlers

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Override
protected void registerHandlers() throws IOException {
    serverBootstrap.registerHandler(GET_WAIT_PATH + ".json", new HttpRequestHandler() {
        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            callCount++;
            if (callCount == waitCount) {
                response.setEntity(new StringEntity(OK_RESPONSE));
            } else {
                response.setEntity(new StringEntity(NOK_RESPONSE));
                response.setStatusCode(404);
            }
        }
    });
}
 
開發者ID:apache,項目名稱:sling-org-apache-sling-testing-clients,代碼行數:16,代碼來源:SlingClientWaitExistsTest.java

示例13: testSuccess

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Test
public void testSuccess() {
	StringBuilder expectedStr = new StringBuilder();
	Map<String, TLE> expected;
	try (BufferedReader r = new BufferedReader(new InputStreamReader(CelestrakClientTest.class.getClassLoader().getResourceAsStream("sample-tle.txt")))) {
		String curLine = null;
		List<String> lines = new ArrayList<>();
		while( (curLine = r.readLine()) != null ) {
			lines.add(curLine);
			expectedStr.append(curLine).append("\n");
		}
		expected = convert(lines);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	
	server.register("/*", new HttpRequestHandler() {

		@Override
		public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
			response.setEntity(new StringEntity(expectedStr.toString(), StandardCharsets.UTF_8));
		}
	});
	// one slash is important here
	CelestrakClient client = new CelestrakClient("http:/" + server.getServiceAddress());
	Map<String, TLE> actual = client.getWeatherTLE();
	assertEquals(expected.size(), actual.size());
	assertTrue(expected.equals(actual));
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:30,代碼來源:CelestrakClientTest.java

示例14: test

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
@Test
public void test() throws ExecutionException, InterruptedException {


    HttpHost target = new HttpHost("localhost");
    BasicConnPool connpool = new BasicConnPool();
    connpool.setMaxTotal(200);
    connpool.setDefaultMaxPerRoute(10);
    connpool.setMaxPerRoute(target, 20);
    Future<BasicPoolEntry> future = connpool.lease(target, null);
    BasicPoolEntry poolEntry = future.get();
    HttpClientConnection conn = poolEntry.getConnection();

    HttpProcessor httpproc = HttpProcessorBuilder.create()
            .add(new ResponseDate())
            .add(new ResponseServer("MyServer-HTTP/1.1"))
            .add(new ResponseContent())
            .add(new ResponseConnControl())
            .build();

    HttpRequestHandler myRequestHandler = new HttpRequestHandler() {

        public void handle(
                HttpRequest request,
                HttpResponse response,
                HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            response.setEntity(
                    new StringEntity("some important message",
                            ContentType.TEXT_PLAIN));
        }

    };

    UriHttpRequestHandlerMapper handlerMapper = new UriHttpRequestHandlerMapper();
    handlerMapper.register("/service/*", myRequestHandler);
    HttpService httpService = new HttpService(httpproc, handlerMapper);
}
 
開發者ID:daishicheng,項目名稱:outcomes,代碼行數:39,代碼來源:TestHttpCore.java

示例15: ListenerThread

import org.apache.http.protocol.HttpRequestHandler; //導入依賴的package包/類
public ListenerThread(final HttpRequestHandler requestHandler, final int port) {
    _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));

    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing cluster service servlet container", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
           .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
           .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
           .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
           .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("/clusterservice", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:34,代碼來源:ClusterServiceServletContainer.java


注:本文中的org.apache.http.protocol.HttpRequestHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。