2014-11-29 1 views
0

내가 HTTP 코어-4.3.3을 사용하여 역방향 프록시를 개발하고, 내가 예를 들어, URL을 다시 작성해야어떻게 재 작성 대상 URL 아파치 HTTP 코어-4.3.3

/srv001/curstomer/ID가/curstomer/ID로 재 작성해야합니다

내 개발이 예 https://hc.apache.org/httpcomponents-core-ga/httpcore/examples/org/apache/http/examples/ElementalReverseProxy.java

을 기반으로

이 내 프록시 처리기

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

    long start = System.currentTimeMillis(); 

    DefaultBHttpClientConnection outconn = (DefaultBHttpClientConnection) context.getAttribute(ProxyContext.HTTP_OUT_CONN); 

    context.setAttribute(HttpCoreContext.HTTP_CONNECTION, outconn); 
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target); 

    System.out.println(">> Request URI: " + request.getRequestLine().getUri()); 

    // Remove hop-by-hop headers 
    ... 

    this.httpexecutor.preProcess(request, this.httpproc, context); 
    final HttpResponse targetResponse = this.httpexecutor.execute(request, outconn, context); 
    this.httpexecutor.postProcess(response, this.httpproc, context); 

    // Remove hop-by-hop headers 
    ... 

    response.setStatusLine(targetResponse.getStatusLine()); 
    response.setHeaders(targetResponse.getAllHeaders()); 
    response.setEntity(targetResponse.getEntity()); 

    System.out.println("<< Response: " + response.getStatusLine()); 

    final boolean keepalive = this.connStrategy.keepAlive(response, context); 
    context.setAttribute(ProxyContext.HTTP_CONN_KEEPALIVE, new Boolean(keepalive)); 

    long end = System.currentTimeMillis(); 
    System.out.println("-- request took (msec): " + Long.toString(end - start)); 
} 

내가 해봤입니다 요청시 대상 URL을 다시 작성하지만이를 수행하는 설정 방법은 없습니다. 어떻게 대상 URL을 다시 쓸 수 있습니까?

답변

1

HttpRequest 및 HttpResponse 개체는 매우 저렴합니다. 되는 소위 홉 - 바이 - 홉 헤더 인 하나

  • 처리를 재 작성

    • URI : HttpCore 당신은 항상 수신 메시지의 사본을 만드는 대신 여러 가지 이유로 같은 객체를 전달해야와 프록시를 구현하는 경우 다른
    • 클라이언트가 HTTP/1.0을 지원하고 원점이 HTTP/1.1을 지원하거나 그 반대 인 경우 프로토콜 업그레이드/다운 그레이드.