Java Code Examples for javax.ws.rs.core.MediaType.getType()

The following are Jave code examples for showing how to use getType() of the javax.ws.rs.core.MediaType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: minijax   File: MockHttpServletResponse.java   Source Code and License Vote up 6 votes
@Override
public void setCharacterEncoding(final String charset) {
    final String type;
    final String subType;
    final Map<String, String> parameters;

    final MediaType prevMediaType = getMediaType();
    if (prevMediaType != null) {
        type = prevMediaType.getType();
        subType = prevMediaType.getSubtype();
        parameters = new HashMap<>(prevMediaType.getParameters());
    } else {
        type = "text";
        subType = "html";
        parameters = new HashMap<>();
    }

    parameters.put(MediaType.CHARSET_PARAMETER, charset);
    setContentType(new MediaType(type, subType, parameters).toString());
}
 
Example 2
Project: rest.vertx   File: MediaTypeHelper.java   Source Code and License Vote up 5 votes
public static String getKey(MediaType mediaType) {

		if (mediaType == null) {
			return MediaType.WILDCARD;
		}

		return mediaType.getType() + "/" + mediaType.getSubtype(); // key does not contain any charset
	}
 
Example 3
Project: neo4j-sparql-extension-yars   File: GraphStore.java   Source Code and License Vote up 5 votes
/**
 * Returns RDF data from a graph in the repository.
 *
 * @see RDFStreamingOutput
 * @param req JAX-RS {@link Request} object
 * @param def the "default" query parameter
 * @param graphString the "graph" query parameter
 * @return RDF data as HTTP response
 */
private Response handleGet(
		Request req,
		String def,
		String graphString) {
	// select matching MIME-Type for response based on HTTP headers
	final Variant variant = req.selectVariant(rdfResultVariants);
	final MediaType mt = variant.getMediaType();
	final String mtstr = mt.getType() + "/" + mt.getSubtype();
	final RDFFormat format = getRDFFormat(mtstr);
	StreamingOutput stream;
	RepositoryConnection conn = null;
	try {
		// return data as RDF stream
		conn = getConnection();
		if (graphString != null) {
			Resource ctx = vf.createURI(graphString);
			if (conn.size(ctx) == 0) {
				return Response.status(Response.Status.NOT_FOUND).build();
			}
			stream = new RDFStreamingOutput(conn, format, ctx);
		} else {
			stream = new RDFStreamingOutput(conn, format);
		}
	} catch (RepositoryException ex) {
		// server error
		close(conn, ex);
		throw new WebApplicationException(ex);
	}
	return Response.ok(stream).build();
}
 
Example 4
Project: ontonethub   File: ModelWriter.java   Source Code and License Vote up 4 votes
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
	String mediaTypeString = mediaType.getType()+'/'+mediaType.getSubtype();
	return Model.class.isAssignableFrom(type) && supportedMediaTypes.contains(mediaTypeString);
}