List of usage examples for org.springframework.http MediaType APPLICATION_XML
MediaType APPLICATION_XML
To view the source code for org.springframework.http MediaType APPLICATION_XML.
Click Source Link
From source file:org.artifactory.webapp.servlet.RepoFilter.java
@SuppressWarnings("OverlyComplexMethod") private void execute(FilterChain chain, final HttpServletRequest request, HttpServletResponse response, String servletPath) throws IOException, ServletException { if (log.isDebugEnabled()) { log.debug("Entering request {}.", requestDebugString(request)); }// w w w. j a va 2s . c o m if (request.getRequestURI().endsWith("treebrowser")) { ArtifactoryRequest artifactoryRequest = new HttpArtifactoryRequest(request); request.setAttribute(ATTR_ARTIFACTORY_REPOSITORY_PATH, artifactoryRequest.getRepoPath()); request.setAttribute(ATTR_ARTIFACTORY_REQUEST_PROPERTIES, artifactoryRequest.getProperties()); } boolean repoRequest = servletPath != null && RequestUtils.isRepoRequest(request, true); if (repoRequest && servletPath.startsWith("/" + ArtifactoryRequest.LIST_BROWSING_PATH) && servletPath.endsWith("/")) { ArtifactoryRequest artifactoryRequest = new HttpArtifactoryRequest(request); String repoKey = artifactoryRequest.getRepoKey(); if (VirtualRepoDescriptor.GLOBAL_VIRTUAL_REPO_KEY.equals(repoKey) && ConstantValues.disableGlobalRepoAccess.getBoolean()) { // The global /repo is disabled. Cannot be used here, returning 403! String msg = "Accessing the global virtual repository /repo is disabled!"; log.warn(msg); response.sendError(HttpStatus.SC_FORBIDDEN, msg); return; } doRepoListing(request, response, servletPath, artifactoryRequest); return; } String method = request.getMethod().toLowerCase().intern(); if (repoRequest) { ArtifactoryRequest artifactoryRequest = new HttpArtifactoryRequest(request); //Handle upload and download requests ArtifactoryResponse artifactoryResponse = new HttpArtifactoryResponse(response); if (artifactoryRequest.isDirectoryRequest() && isGetOrHeadRequest(method)) { //Check that this is not a recursive call if (artifactoryRequest.isRecursive()) { String msg = "Recursive call detected for '" + request + "'. Returning nothing."; artifactoryResponse.sendError(HttpStatus.SC_NOT_FOUND, msg, log); return; } log.debug("Serving a directory get request."); String repoKey = artifactoryRequest.getRepoKey(); if (VirtualRepoDescriptor.GLOBAL_VIRTUAL_REPO_KEY.equals(repoKey) && ConstantValues.disableGlobalRepoAccess.getBoolean()) { // The global /repo is disabled. Cannot be used here, returning 403! String msg = "Accessing the global virtual repository /repo is disabled!"; log.warn(msg); response.sendError(HttpStatus.SC_FORBIDDEN, msg); return; } doRepoListing(request, response, servletPath, artifactoryRequest); return; } try { initRequestContext(method, artifactoryRequest, artifactoryResponse); if (isGetOrHeadRequest(method)) { /** * Do not check for this parameter when not performing a get/head request so that the container * doesn't try to read the parameters and verify the size of the form in case of an upload */ if (artifactoryRequest.getParameter(ArtifactRestConstants.TRACE_PARAM) != null) { //Re-init the context with the trace logging response artifactoryResponse = new TraceLoggingResponse(artifactoryResponse); initRequestContext(method, artifactoryRequest, artifactoryResponse); } // TODO: Should we return 405 Method not allowed for head request on properties: // TODO: For now the HEAD request will ignore this properties query param if (artifactoryRequest.getParameter(ArtifactRestConstants.PROPERTIES_PARAM) != null) { //Set the response to return only the properties of the item in json format artifactoryResponse.setPropertiesMediaType(MediaType.APPLICATION_JSON.toString()); } if (artifactoryRequest.getParameter(ArtifactRestConstants.PROPERTIES_XML_PARAM) != null) { //Set the response to return only the properties of the item in json format artifactoryResponse.setPropertiesMediaType(MediaType.APPLICATION_XML.toString()); } doDownload(request, response, method, artifactoryRequest, artifactoryResponse); return; } if ("put".equals(method)) { doUpload(artifactoryRequest, artifactoryResponse); return; } doWebDavMethod(request, response, method, artifactoryRequest, artifactoryResponse); } finally { RepoRequests.destroy(); } } else if (!response.isCommitted()) { // Webdav request not on repository, return 403 if (RequestUtils.isWebdavRequest(request)) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); if (log.isDebugEnabled()) { log.debug("Received webdav request on " + servletPath + " which is not a repository!\n" + "Returning " + HttpServletResponse.SC_FORBIDDEN); } } else { // TODO: [by dan] this is a workaround for the Git LFS bug in 0.5.1 - see RTFACT-7587 remove this ugly // TODO: hack when we decide we can drop support for versions < 0.5.2 or when Jersey is updated above 2.0 chain.doFilter(wrapRequestIfNeeded(request), response); } } if (log.isDebugEnabled()) { log.debug("Exiting request " + requestDebugString(request)); } }
From source file:org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.java
public static String getSPMetadata(MockMvc mockMvc, String subdomain) throws Exception { return mockMvc .perform(get("/saml/metadata").accept(MediaType.APPLICATION_XML).header(HOST, hasText(subdomain) ? subdomain + ".localhost" : "localhost")) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); }
From source file:org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.java
public static String getIDPMetaData(MockMvc mockMvc, String subdomain) throws Exception { return mockMvc .perform(get("/saml/idp/metadata").accept(MediaType.APPLICATION_XML).header(HOST, hasText(subdomain) ? subdomain + ".localhost" : "localhost")) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); }
From source file:org.fao.geonet.api.GlobalExceptionController.java
/** * * @param request the HTTP request object. * @return true if the content type is allowed to have a body when returning an error to the client, false if the * response should contain an empty body. *///from www. j av a2 s.c o m private boolean contentTypeNeedsBody(HttpServletRequest request) { boolean needsBody; List<MediaType> requestMediaTypes = resolveMediaTypes(new ServletWebRequest(request)); Set<MediaType> allowedContentTypes = Sets.newHashSet(MediaType.APPLICATION_XML, MediaType.APPLICATION_XHTML_XML, MediaType.APPLICATION_JSON); needsBody = !Collections.disjoint(allowedContentTypes, requestMediaTypes); return needsBody; }
From source file:org.glytoucan.web.controller.GlycanController.java
@RequestMapping(value = "/{accessionNumber}/image", method = RequestMethod.GET, produces = { MediaType.IMAGE_PNG_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.IMAGE_JPEG_VALUE }) @ApiOperation(value = "Retrieves glycan image by accession number", response = Byte[].class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 400, message = "Illegal argument"), @ApiResponse(code = 404, message = "Glycan does not exist"), @ApiResponse(code = 500, message = "Internal Server Error") }) public @ResponseBody ResponseEntity<byte[]> getGlycanImage( @ApiParam(required = true, value = "id of the glycan") @PathVariable("accessionNumber") String accessionNumber, @ApiParam(required = false, value = "format of the the glycan image", defaultValue = "png") @RequestParam("format") String format, @ApiParam(required = false, value = "notation to use to generate the image", defaultValue = "cfg") @RequestParam("notation") String notation, @ApiParam(required = false, value = "style of the image", defaultValue = "compact") @RequestParam("style") String style) throws Exception { HashMap<String, Object> data = new HashMap<String, Object>(); data.put(GlycanClientQuerySpec.IMAGE_FORMAT, format); data.put(GlycanClientQuerySpec.IMAGE_NOTATION, notation); data.put(GlycanClientQuerySpec.IMAGE_STYLE, style); data.put(GlycanClientQuerySpec.ID, accessionNumber); byte[] bytes = gtcClient.getImage(data); HttpHeaders headers = new HttpHeaders(); if (format == null || format.equalsIgnoreCase("png")) { headers.setContentType(MediaType.IMAGE_PNG); } else if (format.equalsIgnoreCase("svg")) { headers.setContentType(MediaType.APPLICATION_XML); } else if (format.equalsIgnoreCase("jpg") || format.equalsIgnoreCase("jpeg")) { headers.setContentType(MediaType.IMAGE_JPEG); }/*from w w w .j av a2s . co m*/ int noOfDays = 3650; // 10 years Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, noOfDays); Date date = calendar.getTime(); headers.setExpires(date.getTime()); logger.debug("expires on :>" + date.getTime() + "<"); return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK); }
From source file:org.glytoucan.web.controller.GlycanController.java
@RequestMapping(value = "/image/glycan", method = RequestMethod.POST, consumes = { "application/xml", "application/json" }, produces = { MediaType.IMAGE_PNG_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.IMAGE_JPEG_VALUE }) @ApiOperation(value = "Retrieves glycan image by accession number", response = Byte[].class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 400, message = "Illegal argument"), @ApiResponse(code = 404, message = "Glycan does not exist"), @ApiResponse(code = 415, message = "Media type is not supported"), @ApiResponse(code = 500, message = "Internal Server Error") }) public @ResponseBody ResponseEntity<byte[]> getGlycanImageByStructure( @RequestBody(required = true) @ApiParam(required = true, value = "Glycan") @Valid GlycanInput glycan, @ApiParam(required = false, value = "format of the the glycan image", defaultValue = "png") @RequestParam("format") String format, @ApiParam(required = false, value = "notation to use to generate the image", defaultValue = "cfg") @RequestParam("notation") String notation, @ApiParam(required = false, value = "style of the image", defaultValue = "compact") @RequestParam("style") String style) throws Exception { Sugar sugarStructure = importParseValidate(glycan); if (sugarStructure == null) { throw new IllegalArgumentException("Structure cannot be imported"); }/*from w w w. j a v a2 s . c o m*/ String exportedStructure; // export into GlycoCT try { exportedStructure = StructureParserValidator.exportStructure(sugarStructure); } catch (Exception e) { throw new IllegalArgumentException("Cannot export into common encoding: " + e.getMessage()); } logger.debug(exportedStructure); byte[] bytes = imageGenerator.getImage(exportedStructure, format, notation, style); HttpHeaders headers = new HttpHeaders(); if (format == null || format.equalsIgnoreCase("png")) { headers.setContentType(MediaType.IMAGE_PNG); } else if (format.equalsIgnoreCase("svg")) { headers.setContentType(MediaType.APPLICATION_XML); } else if (format.equalsIgnoreCase("jpg") || format.equalsIgnoreCase("jpeg")) { headers.setContentType(MediaType.IMAGE_JPEG); } return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK); }
From source file:org.infoscoop.api.oauth2.provider.ISOAuth2ExceptionRenderer.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void writeWithMessageConverters(Object returnValue, HttpInputMessage inputMessage, HttpOutputMessage outputMessage, HttpStatus status, HttpServletRequest request) throws IOException, HttpMediaTypeNotAcceptableException { log.info(request.getRemoteAddr() + " " + returnValue + " " + status.value()); Class<?> returnValueType = returnValue.getClass(); List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>(); String fileType = request.getPathInfo(); MediaType acceptedMediaType = MediaType.APPLICATION_JSON; if (fileType.substring(fileType.lastIndexOf(".") + 1).equals("xml")) acceptedMediaType = MediaType.APPLICATION_XML; for (HttpMessageConverter messageConverter : messageConverters) { if (messageConverter.canWrite(returnValueType, acceptedMediaType)) { messageConverter.write(returnValue, acceptedMediaType, outputMessage); if (log.isDebugEnabled()) { MediaType contentType = outputMessage.getHeaders().getContentType(); if (contentType == null) { contentType = acceptedMediaType; }/*from ww w . j a v a2 s.co m*/ log.debug("Written [" + returnValue + "] as \"" + contentType + "\" using [" + messageConverter + "]"); } return; } } for (HttpMessageConverter messageConverter : messageConverters) { allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes()); } throw new HttpMediaTypeNotAcceptableException(allSupportedMediaTypes); }
From source file:org.openmhealth.dsu.controller.EndUserControllerIntegrationTests.java
@Test public void registerUserShouldReturnUnsupportedMediaTypeOnNonJsonContentType() throws Exception { mockMvc.perform(post(REGISTER_USER_URI).contentType(MediaType.APPLICATION_XML)) .andExpect(status().isUnsupportedMediaType()); }
From source file:org.opentestsystem.shared.trapi.TrClient.java
private HttpHeaders getHttpHeaders(TrApiContentType contentType) { HttpHeaders headers = new HttpHeaders(); if (contentType.equals(TrApiContentType.XML)) { headers.setContentType(MediaType.APPLICATION_XML); } else if (contentType.equals(TrApiContentType.JSON)) { headers.setContentType(MediaType.APPLICATION_JSON); } else {//from w w w. ja v a 2 s .c om throw new IllegalArgumentException("Supported content type is xml or json"); } return headers; }
From source file:org.springframework.xd.dirt.rest.ModulesControllerIntegrationTests.java
@Test public void testDisplayNonExistingJobConfiguration() throws Exception { mockMvc.perform(get("/modules/job/not_exists/definition").accept(MediaType.APPLICATION_XML)) .andExpect(status().isNotFound()); }