⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpservercomponent.java

📁 编写rest实例 rest分布式框架在app中的应用
💻 JAVA
字号:
package com.jeffhanson.rest.server.http;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import com.jeffhanson.rest.server.Context;
import com.jeffhanson.rest.server.ContextNotFoundException;
import com.jeffhanson.rest.server.ServerComponent;

public class HTTPServerComponent extends ServerComponent
{
  public static String ContextPathFromRequest(HttpServletRequest request,
                                              HttpServlet servlet)
  {
    return request.getContextPath() + "/" + servlet.getServletName();
  }
  
  private int port = 80;

  public HTTPServerComponent(int port)
  {
    this.port = port;
  }
  
  public Context addContext(String contextRootPath, String contextPath)
  {
    Context context = getContexts().get(contextPath);
    if (context == null)
    {
      context = new HTTPContext(contextRootPath, contextPath);
      getContexts().put(contextPath, context);
    }
    
    return context;
  }
  
  public HTTPContext getContext(HttpServletRequest httpReq, HttpServlet servlet)
    throws ContextNotFoundException
  {
    String contextPath = ContextPathFromRequest(httpReq, servlet);
    HTTPContext context = (HTTPContext)getContexts().get(contextPath);
    
    if (context == null)
    {
      throw new ContextNotFoundException(contextPath);
    }
    
    return context;
  }
  
  public int getPort()
  {
    return port;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -