当前位置: 首页>>代码示例>>Java>>正文


Java HostConfiguration.setLocalAddress方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HostConfiguration.setLocalAddress方法的典型用法代码示例。如果您正苦于以下问题:Java HostConfiguration.setLocalAddress方法的具体用法?Java HostConfiguration.setLocalAddress怎么用?Java HostConfiguration.setLocalAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.HostConfiguration的用法示例。


在下文中一共展示了HostConfiguration.setLocalAddress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: proxyLink

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * Download link and have it be the response.
 * @param req the http request
 * @param resp the http response
 * @param link the link to download
 * @param c the cookie to set if any
 * @throws IOException on any error.
 */
private static void proxyLink(HttpServletRequest req, 
    HttpServletResponse resp, URI link, Cookie c, String proxyHost)
    throws IOException {
  org.apache.commons.httpclient.URI uri = 
    new org.apache.commons.httpclient.URI(link.toString(), false);
  HttpClientParams params = new HttpClientParams();
  params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
  HttpClient client = new HttpClient(params);
  // Make sure we send the request from the proxy address in the config
  // since that is what the AM filter checks against. IP aliasing or
  // similar could cause issues otherwise.
  HostConfiguration config = new HostConfiguration();
  InetAddress localAddress = InetAddress.getByName(proxyHost);
  if (LOG.isDebugEnabled()) {
    LOG.debug("local InetAddress for proxy host: " + localAddress.toString());
  }
  config.setLocalAddress(localAddress);
  HttpMethod method = new GetMethod(uri.getEscapedURI());
  method.setRequestHeader("Connection","close");
  @SuppressWarnings("unchecked")
  Enumeration<String> names = req.getHeaderNames();
  while(names.hasMoreElements()) {
    String name = names.nextElement();
    if(passThroughHeaders.contains(name)) {
      String value = req.getHeader(name);
      LOG.debug("REQ HEADER: "+name+" : "+value);
      method.setRequestHeader(name, value);
    }
  }

  String user = req.getRemoteUser();
  if(user != null && !user.isEmpty()) {
    method.setRequestHeader("Cookie",PROXY_USER_COOKIE_NAME+"="+
        URLEncoder.encode(user, "ASCII"));
  }
  OutputStream out = resp.getOutputStream();
  try {
    resp.setStatus(client.executeMethod(config, method));
    for(Header header : method.getResponseHeaders()) {
      resp.setHeader(header.getName(), header.getValue());
    }
    if(c != null) {
      resp.addCookie(c);
    }
    InputStream in = method.getResponseBodyAsStream();
    if(in != null) {
      IOUtils.copyBytes(in, out, 4096, true);
    }
  } finally {
    method.releaseConnection();
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:62,代码来源:WebAppProxyServlet.java

示例2: proxyLink

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * Download link and have it be the response.
 * @param req the http request
 * @param resp the http response
 * @param link the link to download
 * @param c the cookie to set if any
 * @throws IOException on any error.
 */
private static void proxyLink(HttpServletRequest req, 
    HttpServletResponse resp, URI link, Cookie c, String proxyHost)
    throws IOException {
  org.apache.commons.httpclient.URI uri = 
    new org.apache.commons.httpclient.URI(link.toString(), false);
  HttpClientParams params = new HttpClientParams();
  params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
  HttpClient client = new HttpClient(params);
  // Make sure we send the request from the proxy address in the config
  // since that is what the AM filter checks against. IP aliasing or
  // similar could cause issues otherwise.
  HostConfiguration config = new HostConfiguration();
  InetAddress localAddress = InetAddress.getByName(proxyHost);
  if (LOG.isDebugEnabled()) {
    LOG.debug("local InetAddress for proxy host: " + localAddress.toString());
  }
  config.setLocalAddress(localAddress);
  HttpMethod method = new GetMethod(uri.getEscapedURI());

  @SuppressWarnings("unchecked")
  Enumeration<String> names = req.getHeaderNames();
  while(names.hasMoreElements()) {
    String name = names.nextElement();
    if(passThroughHeaders.contains(name)) {
      String value = req.getHeader(name);
      LOG.debug("REQ HEADER: "+name+" : "+value);
      method.setRequestHeader(name, value);
    }
  }

  String user = req.getRemoteUser();
  if(user != null && !user.isEmpty()) {
    method.setRequestHeader("Cookie",PROXY_USER_COOKIE_NAME+"="+
        URLEncoder.encode(user, "ASCII"));
  }
  OutputStream out = resp.getOutputStream();
  try {
    resp.setStatus(client.executeMethod(config, method));
    for(Header header : method.getResponseHeaders()) {
      resp.setHeader(header.getName(), header.getValue());
    }
    if(c != null) {
      resp.addCookie(c);
    }
    InputStream in = method.getResponseBodyAsStream();
    if(in != null) {
      IOUtils.copyBytes(in, out, 4096, true);
    }
  } finally {
    method.releaseConnection();
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:62,代码来源:WebAppProxyServlet.java

示例3: proxyLink

import org.apache.commons.httpclient.HostConfiguration; //导入方法依赖的package包/类
/**
 * Download link and have it be the response.
 * @param req the http request
 * @param resp the http response
 * @param link the link to download
 * @param c the cookie to set if any
 * @throws IOException on any error.
 */
private static void proxyLink(HttpServletRequest req, 
    HttpServletResponse resp, URI link, Cookie c, String proxyHost)
    throws IOException {
  org.apache.commons.httpclient.URI uri = 
    new org.apache.commons.httpclient.URI(link.toString(), false);
  HttpClientParams params = new HttpClientParams();
  params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
  HttpClient client = new HttpClient(params);
  // Make sure we send the request from the proxy address in the config
  // since that is what the AM filter checks against. IP aliasing or
  // similar could cause issues otherwise.
  HostConfiguration config = new HostConfiguration();
  InetAddress localAddress = InetAddress.getByName(proxyHost);
  if (LOG.isDebugEnabled()) {
    LOG.debug("local InetAddress for proxy host: " + localAddress.toString());
  }
  config.setLocalAddress(localAddress);
  HttpMethod method = new GetMethod(uri.getEscapedURI());
  @SuppressWarnings("unchecked")
  Enumeration<String> names = req.getHeaderNames();
  while(names.hasMoreElements()) {
    String name = names.nextElement();
    if(passThroughHeaders.contains(name)) {
      String value = req.getHeader(name);
      LOG.debug("REQ HEADER: "+name+" : "+value);
      method.setRequestHeader(name, value);
    }
  }

  String user = req.getRemoteUser();
  if(user != null && !user.isEmpty()) {
    method.setRequestHeader("Cookie",PROXY_USER_COOKIE_NAME+"="+
        URLEncoder.encode(user, "ASCII"));
  }
  OutputStream out = resp.getOutputStream();
  try {
    resp.setStatus(client.executeMethod(config, method));
    for(Header header : method.getResponseHeaders()) {
      resp.setHeader(header.getName(), header.getValue());
    }
    if(c != null) {
      resp.addCookie(c);
    }
    InputStream in = method.getResponseBodyAsStream();
    if(in != null) {
      IOUtils.copyBytes(in, out, 4096, true);
    }
  } finally {
    method.releaseConnection();
  }
}
 
开发者ID:chendave,项目名称:hadoop-TCP,代码行数:61,代码来源:WebAppProxyServlet.java


注:本文中的org.apache.commons.httpclient.HostConfiguration.setLocalAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。