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


Java ServletRequest.getServerPort方法代码示例

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


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

示例1: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * Rewrites the outgoing stream to make sure URLs and headers
 * are correct. The incoming request is first processed to 
 * identify what resource we want to proxy.
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain filterChain) throws IOException, ServletException {
    
    if (response.isCommitted()) {
        log.info("Not proxying, already committed.");
        return;
    } else if (!(request instanceof HttpServletRequest)) {
        log.info("Request is not HttpRequest, will only handle HttpRequests.");
        return;
    } else if (!(response instanceof HttpServletResponse)) {
        log.info("Request is not HttpResponse, will only handle HttpResponses.");
        return;
    } else {
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        
        Server server = serverChain.evaluate(httpRequest);
        if (server == null) {
            log.info("Could not find a rule for this request, will not do anything.");
            filterChain.doFilter(request, response);
        } else {
            httpRequest.setAttribute("proxyServer", server);
            
            String ownHostName = request.getServerName() + ":" + request.getServerPort();
            UrlRewritingResponseWrapper wrappedResponse;
            wrappedResponse = new UrlRewritingResponseWrapper(httpResponse, server, ownHostName, httpRequest.getContextPath(), serverChain);
            
            filterChain.doFilter(httpRequest, wrappedResponse);

            wrappedResponse.processStream();
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:41,代码来源:RewriteFilter.java


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