use of org.springframework.http.MediaType in project webofneeds by researchstudio-sat.
the class WonEtagHelper method fromEtagValue.
/**
* Returns a WonEtagHelper if the specified string is a valid ETAG, combining
* [VERSION] {[DELIMITER] [MEDIA-TYPE]} (curly brackets inticate 'optional')
* Returns null if the specified etagValue is null or not valid.
* @param etagValue
* @return
*/
public static WonEtagHelper fromEtagValue(String etagValue) {
if (etagValue == null)
return null;
etagValue = etagValue.trim();
if (etagValue.startsWith("W/")) {
logger.debug("weak etag matching is not supported, cannot " + "process: " + etagValue);
return null;
}
if (!etagValue.startsWith("\"")) {
logger.debug("etag must start with '\"', cannot process: " + etagValue);
return null;
}
if (!etagValue.endsWith("\"")) {
logger.debug("etag must end with '\"', cannot process: " + etagValue);
return null;
}
int index = etagValue.indexOf(VERSION_MEDIATYPE_DELIMITER);
if (index == -1) {
// delimiter not found. Assume only version
return new WonEtagHelper(etagValue.substring(1, etagValue.length() - 1), null);
}
MediaType mt = null;
try {
mt = MediaType.parseMediaType(etagValue.substring(index, etagValue.length() - 1));
} catch (Exception e) {
logger.debug("not a valid media type in etag value, cannot process: " + etagValue);
// not a valid media type
return null;
}
return new WonEtagHelper(etagValue.substring(1, index), mt);
}
use of org.springframework.http.MediaType in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method readAttachment.
@RequestMapping(value = "${uri.path.data.attachment}/{identifier}", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads", "*/*" })
public ResponseEntity<Dataset> readAttachment(HttpServletRequest request, @PathVariable(value = "identifier") String identifier) {
logger.debug("readAttachment() called");
URI attachmentURI = uriService.createAttachmentURIForId(identifier);
DataWithEtag<Dataset> data = linkedDataService.getDatasetForUri(attachmentURI, null);
if (!data.isNotFound()) {
HttpHeaders headers = new HttpHeaders();
addCORSHeader(headers);
String mimeTypeOfResponse = RdfUtils.findFirst(data.getData(), model -> {
String content = getObjectOfPropertyAsString(model, CNT.BYTES);
if (content == null)
return null;
return getObjectOfPropertyAsString(model, WONMSG.CONTENT_TYPE);
});
if (mimeTypeOfResponse != null) {
// we found a base64 encoded attachment, we obtained its contentType, so we set
// it as the
// contentType of the response.
Set<MediaType> producibleMediaTypes = new HashSet<>();
producibleMediaTypes.add(MediaType.valueOf(mimeTypeOfResponse));
request.setAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, producibleMediaTypes);
}
return new ResponseEntity<>(data.getData(), headers, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
use of org.springframework.http.MediaType in project gocd by gocd.
the class BasicProcessingFilterEntryPoint method getAcceptHeader.
private ArrayList<String> getAcceptHeader(ServletRequest request) {
ArrayList<String> headers = new ArrayList<>();
if (request instanceof HttpServletRequest) {
String accept = ((HttpServletRequest) request).getHeader("Accept");
if (accept != null) {
List<MediaType> mediaTypes = MediaType.parseMediaTypes(accept);
for (MediaType mediaType : mediaTypes) {
String type = mediaType.getType() + "/" + mediaType.getSubtype();
headers.add(type);
}
}
}
return headers;
}
use of org.springframework.http.MediaType in project cas by apereo.
the class JsonUtils method render.
/**
* Render model and view.
*
* @param model the model
* @param response the response
*/
@SneakyThrows
public static void render(final Object model, final HttpServletResponse response) {
final MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
jsonConverter.setPrettyPrint(true);
final MediaType jsonMimeType = MediaType.APPLICATION_JSON;
jsonConverter.write(model, jsonMimeType, new ServletServerHttpResponse(response));
}
use of org.springframework.http.MediaType in project coffeenet-starter by coffeenet.
the class IntegrationCoffeeNetWebSecurityConfigurerAdapter method mediaTypeRequestMatcher.
private static MediaTypeRequestMatcher mediaTypeRequestMatcher(final ContentNegotiationStrategy contentNegotiationStrategy) {
ContentNegotiationStrategy negotiationStrategy = contentNegotiationStrategy;
if (negotiationStrategy == null) {
negotiationStrategy = new HeaderContentNegotiationStrategy();
}
MediaTypeRequestMatcher matcher = new MediaTypeRequestMatcher(negotiationStrategy, APPLICATION_XHTML_XML, new MediaType("image", "*"), TEXT_HTML, TEXT_PLAIN);
matcher.setIgnoredMediaTypes(singleton(ALL));
return matcher;
}
Aggregations