Ejemplo n.º 1
0
 static {
   CONTENT_TYPES.put(ContentType.HTTP, Response.HTTP);
   CONTENT_TYPES.put(ContentType.MULTIPART, Response.MULTIPART);
   CONTENT_TYPES.put(ContentType.XML, Response.XML);
   for (final Entry<ContentType, String> entry : CONTENT_TYPES.entrySet())
     TYPE_CONTENTS.put(entry.getValue(), entry.getKey());
 }
Ejemplo n.º 2
0
 @Override
 public void parseRequestParameters(
     final Map<String, String> params, final Map<String, com.bradmcevoy.http.FileItem> files)
     throws RequestParseException {
   try {
     if (isMultiPart()) {
       parseQueryString(params, req.getQueryString());
       @SuppressWarnings("unchecked")
       final List<FileItem> items = new ServletFileUpload().parseRequest(req);
       for (final FileItem item : items) {
         if (item.isFormField()) params.put(item.getFieldName(), item.getString());
         else files.put(item.getFieldName(), new FileItemWrapper(item));
       }
     } else {
       final Enumeration<String> en = req.getParameterNames();
       while (en.hasMoreElements()) {
         final String nm = en.nextElement();
         final String val = req.getParameter(nm);
         params.put(nm, val);
       }
     }
   } catch (final FileUploadException ex) {
     throw new RequestParseException("FileUploadException", ex);
   } catch (final Throwable ex) {
     throw new RequestParseException(ex.getMessage(), ex);
   }
 }
Ejemplo n.º 3
0
 @Override
 public Map<String, String> getHeaders() {
   final Map<String, String> map = new HashMap<>();
   final Enumeration<String> en = req.getHeaderNames();
   while (en.hasMoreElements()) {
     final String name = en.nextElement();
     final String val = req.getHeader(name);
     map.put(name, val);
   }
   return map;
 }
Ejemplo n.º 4
0
 /**
  * Parse the query string.
  *
  * @param map parsed key-values will be stored here
  * @param qs query string
  */
 private static void parseQueryString(final Map<String, String> map, final String qs) {
   if (qs == null) return;
   for (final String nv : qs.split("&")) {
     final String[] parts = nv.split("=");
     final String key = parts[0];
     String val = null;
     if (parts.length > 1) {
       val = parts[1];
       if (val != null) {
         try {
           val = URLDecoder.decode(val, Token.UTF8);
         } catch (final UnsupportedEncodingException ex) {
           throw new RuntimeException(ex);
         }
       }
     }
     map.put(key, val);
   }
 }
Ejemplo n.º 5
0
 /**
  * Request content type.
  *
  * @return the content type of the current request
  */
 private ContentType getRequestContentType() {
   final String s = req.getContentType();
   if (s == null) return null;
   if (s.contains(Response.MULTIPART)) return ContentType.MULTIPART;
   return TYPE_CONTENTS.get(s);
 }