@Override public Charset getCharset() { String charset = null; if(myHeaders.getMediaType() != null && myHeaders.getMediaType().getParameters() != null) { charset = myHeaders.getMediaType().getParameters().get(MediaType.CHARSET_PARAMETER); } if(charset != null) { return Charset.forName(charset); } else { return null; } }
@Override public MediaType getMediaType() { return httpRequest.getHttpHeaders().getMediaType(); }
public MultivaluedMap<String, String> getPutFormParameters() { if (formParameters != null) return formParameters; MediaType mt = getHttpHeaders().getMediaType(); if (MediaType.APPLICATION_FORM_URLENCODED_TYPE.isCompatible(mt)) { try { formParameters = FormUrlEncodedProvider.parseForm(getInputStream(), mt.getParameters().get(MediaType.CHARSET_PARAMETER)); } catch (IOException e) { throw new RuntimeException(e); } } else { throw new IllegalArgumentException(Messages.MESSAGES.requestMediaTypeNotUrlencoded()); } return formParameters; }
public MultivaluedMap<String, String> getFormParameters() { if (formParameters != null) return formParameters; if (decodedFormParameters != null) { formParameters = Encode.encode(decodedFormParameters); return formParameters; } MediaType mt = getHttpHeaders().getMediaType(); if (mt.isCompatible(MediaType.valueOf("application/x-www-form-urlencoded"))) { try { formParameters = FormUrlEncodedProvider.parseForm(getInputStream(), mt.getParameters().get(MediaType.CHARSET_PARAMETER)); } catch (IOException e) { throw new RuntimeException(e); } } else { throw new IllegalArgumentException(Messages.MESSAGES.requestMediaTypeNotUrlencoded()); } return formParameters; }
MediaType mediaType = request.getHttpHeaders().getMediaType(); if (mediaType == null)
public Match match(List<Match> matches, String httpMethod, HttpRequest request) MediaType contentType = request.getHttpHeaders().getMediaType();
httpRequest.getHttpHeaders().getMediaType()); BuiltResponse responseInvoker = getResponse(model, resolvedContentType); if (responseInvoker != null)
protected View(WebContext ctx, Resource resource, String name) { super(ctx, resource, null); mediaType = ctx.getHttpHeaders().getMediaType(); this.name = name; }
@Override public MediaType getMediaType() { return httpRequest.getHttpHeaders().getMediaType(); }
@Override public Response toResponse(ConstraintViolationException exception) { ValidationExceptionRepresentation validationErrorDetails = new ValidationExceptionRepresentation(); ArrayList<ValidationExceptionRepresentation.ValidationError> validationErrors = new ArrayList<>(); boolean responseError = addErrorsToList(exception, validationErrors); validationErrorDetails.setErrors(validationErrors); return Response.status(responseError ? INTERNAL_SERVER_ERROR : BAD_REQUEST) .entity(validationErrorDetails) .type(headers.getMediaType()) .build(); }
protected OEntity getRequestEntity(HttpHeaders httpHeaders, UriInfo uriInfo, String payload, EdmDataServices metadata, String entitySetName, OEntityKey entityKey) { // TODO validation of MaxDataServiceVersion against DataServiceVersion // see spec [ms-odata] section 1.7 ODataVersion version = InternalUtil.getDataServiceVersion(httpHeaders.getRequestHeaders().getFirst(ODataConstants.Headers.DATA_SERVICE_VERSION)); return convertFromString(payload, httpHeaders.getMediaType(), version, metadata, entitySetName, entityKey); }
@PUT @Path("emptyput") @Consumes("application/json") public void emptyput() { if (!"application/json".equals(httpHeaders.getMediaType().toString())) { throw new RuntimeException(); } }
private OEntityId parseRequestUri(HttpHeaders httpHeaders, UriInfo uriInfo, String payload) { FormatParser<SingleLink> parser = FormatParserFactory.getParser(SingleLink.class, httpHeaders.getMediaType(), null); SingleLink link = parser.parse(new StringReader(payload)); return OEntityIds.parse(uriInfo.getBaseUri().toString(), link.getUri()); }
@Test public void testGetMediaType() throws Exception { MediaType mediaType = httpHeaders1.getMediaType(); assertNotNull(mediaType); assertEquals(mediaType.getType(), "text"); assertEquals(mediaType.getSubtype(), "html"); assertEquals(mediaType.toString(), "text/html"); MediaType mediaType2 = httpHeaders2.getMediaType(); assertNull(mediaType2); }
@Override public String toString() { return String.format("Method: %s, Path: %s, MediaType: %s", //$NON-NLS-1$ getHttpMethod(), getUriInfo().getPath(false), getHttpHeaders().getMediaType()); }
protected Response deleteInternal(String version, String persistenceUnit, String type, String id, HttpHeaders headers, UriInfo uriInfo) { JPARSLogger.entering(CLASS_NAME, "deleteInternal", new Object[] { "DELETE", headers.getMediaType(), version, persistenceUnit, type, id, uriInfo.getRequestUri().toASCIIString() }); try { PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Map<String, String> discriminators = getMatrixParameters(uriInfo, persistenceUnit); Object entityId = IdHelper.buildId(context, type, id); context.delete(discriminators, type, entityId); return Response.ok().build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
protected Response deleteInternal(String version, String persistenceUnit, String type, String id, HttpHeaders headers, UriInfo uriInfo) { JPARSLogger.entering(CLASS_NAME, "deleteInternal", new Object[] { "DELETE", headers.getMediaType(), version, persistenceUnit, type, id, uriInfo.getRequestUri().toASCIIString() }); try { PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Map<String, String> discriminators = getMatrixParameters(uriInfo, persistenceUnit); Object entityId = IdHelper.buildId(context, type, id); context.delete(discriminators, type, entityId); return Response.ok().build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
protected Response updateInternal(String version, String persistenceUnit, String type, HttpHeaders headers, UriInfo uriInfo, InputStream in) { JPARSLogger.entering(CLASS_NAME, "updateInternal", new Object[] { "POST", headers.getMediaType(), version, persistenceUnit, type, uriInfo.getRequestUri().toASCIIString() }); try { PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Object entity = context.unmarshalEntity(type, mediaType(headers.getAcceptableMediaTypes()), in); entity = context.merge(getMatrixParameters(uriInfo, persistenceUnit), entity); return Response.ok(new StreamingOutputMarshaller(context, singleEntityResponse(context, entity, uriInfo), headers.getAcceptableMediaTypes())).build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
protected Response updateInternal(String version, String persistenceUnit, String type, HttpHeaders headers, UriInfo uriInfo, InputStream in) { JPARSLogger.entering(CLASS_NAME, "updateInternal", new Object[] { "POST", headers.getMediaType(), version, persistenceUnit, type, uriInfo.getRequestUri().toASCIIString() }); try { PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Object entity = context.unmarshalEntity(type, mediaType(headers.getAcceptableMediaTypes()), in); entity = context.merge(getMatrixParameters(uriInfo, persistenceUnit), entity); return Response.ok(new StreamingOutputMarshaller(context, singleEntityResponse(context, entity, uriInfo), headers.getAcceptableMediaTypes())).build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
@GET @Path("/books/feed") @Produces({"application/atom+xml", "application/json" }) public Feed getBooksAsFeed(@Context UriInfo uParam) { MediaType mt = headers.getMediaType(); if (!mt.equals(MediaType.valueOf(MediaType.MEDIA_TYPE_WILDCARD)) && !mt.equals(MediaType.APPLICATION_JSON_TYPE) && !mt.equals(MediaType.APPLICATION_ATOM_XML_TYPE)) { throw new WebApplicationException(); } return doGetBookAsFeed(uParam); }