/** * Constructor. * * @param xmlRepresentation * A source XML representation to parse. */ public DomRepresentation(Representation xmlRepresentation) { super((xmlRepresentation == null) ? null : xmlRepresentation .getMediaType()); this.xmlRepresentation = xmlRepresentation; }
/** * Creates a new JAXB representation, converting the input XML into a Java * content tree. The XML is validated. * * @param xmlRepresentation * The XML wrapped in a representation. * @param contextPath * The list of Java package names for JAXB. * @param validationHandler * A handler for dealing with validation failures. * * @throws JAXBException * If the incoming XML does not validate against the schema. * @throws IOException * If unmarshalling XML fails. */ public JaxbRepresentation(Representation xmlRepresentation, String contextPath, ValidationEventHandler validationHandler) { super(xmlRepresentation.getMediaType()); this.contextPath = contextPath; this.object = null; this.validationEventHandler = validationHandler; this.xmlRepresentation = xmlRepresentation; }
@Override public Header getContentType() { final String contentType = (entity.getMediaType() != null) ? entity .getMediaType().toString() : null; if (contentType != null) { return new BasicHeader("Content-Type", contentType); } else { return null; } }
@Override public MediaType getMediaType() { return getWrappedRepresentation().getMediaType(); }
/** * Returns the schema URI for the current schema media type. * * @return The schema URI. */ private static String getSchemaLanguageUri( Representation schemaRepresentation) { String result = null; if (schemaRepresentation != null) { if (MediaType.APPLICATION_W3C_SCHEMA_XML .equals(schemaRepresentation.getMediaType())) { result = XMLConstants.W3C_XML_SCHEMA_NS_URI; } else if (MediaType.APPLICATION_RELAXNG_COMPACT .equals(schemaRepresentation.getMediaType())) { result = XMLConstants.RELAXNG_NS_URI; } else if (MediaType.APPLICATION_RELAXNG_XML .equals(schemaRepresentation.getMediaType())) { result = XMLConstants.RELAXNG_NS_URI; } } return result; }
/** * Constructor reading the object from a serialized representation. This * representation must have the proper media type: * "application/x-java-serialized-object". * * @param serializedRepresentation * The serialized representation. * @throws IOException * @throws ClassNotFoundException * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") public ObjectRepresentation(Representation serializedRepresentation) throws IOException, ClassNotFoundException, IllegalArgumentException { super(MediaType.APPLICATION_JAVA_OBJECT); if (serializedRepresentation.getMediaType().equals( MediaType.APPLICATION_JAVA_OBJECT)) { final ObjectInputStream ois = new ObjectInputStream( serializedRepresentation.getStream()); this.object = (T) ois.readObject(); ois.close(); } else { throw new IllegalArgumentException( "The serialized representation must have this media type: " + MediaType.APPLICATION_JAVA_OBJECT.toString()); } }
void checkPosMediaType(Representation entity) throws GeoWebCacheException { String remoteAdr = getRequest().getClientInfo().getAddress(); if (entity == null || ((!entity.getMediaType().includes(MediaType.APPLICATION_XML)) && (!entity.getMediaType().includes(MediaType.APPLICATION_JSON)))) { String message = "Request from "+ remoteAdr + " did not specify MIME type" + " of the document posted. Please specify application/xml " + " or application/json"; throw new GeoWebCacheException(message); } else { log.info("Received seed request from " + remoteAdr); } }
public Response get(Reference uri, MediaType accepts) throws NotSuccessException, MediaTypeException { Response response = request(Method.GET, uri, null, null, accepts); MediaType mediaType = response.getEntity().getMediaType(); if (!accepts.includes(mediaType)) { throw new MediaTypeException(accepts, mediaType); } return response; }
/** * Constructor. * * @param xmlRepresentation * A source XML representation to parse. * @throws IOException */ public SaxRepresentation(Representation xmlRepresentation) { super(xmlRepresentation.getMediaType()); try { if (xmlRepresentation instanceof XmlRepresentation) { this.source = ((XmlRepresentation) xmlRepresentation) .getSaxSource(); } else { this.source = new SAXSource(new InputSource(xmlRepresentation .getStream())); } if (xmlRepresentation.getIdentifier() != null) { this.source.setSystemId(xmlRepresentation.getIdentifier() .getTargetRef().toString()); } } catch (IOException ioe) { ioe.printStackTrace(); } }
private File doFileUpload() { try { getResponse().setStatus(Status.SUCCESS_ACCEPTED); File directory = catalog.getResourceLoader().findOrCreateDirectory(getDirectoryPath(getRequest())); if (LOGGER.isLoggable(Level.INFO)) { MediaType mediaType = getRequest().getEntity().getMediaType(); LOGGER.info("PUT file: mimetype=" + mediaType + ", path=" + directory.getAbsolutePath()); } return RESTUtils.handleBinUpload(getAttribute("template") + "." + MEDIATYPE_FTL_EXTENSION, directory, false, getRequest()); } catch (IOException e) { throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e); } }
getResponse().setStatus(Status.SUCCESS_ACCEPTED); MediaType mediaType = getRequest().getEntity().getMediaType(); if(LOGGER.isLoggable(Level.INFO)) LOGGER.info("PUT file, mimetype: " + mediaType );
MediaType type = getRequest().getEntity().getMediaType(); if ( type != null ) {
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings().contains( Encoding.FREEMARKER)) { final TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); if (this.dataModel == null) { representation.setDataModel(request, response); } else { representation.setDataModel(this.dataModel); } response.setEntity(representation); } }
if (representation != null) { request.getClientInfo().getAcceptedMediaTypes().add( new Preference<MediaType>(representation.getMediaType()));
new Preference<MediaType>( representation.getMediaType() ) );
final MediaType mediaType = getInlineContent().getMediaType(); String type = null;
final TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), response.getEntity() .getMediaType());
add(new Preference<MediaType>(representation.getMediaType()));
@Override public Object upload(Context context, Request request, Response response, List<FileItem> files) throws ResourceException { // NEXUS-4151: Do not accept upload/deploy requests with media type (Content-Type) of // "application/x-www-form-urlencoded", since ad 1, it's wrong, ad 2, we do know // Jetty's Request object "eats" up it's body to parse request parameters, invoked // way earlier in security filters if (request.isEntityAvailable()) { MediaType mt = request.getEntity().getMediaType(); if (mt != null && MediaType.APPLICATION_WWW_FORM.isCompatible(mt)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Content-type of \"" + mt.toString() + "\" is not acceptable for uploads!"); } } try { final ResourceStoreRequest req = getResourceStoreRequest(request); for (FileItem fileItem : files) { getResourceStore(request).storeItem(req, fileItem.getInputStream(), null); } } catch (Exception t) { handleException(request, response, t); } return null; }
MediaType mt = request.getEntity().getMediaType();