Java 类javax.servlet.http.HttpUtils 实例源码

项目:HowTomcatWorks    文件:HttpResponseBase.java   
/**
 * Convert (if necessary) and return the absolute URL that represents the
 * resource referenced by this possibly relative URL.  If this URL is
 * already absolute, return it unchanged.
 *
 * @param location URL to be (possibly) converted and then returned
 *
 * @exception IllegalArgumentException if a MalformedURLException is
 *  thrown when converting the relative URL to an absolute one
 */
private String toAbsolute(String location) {

    if (location == null)
        return (location);

    // Construct a new absolute URL if possible (cribbed from
    // the DefaultErrorPage servlet)
    URL url = null;
    try {
        url = new URL(location);
    } catch (MalformedURLException e1) {
        HttpServletRequest hreq =
            (HttpServletRequest) request.getRequest();
        String requrl = HttpUtils.getRequestURL(hreq).toString();
        try {
            url = new URL(new URL(requrl), location);
        } catch (MalformedURLException e2) {
            throw new IllegalArgumentException(location);
        }
    }
    return (url.toExternalForm());

}
项目:javamelody    文件:TestPayloadNameRequestWrapper.java   
Map<String, String[]> getParameterMap() throws IOException {
    final Map<String, String[]> parameterMap = new HashMap<String, String[]>();

    if (request.getQueryString() != null) {
        final Map<String, String[]> queryParams = HttpUtils
                .parseQueryString(request.getQueryString());
        parameterMap.putAll(queryParams);
    }

    if (request.getContentType() != null
            && request.getContentType().startsWith("application/x-www-form-urlencoded")) {
        //get form params from body data
        //note this consumes the inputstream!  But that's what happens on Tomcat
        final Map<String, String[]> bodyParams = HttpUtils.parsePostData(body.length(),
                request.getInputStream());

        //merge body params and query params
        for (final String key : bodyParams.keySet()) {

            final String[] queryValues = parameterMap.get(key);
            final String[] bodyValues = bodyParams.get(key);

            final List<String> values = new ArrayList<String>();
            if (queryValues != null) {
                values.addAll(Arrays.asList(queryValues));
            }

            values.addAll(Arrays.asList(bodyValues));

            parameterMap.put(key, values.toArray(new String[values.size()]));
        }
    } //end if form-encoded params in request body

    return parameterMap;
}
项目:Deskera-HRMS    文件:URLUtil.java   
public static String getPageURL(HttpServletRequest request, String pagePathFormat) {
    String subdomain = request.getParameter("cdomain");
    String path = HttpUtils.getRequestURL(request).toString();
    String servPath = request.getServletPath();
    String uri = path.replace(servPath, "/" + String.format(pagePathFormat, subdomain));
    return uri;
}
项目:iaf    文件:IbisSoapServlet.java   
private void zip(HttpServletRequest req, HttpServletResponse res) throws IOException, XMLStreamException, NamingException, ConfigurationException {
    Adapter adapter = getAdapter(ibisManager, req.getPathInfo());
    Wsdl wsdl = new Wsdl(adapter.getPipeLine());
    wsdl.setUseIncludes(true);
    setDocumentation(wsdl, req);
    wsdl.init();
    res.setHeader("Content-Disposition",
        "inline;filename=\"" + wsdl.getFilename() + ".zip\"");
    String servlet = HttpUtils.getRequestURL(req).toString();
    servlet = servlet.substring(0, servlet.lastIndexOf(".")) + getWsdlExtention();
    wsdl.zip(res.getOutputStream(), servlet);
}
项目:deskshare-public    文件:JnlpFileHandler.java   
public synchronized DownloadResponse getJnlpFile(JnlpResource jnlpres, DownloadRequest dreq) throws IOException {
      String path = jnlpres.getPath();
      URL resource = jnlpres.getResource();
      long lastModified = jnlpres.getLastModified();
      _log.addDebug("lastModified: " + lastModified + " " + new Date(lastModified));
      if (lastModified == 0) {
          _log.addWarning("servlet.log.warning.nolastmodified", path);
      }
// fix for 4474854:  use the request URL as key to look up jnlp file in hash map
String reqUrl = HttpUtils.getRequestURL(dreq.getHttpRequest()).toString();
JnlpFileEntry jnlpFile = null;
// utilize internal cache of previously generated jnlp files
if (useCaching) {
    // Check if entry already exist in HashMap
    jnlpFile = (JnlpFileEntry) _jnlpFiles.get(reqUrl);
    if (jnlpFile != null && jnlpFile.getLastModified() == lastModified) {
        // Entry found in cache, so return it
        return jnlpFile.getResponse();
    }
}
      // Read information from WAR file
      long timeStamp = lastModified;
      String mimeType = _servletContext.getMimeType(path);
      if (mimeType == null) mimeType = JNLP_MIME_TYPE;
      StringBuffer jnlpFileTemplate = new StringBuffer();
      URLConnection conn = resource.openConnection();
      BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      String line = br.readLine();
      if (line != null && line.startsWith("TS:")) {
          timeStamp = parseTimeStamp(line.substring(3));
          _log.addDebug("Timestamp: " + timeStamp + " " + new Date(timeStamp));
          if (timeStamp == 0) {
              _log.addWarning("servlet.log.warning.notimestamp", path);
              timeStamp = lastModified;
          }
          line = br.readLine();
      }
      while(line != null) {
          jnlpFileTemplate.append(line);
          line = br.readLine();
      }
      String jnlpFileContent = specializeJnlpTemplate(dreq.getHttpRequest(), path, jnlpFileTemplate.toString());
      // Convert to bytes as a UTF-8 encoding
      byte[] byteContent = jnlpFileContent.getBytes("UTF-8");
      // Create entry
      DownloadResponse resp = DownloadResponse.getFileDownloadResponse(byteContent, mimeType, timeStamp, jnlpres.getReturnVersionId());
if (useCaching) {
    jnlpFile = new JnlpFileEntry(resp, lastModified);
    _jnlpFiles.put(reqUrl, jnlpFile);
}
      return resp;
  }
项目:webstart    文件:JnlpFileHandler.java   
public synchronized DownloadResponse getJnlpFile( JnlpResource jnlpres, DownloadRequest dreq )
        throws IOException
{
    String path = jnlpres.getPath();
    URL resource = jnlpres.getResource();
    long lastModified = jnlpres.getLastModified();

    _log.addDebug( "lastModified: " + lastModified + " " + new Date( lastModified ) );
    if ( lastModified == 0 )
    {
        _log.addWarning( "servlet.log.warning.nolastmodified", path );
    }

    // fix for 4474854:  use the request URL as key to look up jnlp file
    // in hash map
    String reqUrl = HttpUtils.getRequestURL( dreq.getHttpRequest() ).toString();

    // Check if entry already exist in HashMap
    JnlpFileEntry jnlpFile = (JnlpFileEntry) _jnlpFiles.get( reqUrl );

    if ( jnlpFile != null && jnlpFile.getLastModified() == lastModified )
    {
        // Entry found in cache, so return it
        return jnlpFile.getResponse();
    }

    // Read information from WAR file
    long timeStamp = lastModified;
    String mimeType = _servletContext.getMimeType( path );
    if ( mimeType == null )
    {
        mimeType = JNLP_MIME_TYPE;
    }

    StringBuilder jnlpFileTemplate = new StringBuilder();
    URLConnection conn = resource.openConnection();
    BufferedReader br = new BufferedReader( new InputStreamReader( conn.getInputStream(), "UTF-8" ) );
    String line = br.readLine();
    if ( line != null && line.startsWith( "TS:" ) )
    {
        timeStamp = parseTimeStamp( line.substring( 3 ) );
        _log.addDebug( "Timestamp: " + timeStamp + " " + new Date( timeStamp ) );
        if ( timeStamp == 0 )
        {
            _log.addWarning( "servlet.log.warning.notimestamp", path );
            timeStamp = lastModified;
        }
        line = br.readLine();
    }
    while ( line != null )
    {
        jnlpFileTemplate.append( line );
        line = br.readLine();
    }

    String jnlpFileContent = specializeJnlpTemplate( dreq.getHttpRequest(), path, jnlpFileTemplate.toString() );

    // Convert to bytes as a UTF-8 encoding
    byte[] byteContent = jnlpFileContent.getBytes( "UTF-8" );

    // Create entry
    DownloadResponse resp =
            DownloadResponse.getFileDownloadResponse( byteContent, mimeType, timeStamp, jnlpres.getReturnVersionId() );
    jnlpFile = new JnlpFileEntry( resp, lastModified );
    _jnlpFiles.put( reqUrl, jnlpFile );

    return resp;
}
项目:Deskera-HRMS    文件:URLUtil.java   
public static String getPageURL(HttpServletRequest request, String pagePathFormat,String subdomain) {
    String path = HttpUtils.getRequestURL(request).toString();
    String servPath = request.getServletPath();
    String uri = path.replace(servPath, "/" + String.format(pagePathFormat, subdomain));
    return uri;
}