コード例 #1
0
ファイル: ZenoVCALServlet.java プロジェクト: tfgordon/zeno
 private void setNoCache(HttpServletRequest request, HttpServletResponse response) {
   if (request.getProtocol().compareTo("HTTP/1.0") == 0) {
     response.setHeader("Pragma", "no-cache");
   } else if (request.getProtocol().compareTo("HTTP/1.1") == 0) {
     response.setHeader("Cache-Control", "no-cache");
   }
   response.setDateHeader("Expires", 0);
 }
コード例 #2
0
ファイル: InMessage.java プロジェクト: kcomkar/EasySOA
  /**
   * Build a InMessage from an HttpServletrequest
   *
   * @param request The HttpservletRequest
   */
  public InMessage(HttpServletRequest request) {

    // TODO : Check this code : WSDL request are not well recorded !
    this.method = request.getMethod();
    // Set the headers
    this.headers = new Headers();
    Enumeration<String> headerNameEnum = request.getHeaderNames();
    while (headerNameEnum.hasMoreElements()) {
      String headerName = headerNameEnum.nextElement();
      this.headers.addHeader(new Header(headerName, request.getHeader(headerName)));
    }
    // Set protocol, server, port, path
    this.protocol = request.getProtocol().substring(0, request.getProtocol().indexOf('/'));
    this.protocolVersion = request.getProtocol().substring(request.getProtocol().indexOf('/') + 1);
    this.server = request.getServerName();
    this.port = request.getServerPort();
    this.path = request.getRequestURI();
    this.remoteHost = request.getRemoteHost();
    // this.completeUrl = request.getRequestURL().toString();
    // Set url parameters
    this.queryString = new QueryString();
    Enumeration<String> parametersNameEnum = request.getParameterNames();
    while (parametersNameEnum.hasMoreElements()) {
      String parameterName = parametersNameEnum.nextElement();
      for (String parameterValue : request.getParameterValues(parameterName)) {
        this.queryString.addQueryParam(new QueryParam(parameterName, parameterValue));
      }
    }
    this.messageContent = new MessageContent();
    StringBuffer requestBody = new StringBuffer();
    BufferedReader requestBodyReader = null;
    CharBuffer buffer = CharBuffer.allocate(512);
    try {
      requestBodyReader = new BufferedReader(new InputStreamReader(request.getInputStream()));
      while (requestBodyReader.read(buffer) >= 0) {
        requestBody.append(buffer.flip());
        buffer.clear();
      }
      this.messageContent.setRawContent(requestBody.toString());
      this.messageContent.setSize(requestBody.length());
      this.messageContent.setMimeType(request.getContentType());
    } catch (Exception ex) {
      logger.warn("Error while reading request body !", ex);
    } finally {
      try {
        if (requestBodyReader != null) {
          requestBodyReader.close();
        }
      } catch (IOException ex) {
        // logger.warn("Error while closing the requestBodyReader !",
        // ex);
      }
    }
    this.comment = "";
  }
コード例 #3
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   String title = "Showing Request Headers";
   StringBuilder sb = new StringBuilder();
   sb.append("<html>\n<head>\n");
   sb.append("<title>" + title + "</title>\n");
   sb.append("</head>\n");
   sb.append("<body bgcolor='#FDF5E6'>\n");
   sb.append("<h1 align='center'>" + title + "</h1>\n");
   sb.append("<b> Request Method: </b>" + request.getMethod() + "<br>\n");
   sb.append("<b> Request URI: </b>" + request.getRequestURI() + "<br>\n");
   sb.append("<b> Request Protocol: </b>" + request.getProtocol() + "<br>\n");
   sb.append("<table border=1 align='center'>\n");
   sb.append("<tr bgcolor='#FFAD00'>\n");
   sb.append("<th> Header Name </th><th> Header Value </th></tr>\n");
   Enumeration headerNames = request.getHeaderNames();
   while (headerNames.hasMoreElements()) {
     String headerName = (String) headerNames.nextElement();
     sb.append("<tr><td>" + headerName + "</td>");
     sb.append("<td>" + request.getHeader(headerName) + "</td></tr>\n");
   }
   sb.append("</table>\n");
   sb.append("</body></html>");
   out.println(sb.toString());
   out.close();
 }
コード例 #4
0
  public AbstractMockRequest(
      HttpServletRequest request, HttpServletResponse response, WsdlMockRunContext context) {
    this.request = request;
    this.response = response;
    this.context = context;

    requestContext = new WsdlMockRunContext(context.getMockService(), null);

    requestHeaders = new StringToStringsMap();
    for (Enumeration<?> e = request.getHeaderNames(); e.hasMoreElements(); ) {
      String header = (String) e.nextElement();
      String lcHeader = header.toLowerCase();
      if (lcHeader.equals("soapaction"))
        requestHeaders.put("SOAPAction", request.getHeader(header));
      else if (lcHeader.equals("content-type"))
        requestHeaders.put("Content-Type", request.getHeader(header));
      else if (lcHeader.equals("content-length"))
        requestHeaders.put("Content-Length", request.getHeader(header));
      else if (lcHeader.equals("content-encoding"))
        requestHeaders.put("Content-Encoding", request.getHeader(header));
      else requestHeaders.put(header, request.getHeader(header));
    }

    protocol = request.getProtocol();
    path = request.getPathInfo();
    if (path == null) path = "";
  }
コード例 #5
0
  private static Properties createCGIEnvironment(
      HttpServletRequest sreq, URI root_uri, File canonical_script_file) throws URISyntaxException {

    URI full_request_uri =
        new URI(
            sreq.getScheme(),
            null,
            sreq.getServerName(),
            sreq.getServerPort(),
            sreq.getRequestURI(),
            sreq.getQueryString(),
            null);

    Properties p =
        createCGIEnvironment(
            sreq.getMethod(),
            sreq.getProtocol(),
            full_request_uri,
            new InetSocketAddress(sreq.getLocalAddr(), sreq.getLocalPort()),
            new InetSocketAddress(sreq.getRemoteAddr(), sreq.getRemotePort()),
            sreq.getContextPath() + "/",
            root_uri,
            canonical_script_file);

    // Add request headers

    for (Enumeration e = sreq.getHeaderNames(); e.hasMoreElements(); ) {
      String h = (String) e.nextElement();
      p.setProperty(ESXX.httpToCGI(h), sreq.getHeader(h));
    }

    return p;
  }
コード例 #6
0
  protected void _init(PageContext pc, Map<String, String> arguments) {
    this.pc = pc;

    // header
    HttpServletRequest req = pc.getHttpServletRequest();

    header = new StringBuffer();
    createHeader(header, "context-path", req.getContextPath());
    createHeader(header, "remote-user", req.getRemoteUser());
    createHeader(header, "remote-addr", req.getRemoteAddr());
    createHeader(header, "remote-host", req.getRemoteHost());
    createHeader(
        header,
        "script-name",
        StringUtil.emptyIfNull(req.getContextPath())
            + StringUtil.emptyIfNull(req.getServletPath()));
    createHeader(header, "server-name", req.getServerName());
    createHeader(header, "protocol", req.getProtocol());
    createHeader(header, "server-port", Caster.toString(req.getServerPort()));
    createHeader(
        header,
        "path-info",
        StringUtil.replace(
            StringUtil.emptyIfNull(req.getRequestURI()),
            StringUtil.emptyIfNull(req.getServletPath()),
            "",
            true));
    // createHeader(header,"path-translated",pc.getBasePageSource().getDisplayPath());
    createHeader(header, "query-string", req.getQueryString());
    createHeader(header, "unit", unitShortToString(unit));
    createHeader(header, "min-time-nano", min + "");

    content = new StringBuffer();

    // directory
    String strDirectory = arguments.get("directory");
    if (dir == null) {
      if (StringUtil.isEmpty(strDirectory)) {
        dir = getTemp(pc);
      } else {
        try {
          dir = ResourceUtil.toResourceNotExisting(pc, strDirectory, false);
          if (!dir.exists()) {
            dir.createDirectory(true);
          } else if (dir.isFile()) {
            err(
                pc,
                "can not create directory [" + dir + "], there is already a file with same name.");
          }
        } catch (Throwable t) {
          err(pc, t);
          dir = getTemp(pc);
        }
      }
    }
    file = dir.getRealResource((pc.getId()) + "-" + CreateUUID.call(pc) + ".exl");
    file.createNewFile();
    start = System.currentTimeMillis();
  }
コード例 #7
0
ファイル: RequestTest.java プロジェクト: gimlet2/spark
  @Test
  public void testProtocol() {

    final String protocol = "HTTP/1.1";

    when(servletRequest.getProtocol()).thenReturn(protocol);

    assertEquals(
        "The underlying request protocol should be returned", protocol, request.protocol());
  }
コード例 #8
0
ファイル: testServlet.java プロジェクト: bjhm/Servlet-JSP
 protected void preventCaching(HttpServletRequest request, HttpServletResponse response) {
   // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
   String protocol = request.getProtocol();
   if ("HTTP/1.0".equalsIgnoreCase(protocol)) {
     response.setHeader("Pragma", "no-cache");
   } else if ("HTTP/1.1".equalsIgnoreCase(protocol)) {
     response.setHeader("Cache-Control", "no-cache"); // "no-store" work also
   }
   response.setDateHeader("Expires", 0);
 }
コード例 #9
0
  private void dumpDetails(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");

    PrintWriter out = resp.getWriter();

    out.printf("Method: %s%n", req.getMethod());
    out.printf("Request-URI: %s%n", req.getRequestURI());
    out.printf("Version: %s%n", req.getProtocol());
    out.printf("Request-URL: %s%n", req.getRequestURL());
  }
コード例 #10
0
 protected VersionNumber getHttpVersion(HttpServletRequest request) {
   final String protocol = request.getProtocol();
   if (protocol != null) {
     final String[] protocolAndVersion = protocol.split("/");
     final String[] versionNumbers = protocolAndVersion[1].split("\\.");
     final int major = Integer.parseInt(versionNumbers[0]);
     final int minor = Integer.parseInt(versionNumbers[1]);
     return new VersionNumber(major, minor);
   }
   return VersionNumber.UNDETERMINED;
 }
コード例 #11
0
 @objid("4eb24091-31da-45dc-8750-c549900243d1")
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   String protocol = req.getProtocol();
   String msg = lStrings.getString("http.method_post_not_supported");
   if (protocol.endsWith("1.1")) {
     resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
   } else {
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
   }
 }
コード例 #12
0
 @objid("c1c94dab-88d9-4ed8-b898-e70a165ce6c2")
 protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   String protocol = req.getProtocol();
   String msg = lStrings.getString("http.method_delete_not_supported");
   if (protocol.endsWith("1.1")) {
     resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
   } else {
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
   }
 }
コード例 #13
0
 @objid("a811a6cf-8feb-4032-a7fe-21c894b0fa87")
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   String protocol = req.getProtocol();
   String msg = lStrings.getString("http.method_get_not_supported");
   if (protocol.endsWith("1.1")) {
     resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
   } else {
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
   }
 }
コード例 #14
0
 @objid("97d9eeca-5874-4bfb-b547-685efd2a2db8")
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   String protocol = req.getProtocol();
   String msg = lStrings.getString("http.method_post_not_supported");
   if (protocol.endsWith("1.1")) {
     resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
   } else {
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
   }
 }
コード例 #15
0
 @objid("feb59620-9e02-4d80-94d9-62cc60892f3f")
 protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   String protocol = req.getProtocol();
   String msg = lStrings.getString("http.method_delete_not_supported");
   if (protocol.endsWith("1.1")) {
     resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
   } else {
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
   }
 }
コード例 #16
0
  private void request(HttpServletRequest request) {
    System.out.println(request.getCharacterEncoding());
    System.out.println(request.getContentType());
    System.out.println(request.getProtocol());

    Enumeration<String> e = request.getHeaderNames();
    while (e.hasMoreElements()) {
      Object o = e.nextElement();
      System.out.println(o + ":" + request.getHeader((String) o));
    }
  }
コード例 #17
0
    @Test
    public void shouldCorrectlyConstructRequestLine() {
      when(request.getProtocol()).thenReturn("HTTP/1.1");
      when(request.getRequestURI()).thenReturn("/index.html");
      when(request.getMethod()).thenReturn("GET");

      final HttpLogFormatter formatter = new HttpLogFormatter("%r");
      final String expected = "GET /index.html HTTP/1.1";

      assertEquals(expected, formatter.format(request, response));
    }
コード例 #18
0
 @objid("877708cd-6f0b-4420-a638-5e42a392a62c")
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws IOException, ServletException {
   String protocol = req.getProtocol();
   String msg = lStrings.getString("http.method_get_not_supported");
   if (protocol.endsWith("1.1")) {
     resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
   } else {
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
   }
 }
コード例 #19
0
  /**
   * This turns the builder into a Apache Combined Log Format line with a JIRA twist
   *
   * <p>http://httpd.apache.org/docs/1.3/logs.html
   *
   * @return a string representing the Apache CLF log entry
   */
  public String toApacheCombinedLogFormat() {
    final String transportProtocol = httpReq.getProtocol();
    final String httpMethod = httpReq.getMethod();
    final String remoteAddress = httpReq.getRemoteAddr();
    final String userAgent = httpReq.getHeader("User-Agent");
    final String referer = httpReq.getHeader("Referer");
    final String dateStr =
        dateOfEvent == null ? getDateString(new DateTime()) : getDateString(dateOfEvent);
    final Long contentLen = responseContentLength < 0 ? null : responseContentLength;
    final Long responseTimeMillis = responseTimeMS < 0 ? null : responseTimeMS;
    final Integer httpStatus = httpStatusCode < 0 ? null : httpStatusCode;

    final StringBuilder urlStr =
        new StringBuilder()
            .append(enc(httpMethod))
            .append(" ")
            .append(enc(url))
            .append(" ")
            .append(enc(transportProtocol));

    //
    // According to http://httpd.apache.org/docs/1.3/logs.html - Apache Combined Log Format looks
    // like this :
    //
    //      127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
    // "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"
    //
    // JIRA flavour - We insert the request id into the "identd" field, insert a time taken in field
    // 7 and put the session id at the end.
    //
    return new StringBuilder(enc(remoteAddress)) // remote address
        .append(" ")
        .append(enc(requestId)) // <<-- normally the '-' character in Apache CLF
        .append(" ")
        .append(enc(userName)) // user
        .append(" ")
        .append(enc(dateStr)) // date
        .append(" ")
        .append(quote(urlStr)) // url
        .append(" ")
        .append(enc(httpStatus)) // http return
        .append(" ")
        .append(enc(contentLen)) // content length
        .append(" ")
        .append(enc(formatMStoDecimalSecs(responseTimeMillis))) // <<-- not specified in Apache CLF
        .append(" ")
        .append(quote(referer)) // referer [sic]
        .append(" ")
        .append(quote(userAgent)) // user agent
        .append(" ")
        .append(quote(sessionId)) // <<-- not specified in Apache CLF
        .toString();
  }
コード例 #20
0
  public static ClickstreamRequest getClickstreamRequest(
      HttpServletRequest request, Date timestamp) {

    HttpSession session = request.getSession();
    long languageId = langAPI.getDefaultLanguage().getId();
    if (session.getAttribute(WebKeys.HTMLPAGE_LANGUAGE) != null) {
      languageId = Long.parseLong(session.getAttribute(WebKeys.HTMLPAGE_LANGUAGE).toString());
    }

    String uri = request.getRequestURI();
    if (request.getAttribute(WebKeys.CLICKSTREAM_URI_OVERRIDE) != null) {
      uri = (String) request.getAttribute(WebKeys.CLICKSTREAM_URI_OVERRIDE);
    }

    HostWebAPI hostWebAPI = WebAPILocator.getHostWebAPI();
    Host host = null;

    try {
      host = hostWebAPI.getCurrentHost(request);
    } catch (PortalException e) {
      Logger.error(
          ClickstreamRequestFactory.class,
          "Unable to retrieve current request host for URI " + uri);
    } catch (SystemException e) {
      Logger.error(
          ClickstreamRequestFactory.class,
          "Unable to retrieve current request host for URI  " + uri);
    } catch (DotDataException e) {
      Logger.error(
          ClickstreamRequestFactory.class,
          "Unable to retrieve current request host for URI  " + uri);
    } catch (DotSecurityException e) {
      Logger.error(
          ClickstreamRequestFactory.class,
          "Unable to retrieve current request host for URI  " + uri);
    }

    String hostIdentifier = host.getIdentifier();

    ClickstreamRequest cr = new ClickstreamRequest();
    cr.setProtocol(request.getProtocol());
    cr.setServerName(request.getServerName());
    cr.setServerPort(request.getServerPort());
    cr.setQueryString(request.getQueryString());
    cr.setRemoteUser(request.getRemoteUser());
    cr.setRequestURI(uri);
    cr.setLanguageId(languageId);
    cr.setTimestamp(timestamp);
    cr.setHostId(hostIdentifier);
    return cr;
  }
コード例 #21
0
  private Map<String, Object> makeRequestWrapper(HttpServletRequest req) {
    HashMap<String, Object> result = new HashMap<String, Object>();

    result.put("user", new UserWrap(Authenticate.getUser()));

    result.put("method", req.getMethod());
    result.put("protocol", req.getProtocol());

    result.put("url", getFullURL(req));
    result.put("contentType", req.getContentType());
    result.put("contextPath", req.getContextPath());

    return result;
  }
コード例 #22
0
  /**
   * executed when a post request happens
   *
   * @param request the request object
   * @param response the response object
   * @throws ServletException if a read error occurs
   * @throws IOException if a read error occurs
   */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    if (log.isDebugEnabled()) {
      log.debug("Entered doPost");
    }

    if (request.getHeader("SOAPAction") != null) {
      passControl(request, response);
      return;
    }

    response.setContentType("text/xml");
    try {
      if (log.isDebugEnabled()) {
        log.debug("Passing control to XmlRpcServer.execute");
      }

      server.execute(
          request.getInputStream(),
          response.getWriter(),
          request.getRemoteAddr(),
          request.getLocalName(),
          request.getProtocol());

      /*
       * jesusr - 2007.09.14
       * this is still the case
       *
       * mbowman - 2005.10.06
       * Like we were raised in a barn, we are going to leave here without
       * flushing ;)
       * -- The current thinking is that Tocmat handles the outputStream
       * -- flushing and closing for us. This make sense since after this
       * -- method runs, the response still needs to go back up through
       * -- the filters and out. If things start breaking in the future,
       * -- this is a  good place to start looking.
       */
    }
    // As bad as this is, we have no choice, Marquee-xmlrpc throws
    // Throwable, so we have to catch it.
    catch (Throwable t) {
      // By the time we get here, it can't be a FaultException, so just
      // wrap it in a ServletException and toss.
      ServletException e = new ServletException("Throwable from XmlRpc", t);
      e.initCause(t);
      throw e;
    }
  }
コード例 #23
0
ファイル: ZenoVCALServlet.java プロジェクト: tfgordon/zeno
 private String getUID(HttpServletRequest req, ZenoResource resource) {
   String prot = req.getProtocol();
   prot = prot.substring(0, prot.indexOf("/")).toLowerCase();
   String uid =
       prot
           + "://"
           + req.getServerName()
           + ":"
           + req.getServerPort()
           + req.getContextPath()
           + req.getServletPath()
           + "/"
           + resource.getId()
           + ".vcs";
   return uid;
 }
コード例 #24
0
ファイル: HelperInput.java プロジェクト: linving/absir
  /**
   * @param request
   * @return
   */
  public static String getRequestUrl(HttpServletRequest request, int defaultPort) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(request.getProtocol());
    stringBuilder.append("://");
    stringBuilder.append(request.getServerName());
    if (request.getRemotePort() != defaultPort) {
      stringBuilder.append(':');
      stringBuilder.append(request.getRemotePort());
    }

    stringBuilder.append(request.getContextPath());
    stringBuilder.append(request.getServletPath());
    if (!KernelString.isEmpty(request.getQueryString())) {
      stringBuilder.append('?');
      stringBuilder.append(request.getQueryString());
    }

    return stringBuilder.toString();
  }
コード例 #25
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String s = "";
    Enumeration enume = request.getHeaderNames();
    s += "<B>request.getHeaderNames()</B>" + "<BR>\n";
    while (enume.hasMoreElements()) {
      String h = (String) enume.nextElement();
      s += h + "->" + request.getHeader(h) + "<BR>\n";
    }
    s += "<B>request.getContextPath()</B> -> " + request.getContextPath() + "<BR>\n";
    s += "<B>request.getMethod()</B> -> " + request.getMethod() + "<BR>\n";
    s += "<B>request.getServletPath()</B> -> " + request.getServletPath() + "<BR>\n";
    s += "<B>request.getPathInfo()</B> -> " + request.getPathInfo() + "<BR>\n";
    s += "<B>request.getProtocol()</B> -> " + request.getProtocol() + "<BR>\n";
    s += "<B>request.getQueryString()</B> -> " + request.getQueryString() + "<BR>\n";
    s += "<B>request.getRemoteAddr()</B> -> " + request.getRemoteAddr() + "<BR>\n";
    s += "<B>request.getRemoteHost()</B> -> " + request.getRemoteHost() + "<BR>\n";
    s += "<B>request.getRemoteUser()</B> -> " + request.getRemoteUser() + "<BR>\n";
    s += "<B>request.getServerName()</B> -> " + request.getServerName() + "<BR>\n";
    s += "<B>request.getRequestURI()</B> -> " + request.getRequestURI() + "<BR>\n";
    s += "<B>request.getRequestURL()</B> -> " + request.getRequestURL() + "<BR>\n";
    s += "<B>request.getScheme()</B> -> " + request.getScheme() + "<BR>\n";
    s += "<B>request.getSession().getId()</B> -> " + request.getSession().getId() + "<BR>\n";

    /*
        Vector v = (new MyHomeList()).getUserHomeList("1000000376");
        s+= v.toString();

    MetaData md = new MetaData () ;
    md.setUserID("UID123");

    request.getSession().setAttribute((String)"XXX", (MetaData)md);
    */

    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>DummyServlet</title></head>");
    out.println("<body>");
    out.println(s);
    out.println("</body></html>");
    out.close();
  }
コード例 #26
0
ファイル: Request.java プロジェクト: frankely/ServletIO
  Request(HttpServletRequest request) {
    raw = request;
    scheme = request.getScheme();
    method = request.getMethod();
    port = request.getServerPort();
    uri = request.getRequestURI();
    url = request.getRequestURL().toString();
    ip = request.getRemoteAddr();
    userAgent = request.getHeader(USER_AGENT);
    pathInfo = request.getPathInfo();
    protocol = request.getProtocol();
    servletPath = request.getServletPath();
    contextPath = request.getContextPath();
    contentType = request.getContentType();
    contentLength = request.getContentLength();
    queryParams = request.getParameterMap().keySet();

    cookies = cookies();
    attributes = attributes();
    headers = headers();
  }
コード例 #27
0
ファイル: AbstractPlainProvider.java プロジェクト: oehf/ipf
  protected Map<String, Object> enrichParameters(
      FhirSearchParameters parameters, HttpServletRequest httpServletRequest) {
    // Populate some headers.
    Map<String, Object> enriched = new HashMap<>();
    enriched.put(Constants.HTTP_URI, httpServletRequest.getRequestURI());
    enriched.put(Constants.HTTP_URL, httpServletRequest.getRequestURL().toString());
    enriched.put(Constants.HTTP_METHOD, httpServletRequest.getMethod());
    enriched.put(Constants.HTTP_QUERY, httpServletRequest.getQueryString());
    enriched.put(Constants.HTTP_CHARACTER_ENCODING, httpServletRequest.getCharacterEncoding());
    enriched.put(Constants.HTTP_CONTENT_TYPE, httpServletRequest.getContentType());
    enriched.put(Constants.HTTP_PROTOCOL_VERSION, httpServletRequest.getProtocol());
    enriched.put(Constants.HTTP_SCHEME, httpServletRequest.getScheme());
    enriched.put(Constants.HTTP_CLIENT_IP_ADDRESS, httpServletRequest.getRemoteAddr());

    Map<String, List<String>> headers = extractHttpHeaders(httpServletRequest);
    enriched.put(Constants.HTTP_HEADERS, headers);

    if (parameters != null) {
      enriched.put(Constants.FHIR_REQUEST_PARAMETERS, parameters);
    }
    return enriched;
  }
コード例 #28
0
ファイル: DebugTag.java プロジェクト: automenta/lojix
  /**
   * Returns a String with all basic request information in an HTML table.
   *
   * @return A String with all basic request information in an HTML table.
   */
  public String getRequestInfo() {
    Map info = new TreeMap();
    HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();

    info.put("authType", nullToString(req.getAuthType()));
    info.put("characterEncoding", nullToString(req.getCharacterEncoding()));
    info.put("contentLength", Integer.toString(req.getContentLength()));
    info.put("contentType", nullToString(req.getContentType()));
    info.put("contextPath", nullToString(req.getContextPath()));
    info.put("pathInfo", nullToString(req.getPathInfo()));
    info.put("protocol", nullToString(req.getProtocol()));
    info.put("queryString", nullToString(req.getQueryString()));
    info.put("remoteAddr", nullToString(req.getRemoteAddr()));
    info.put("remoteHost", nullToString(req.getRemoteHost()));
    info.put("remoteUser", nullToString(req.getRemoteUser()));
    info.put("requestURI", nullToString(req.getRequestURI()));
    info.put("scheme", nullToString(req.getScheme()));
    info.put("serverName", nullToString(req.getServerName()));
    info.put("serverPort", Integer.toString(req.getServerPort()));
    info.put("servletPath", nullToString(req.getServletPath()));

    return toHTMLTable("request properties", info);
  }
コード例 #29
0
ファイル: TmlHttpServlet.java プロジェクト: rolfdeboer/navajo
 private void logRequestParams(HttpServletRequest request) {
   // logger.info("Empty service specified, request originating from "
   // + request.getRemoteHost());
   logger.info("thread = " + Thread.currentThread().hashCode());
   logger.info("path = " + request.getPathInfo());
   logger.info("query = " + request.getQueryString());
   logger.info("protocol = " + request.getProtocol());
   logger.info("agent = " + request.getRemoteUser());
   logger.info("uri = " + request.getRequestURI());
   logger.info("method = " + request.getMethod());
   logger.info("contenttype = " + request.getContentType());
   logger.info("scheme = " + request.getScheme());
   logger.info("server = " + request.getServerName());
   logger.info("port = " + request.getServerPort());
   logger.info("contentlength = " + request.getContentLength());
   Enumeration<String> enm = request.getHeaderNames();
   while (enm.hasMoreElements()) {
     String key = enm.nextElement();
     String header = request.getHeader(key);
     logger.info(">>" + key + "=" + header);
   }
   return;
 }
コード例 #30
0
ファイル: Start.java プロジェクト: cad188/eecs4413
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // Redirects to /Start if the Startup/YorkRedirect address is attempted
    if (request.getRequestURI().equals("/mCalc0/Startup/YorkRedirect")) {
      response.sendRedirect("/mCalc0/Start");
      System.out.println("Redirect successful\n");
    }

    // Send message to the console
    System.out.println("doGet Hello World\n");
    response.setContentType("plain");
    // Output message in the browser
    response.getWriter().println("doGet Hello World\n");

    double i = extractParameter("interest", request) / 100; // interest in %
    double a = extractParameter("amortization", request); // amortization
    double p = extractParameter("principle", request); // principle
    DecimalFormat truncate = new DecimalFormat("#.##");

    PrintWriter out = response.getWriter();
    out.println(
        "\tThe Networking Layer\n"
            + "Server IP: "
            + request.getLocalAddr()
            + "\n"
            + "Server Port: "
            + request.getLocalPort()
            + "\n"
            + "Client IP: "
            + request.getRemoteAddr()
            + "\n"
            + "Client Port: "
            + request.getRemotePort()
            + "\n"
            + "\n"
            + "\tThe HTTP Layer\n"
            + "Request Protocol: "
            + request.getProtocol()
            + "\n"
            + "Request Method: "
            + request.getMethod()
            + "\n"
            + "Client's query string: ("
            + request.getQueryString()
            + ")\n"
            + "Named Request Parameter: "
            + request.getParameter("name")
            + "\n"
            + "\n\tThe URL\n"
            + "URI: "
            + request.getRequestURI()
            + "\n"
            + "Context Path: "
            + request.getContextPath()
            + "\n"
            + "Servlet/Extra Path: "
            + request.getServletPath()
            + "\n"
            + "Translated Path: "
            + request.getPathTranslated()
            + "\n"
            + "\n\tContext Parameter\n"
            + "name - "
            + request.getSession().getServletContext().getServletContextName()
            + "\n"
            + "value - "
            + request.getSession().getServletContext().getInitParameter("ContextParameter")
            + "\n"
            + "\n\tThe Computation"
            + "\n"
            + "Principle: "
            + p
            + "\n"
            + "Amortization: "
            + a
            + "\n"
            + "Interest: "
            + i
            + "\n"
            + "Monthly payment: $"
            + truncate.format(computePayment(p, i, a))
            + "\n");
    // Error to be caught
    // int x = 0;
    // int y = 20/x;

  }