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


Java HttpUtils类代码示例

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


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

示例1: toAbsolute

import javax.servlet.http.HttpUtils; //导入依赖的package包/类
/**
 * 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());

}
 
开发者ID:eclipsky,项目名称:HowTomcatWorks,代码行数:34,代码来源:HttpResponseBase.java

示例2: getParameterMap

import javax.servlet.http.HttpUtils; //导入依赖的package包/类
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;
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:36,代码来源:TestPayloadNameRequestWrapper.java

示例3: getPageURL

import javax.servlet.http.HttpUtils; //导入依赖的package包/类
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;
}
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:8,代码来源:URLUtil.java

示例4: zip

import javax.servlet.http.HttpUtils; //导入依赖的package包/类
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);
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:13,代码来源:IbisSoapServlet.java

示例5: getJnlpFile

import javax.servlet.http.HttpUtils; //导入依赖的package包/类
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;
  }
 
开发者ID:BigMarker,项目名称:deskshare-public,代码行数:53,代码来源:JnlpFileHandler.java

示例6: getJnlpFile

import javax.servlet.http.HttpUtils; //导入依赖的package包/类
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;
}
 
开发者ID:mojohaus,项目名称:webstart,代码行数:69,代码来源:JnlpFileHandler.java


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