List of usage examples for javax.servlet.http HttpServletRequest getCharacterEncoding
public String getCharacterEncoding();
From source file:com.adito.boot.Util.java
/** * Decode a string based on the either the _charset_ request parameter that * may have been suplied with a request or the requests character encoding. * <p>//from www. j av a 2 s . com * TODO Make sure this still works and it being used correctly, im not so * sure it is! * * @param request request to get encoding from * @param string string to decode * @return decoded string */ public static String decodeRequestString(HttpServletRequest request, String string) { String enc = request.getParameter("_charset_"); if (enc != null && !enc.equals("ISO-8859-1")) { try { return new String(string.getBytes("ISO-8859-1"), enc); } catch (Exception e) { } } enc = request.getCharacterEncoding(); if (enc != null && !enc.equals("ISO-8859-1")) { try { return new String(string.getBytes("ISO-8859-1"), enc); } catch (Exception e) { } } return string; }
From source file:org.mortbay.servlet.MultiPartRequest.java
/** Constructor. * @param request The request containing a multipart/form-data * request// ww w .ja v a 2 s . c o m * @exception IOException IOException */ public MultiPartRequest(HttpServletRequest request) throws IOException { _request = request; String content_type = request.getHeader("Content-Type"); if (!content_type.startsWith("multipart/form-data")) throw new IOException("Not multipart/form-data request"); //if(log.isDebugEnabled())log.debug("Multipart content type = "+content_type); _encoding = request.getCharacterEncoding(); if (_encoding != null) _in = new LineInput(request.getInputStream(), 2048, _encoding); else _in = new LineInput(request.getInputStream()); // Extract boundary string _boundary = "--" + value(content_type.substring(content_type.indexOf("boundary="))); //if(log.isDebugEnabled())log.debug("Boundary="+_boundary); _byteBoundary = (_boundary + "--").getBytes("UTF-8"); loadAllParts(); }
From source file:org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryRestEndpoint.java
@POST @Produces(MediaType.TEXT_HTML)/*from ww w . jav a 2s . c o m*/ @Path(WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX + "{mediaPackageID}/{mediaPackageElementID}/{filename}") @RestQuery(name = "putWithFilename", description = "Store a file in working repository under ./mediaPackageID/mediaPackageElementID/filename", returnDescription = "The URL to access the stored file", pathParameters = { @RestParameter(name = "mediaPackageID", description = "the mediapackage identifier", isRequired = true, type = STRING), @RestParameter(name = "mediaPackageElementID", description = "the mediapackage element identifier", isRequired = true, type = STRING), @RestParameter(name = "filename", description = "the filename", isRequired = true, type = FILE) }, reponses = { @RestResponse(responseCode = SC_OK, description = "OK, file stored") }) public Response restPutURLEncoded(@Context HttpServletRequest request, @PathParam("mediaPackageID") String mediaPackageID, @PathParam("mediaPackageElementID") String mediaPackageElementID, @PathParam("filename") String filename, @FormParam("content") String content) throws Exception { String encoding = request.getCharacterEncoding(); if (encoding == null) encoding = "utf-8"; URI url = this.put(mediaPackageID, mediaPackageElementID, filename, IOUtils.toInputStream(content, encoding)); return Response.ok(url.toString()).build(); }
From source file:com.alibaba.citrus.service.requestcontext.parser.impl.ParameterParserImpl.java
/** ?query string */ private void parseQueryString(ParserRequestContext requestContext, HttpServletRequest wrappedRequest) { // useBodyEncodingForURI=truerequest.setCharacterEncoding()???URIEncodingUTF-8 // useBodyEncodingForURItrue // tomcat?tomcat8859_1 String charset = requestContext.isUseBodyEncodingForURI() ? wrappedRequest.getCharacterEncoding() : requestContext.getURIEncoding(); QueryStringParser parser = new QueryStringParser(charset, DEFAULT_CHARSET_ENCODING) { @Override// w ww. j a v a 2 s.c o m protected void add(String key, String value) { ParameterParserImpl.this.add(key, value); } }; parser.parse(wrappedRequest.getQueryString()); }
From source file:unUtils.ActionError.java
@Override public Object doAction(WikittyPublicationContext context) { error.printStackTrace();/* w w w. ja v a 2 s .co m*/ HttpServletRequest req = context.getRequest(); String result = "<html><body>Error: " + "<br>context: " + context + "<br>" + "<br>getContextPath: " + req.getContextPath() + "<br>getMethod: " + req.getMethod() + "<br>getPathInfo: " + req.getPathInfo() + "<br>getPathTranslated: " + req.getPathTranslated() + "<br>getQueryString: " + req.getQueryString() + "<br>getRemoteUser: " + req.getRemoteUser() + "<br>getRequestURI: " + req.getRequestURI() + "<br>getRequestURI: " + req.getRequestURI() + "<br>getRequestedSessionId: " + req.getRequestedSessionId() + "<br>getServletPath: " + req.getServletPath() + "<br>getCharacterEncoding: " + req.getCharacterEncoding() + "<br>getContentType: " + req.getContentType() + "<br>getLocalAddr: " + req.getLocalAddr() + "<br>getLocalName: " + req.getLocalName() + "<br>getProtocol: " + req.getProtocol() + "<br>getRemoteAddr: " + req.getRemoteAddr() + "<br>getRemoteHost: " + req.getRemoteHost() + "<br>getScheme: " + req.getScheme() + "<br>getServerName: " + req.getServerName() + "<br>" + "<br>error:<pre>" + StringEscapeUtils.escapeHtml(ExceptionUtil.stackTrace(error)) + "</pre>" + "</body></html>"; return result; }
From source file:org.apache.shindig.social.opensocial.service.RestfulRequestItem.java
public RestfulRequestItem(HttpServletRequest servletRequest, SecurityToken token, BeanConverter converter) { super(getServiceFromPath(servletRequest.getPathInfo()), getMethod(servletRequest), token, converter); this.url = servletRequest.getPathInfo(); this.params = createParameterMap(servletRequest); String method = getMethod(servletRequest); if (method != null && !("GET").equals(method) && !("HEAD").equals(method)) { try {/*w w w .j a va2 s . c om*/ ServletInputStream is = servletRequest.getInputStream(); postData = IOUtils.toString(is, servletRequest.getCharacterEncoding()); } catch (IOException e) { throw new RuntimeException("Could not get the post data from the request", e); } } }
From source file:net.lightbody.bmp.proxy.jetty.servlet.MultiPartRequest.java
/** Constructor. * @param request The request containing a multipart/form-data * request//from w w w. j a va2 s .co m * @exception IOException IOException */ public MultiPartRequest(HttpServletRequest request) throws IOException { _request = request; String content_type = request.getHeader(HttpFields.__ContentType); if (!content_type.startsWith("multipart/form-data")) throw new IOException("Not multipart/form-data request"); if (log.isDebugEnabled()) log.debug("Multipart content type = " + content_type); _encoding = request.getCharacterEncoding(); if (_encoding != null) _in = new LineInput(request.getInputStream(), 2048, _encoding); else _in = new LineInput(request.getInputStream()); // Extract boundary string _boundary = "--" + value(content_type.substring(content_type.indexOf("boundary="))); if (log.isDebugEnabled()) log.debug("Boundary=" + _boundary); _byteBoundary = (_boundary + "--").getBytes(StringUtil.__ISO_8859_1); loadAllParts(); }
From source file:org.apache.jackrabbit.server.util.HttpMultipartPost.java
/** * /*from w w w . ja v a 2 s .c o m*/ * @param request * @param tmpDir * @throws IOException */ private void extractMultipart(HttpServletRequest request, File tmpDir) throws IOException { if (!ServletFileUpload.isMultipartContent(request)) { log.debug("Request does not contain multipart content -> ignoring."); return; } ServletFileUpload upload = new ServletFileUpload(getFileItemFactory(tmpDir)); // make sure the content disposition headers are read with the charset // specified in the request content type (or UTF-8 if no charset is specified). // see JCR if (request.getCharacterEncoding() == null) { upload.setHeaderEncoding("UTF-8"); } try { @SuppressWarnings("unchecked") List<FileItem> fileItems = upload.parseRequest(request); for (FileItem fileItem : fileItems) { addItem(fileItem); } } catch (FileUploadException e) { log.error("Error while processing multipart.", e); throw new IOException(e.toString()); } }
From source file:com.jdon.jivejdon.presentation.servlet.upload.ExtendedMultiPartRequestHandler.java
/** * Adds a regular text parameter to the set of text parameters for this * request and also to the list of all parameters. Handles the case of * multiple values for the same parameter by using an array for the * parameter value.//w w w. j a v a 2 s .c o m * * @param request * The request in which the parameter was specified. * @param item * The file item for the parameter to add. */ protected void addTextParameter(HttpServletRequest request, FileItem item) { String name = item.getFieldName(); String value = null; boolean haveValue = false; String encoding = request.getCharacterEncoding(); if (encoding != null) { try { value = item.getString(encoding); haveValue = true; } catch (Exception e) { // Handled below, since haveValue is false. } } if (!haveValue) { try { value = item.getString("ISO-8859-1"); } catch (java.io.UnsupportedEncodingException uee) { value = item.getString(); } haveValue = true; } if (request instanceof MultipartRequestWrapper) { MultipartRequestWrapper wrapper = (MultipartRequestWrapper) request; wrapper.setParameter(name, value); } String[] oldArray = (String[]) elementsText.get(name); String[] newArray; if (oldArray != null) { newArray = new String[oldArray.length + 1]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); newArray[oldArray.length] = value; } else { newArray = new String[] { value }; } elementsText.put(name, newArray); elementsAll.put(name, newArray); }
From source file:org.apache.wicket.protocol.http.servlet.MultipartServletWebRequestImpl.java
@Override public void parseFileParts() throws FileUploadException { HttpServletRequest request = getContainerRequest(); // The encoding that will be used to decode the string parameters // It should NOT be null at this point, but it may be // especially if the older Servlet API 2.2 is used String encoding = request.getCharacterEncoding(); // The encoding can also be null when using multipart/form-data encoded forms. // In that case we use the [application-encoding] which we always demand using // the attribute 'accept-encoding' in wicket forms. if (encoding == null) { encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding(); }//from ww w . ja v a 2s . com FileUploadBase fileUpload = newFileUpload(encoding); List<FileItem> items; if (wantUploadProgressUpdates()) { ServletRequestContext ctx = new ServletRequestContext(request) { @Override public InputStream getInputStream() throws IOException { return new CountingInputStream(super.getInputStream()); } }; totalBytes = request.getContentLength(); onUploadStarted(totalBytes); try { items = fileUpload.parseRequest(ctx); } finally { onUploadCompleted(); } } else { // try to parse the file uploads by using Apache Commons FileUpload APIs // because they are feature richer (e.g. progress updates, cleaner) items = fileUpload.parseRequest(new ServletRequestContext(request)); if (items.isEmpty()) { // fallback to Servlet 3.0 APIs items = readServlet3Parts(request); } } // Loop through items for (final FileItem item : items) { // Get next item // If item is a form field if (item.isFormField()) { // Set parameter value final String value; if (encoding != null) { try { value = item.getString(encoding); } catch (UnsupportedEncodingException e) { throw new WicketRuntimeException(e); } } else { value = item.getString(); } addParameter(item.getFieldName(), value); } else { List<FileItem> fileItems = files.get(item.getFieldName()); if (fileItems == null) { fileItems = new ArrayList<>(); files.put(item.getFieldName(), fileItems); } // Add to file list fileItems.add(item); } } }