本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}