Package org.cruxframework.crux.core.server.rest.core

Examples of org.cruxframework.crux.core.server.rest.core.MediaType


  public Object extractValue(String strVal, HttpRequest request)
  {
    Object value = extractValue(strVal);
    if (strVal != null && value == null)
    {
      MediaType mediaType = request.getHttpHeaders().getMediaType();
      if (mediaType == null)
      {
        mediaType = MediaType.WILDCARD_TYPE;
      }
      if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE))
      {
        if (this.reader == null)
        {
          lock.lock();
          try
          {
            if (this.reader == null)
            {
              this.reader = JsonUtil.createReader(type);
            }
          }
          finally
          {
            lock.unlock();
          }
        }
        try
                {
          if (strVal == null || strVal.length()==0)
          {
            strVal = defaultValue;
          }
                  value = this.reader.readValue(strVal);
                }
                catch (Exception e)
                {
              throw new BadRequestException("Can not read request body for path: " + request.getUri().getPath(), e);
                }
      }
      else
      {
        throw new UnsupportedMediaTypeException("Media type not supported: " + mediaType.toString());
      }
    }
    return value;
  }
View Full Code Here


         while (start < params.length())
         {
            start = HeaderParameterParser.setParam(typeParams, params, start);
         }
         return new MediaType(major, subtype, typeParams);
      }
      else
      {
         return new MediaType(major, subtype);
      }
   }
View Full Code Here

      String responseContent = methodReturn.getReturn();
      byte[] responseBytes = getResponseBytes(request, response, responseContent);
      response.setContentLength(responseBytes.length);
      response.setStatus(HttpServletResponse.SC_OK);
      outputHeaders.putSingle(HttpHeaderNames.CONTENT_TYPE, new MediaType("application", "json", "UTF-8"));
      response.getOutputStream().write(responseBytes);
    }
  }
View Full Code Here

    response.setStatus(status);
    if (message!= null)
    {
      byte[] responseBytes = HttpResponse.serializeException(message).getBytes("UTF-8");
      response.setContentLength(responseBytes.length);
      response.setHeader(HttpHeaderNames.CONTENT_TYPE, MediaTypeHeaderParser.toString(new MediaType("text", "plain", "UTF-8")));
      response.getOutputStream().write(responseBytes);
    }
  }
View Full Code Here

    response.setStatus(status);
    if (message!= null)
    {
      byte[] responseBytes = message.getBytes("UTF-8");
      response.setContentLength(responseBytes.length);
      outputHeaders.putSingle(HttpHeaderNames.CONTENT_TYPE, new MediaType("text", "plain", "UTF-8"));
      response.getOutputStream().write(responseBytes);
      response.flushBuffer();
    }
  }
View Full Code Here

TOP

Related Classes of org.cruxframework.crux.core.server.rest.core.MediaType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.