当前位置: 首页>>代码示例>>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;未经允许,请勿转载。