Java Code Examples for javax.ws.rs.core.MediaType#APPLICATION_XML_TYPE
The following examples show how to use
javax.ws.rs.core.MediaType#APPLICATION_XML_TYPE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestImplTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testMultipleVariantsBestMatch() { metadata.putSingle(HttpHeaders.ACCEPT, "application/xml"); metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en-us"); metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "gzip;q=1.0, compress"); List<Variant> list = new ArrayList<>(); list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "gzip")); Variant var2 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "gzip"); list.add(var2); Variant var3 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), null); list.add(var3); assertSame(var2, new RequestImpl(m).selectVariant(list)); list.clear(); list.add(var3); assertSame(var3, new RequestImpl(m).selectVariant(list)); }
Example 2
Source File: TransactionalStorage.java From iaf with Apache License 2.0 | 6 votes |
private Response buildResponse(String msg, String fileName) { MediaType type = MediaType.TEXT_PLAIN_TYPE; String fileNameExtension = "txt"; if (StringUtils.isEmpty(msg)) { throw new ApiException("message not found"); } else { if(msg.startsWith("<")) { type = MediaType.APPLICATION_XML_TYPE; fileNameExtension = "xml"; } else if(msg.startsWith("{") || msg.startsWith("[")) { type = MediaType.APPLICATION_JSON_TYPE; fileNameExtension = "json"; } } return Response.status(Response.Status.OK) .type(type) .entity(msg) .header("Content-Disposition", "attachment; filename=\"msg-"+fileName+"."+fileNameExtension+"\"") .build(); }
Example 3
Source File: AccessDeniedExceptionHandler.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public Response toResponse(AccessDeniedException e) { //There are a few jax-rs resources that generate HTML content, and we want the //default web-container error handler pages to get used in those cases. if (headers.getAcceptableMediaTypes().contains(MediaType.TEXT_HTML_TYPE)) { try { response.sendError(403, e.getMessage()); return null; //the error page handles the response, so no need to return a response } catch (IOException ex) { LOG.error("Error displaying error page", ex); } } Response.Status errorStatus = Response.Status.FORBIDDEN; SLIPrincipal principal = null ; String message = e.getMessage(); if (SecurityContextHolder.getContext().getAuthentication() != null) { principal = (SLIPrincipal)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); LOG.warn("Access has been denied to user: {}",principal ); } else { LOG.warn("Access has been denied to user for being incorrectly associated"); } LOG.warn("Cause: {}", e.getMessage()); MediaType errorType = MediaType.APPLICATION_JSON_TYPE; if(this.headers.getMediaType() == MediaType.APPLICATION_XML_TYPE) { errorType = MediaType.APPLICATION_XML_TYPE; } return Response.status(errorStatus).entity(new ErrorResponse(errorStatus.getStatusCode(), errorStatus.getReasonPhrase(), "Access DENIED: " + e.getMessage())).type(errorType).build(); }
Example 4
Source File: SseEventBuilder.java From cxf with Apache License 2.0 | 5 votes |
private MediaType guessMediaType(String dataString) { if (dataString != null) { if (dataString.startsWith("<")) { return MediaType.APPLICATION_XML_TYPE; } if (dataString.startsWith("{")) { return MediaType.APPLICATION_JSON_TYPE; } } return MediaType.WILDCARD_TYPE; }
Example 5
Source File: SMIMEResource.java From resteasy-examples with Apache License 2.0 | 5 votes |
@Path("encrypted") @GET public EnvelopedOutput getEncrypted() { System.out.println("HERE!!!!!"); Customer cust = new Customer(); cust.setName("Bill"); EnvelopedOutput output = new EnvelopedOutput(cust, MediaType.APPLICATION_XML_TYPE); output.setCertificate(certificate); return output; }
Example 6
Source File: RequestImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testMultipleVariantsSingleMatch() { metadata.putSingle(HttpHeaders.ACCEPT, "application/xml"); metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en"); metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "gzip"); List<Variant> list = new ArrayList<>(); list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8")); list.add(new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("es"), "utf-8")); Variant var3 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "gzip"); list.add(var3); assertSame(var3, new RequestImpl(m).selectVariant(list)); }
Example 7
Source File: Util.java From swagger-petstore with Apache License 2.0 | 5 votes |
public static MediaType getMediaType(final RequestContext request) { MediaType outputType = MediaType.APPLICATION_JSON_TYPE; final List<String> accept = request.getHeaders().get("Accept"); String responseMediaType = ""; if (accept != null && accept.get(0) != null) { responseMediaType = accept.get(0); } if (MediaType.APPLICATION_XML.equals(responseMediaType)) { return MediaType.APPLICATION_XML_TYPE; } boolean isJsonOK = false; boolean isYamlOK = false; final MediaType yamlMediaType = new MediaType(APPLICATION, YAML); for (final MediaType mediaType : request.getAcceptableMediaTypes()) { if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { isJsonOK = true; } else if (mediaType.equals(yamlMediaType)) { isYamlOK = true; } } if (isYamlOK && !isJsonOK) { outputType = yamlMediaType; } return outputType; }
Example 8
Source File: MediaTypeHeaderProvider.java From cxf with Apache License 2.0 | 5 votes |
private static MediaType handleMediaTypeWithoutSubtype(String mType) { if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) { String mTypeNext = mType.length() == 1 ? "" : mType.substring(1).trim(); boolean mTypeNextEmpty = StringUtils.isEmpty(mTypeNext); if (mTypeNextEmpty || mTypeNext.startsWith(";")) { if (!mTypeNextEmpty) { Map<String, String> parameters = new LinkedHashMap<>(); StringTokenizer st = new StringTokenizer(mType.substring(2).trim(), ";"); while (st.hasMoreTokens()) { addParameter(parameters, st.nextToken()); } return new MediaType(MediaType.MEDIA_TYPE_WILDCARD, MediaType.MEDIA_TYPE_WILDCARD, parameters); } return MediaType.WILDCARD_TYPE; } } Message message = PhaseInterceptorChain.getCurrentMessage(); if (message != null && !MessageUtils.getContextualBoolean(message, STRICT_MEDIA_TYPE_CHECK, false)) { MediaType mt = null; if (mType.equals(MediaType.TEXT_PLAIN_TYPE.getType())) { mt = MediaType.TEXT_PLAIN_TYPE; } else if (mType.equals(MediaType.APPLICATION_XML_TYPE.getSubtype())) { mt = MediaType.APPLICATION_XML_TYPE; } else { mt = MediaType.WILDCARD_TYPE; } LOG.fine("Converting a malformed media type '" + mType + "' to '" + typeToString(mt) + "'"); return mt; } throw new IllegalArgumentException("Media type separator is missing"); }
Example 9
Source File: AbstractTemplate.java From redpipe with Apache License 2.0 | 5 votes |
public static MediaType parseMediaType(String extension) { // FIXME: bigger list, and override in config if(extension.equalsIgnoreCase("html")) return MediaType.TEXT_HTML_TYPE; if(extension.equalsIgnoreCase("xml")) return MediaType.APPLICATION_XML_TYPE; if(extension.equalsIgnoreCase("txt")) return MediaType.TEXT_PLAIN_TYPE; if(extension.equalsIgnoreCase("json")) return MediaType.APPLICATION_JSON_TYPE; System.err.println("Unknown extension type: "+extension); return MediaType.APPLICATION_OCTET_STREAM_TYPE; }
Example 10
Source File: ResteasyViolationExceptionMapper.java From quarkus with Apache License 2.0 | 5 votes |
private MediaType getAcceptMediaType(List<MediaType> accept) { Iterator<MediaType> it = accept.iterator(); while (it.hasNext()) { MediaType mt = it.next(); if (MediaType.APPLICATION_XML_TYPE.getType().equals(mt.getType()) && MediaType.APPLICATION_XML_TYPE.getSubtype().equals(mt.getSubtype())) { return MediaType.APPLICATION_XML_TYPE; } if (MediaType.APPLICATION_JSON_TYPE.getType().equals(mt.getType()) && MediaType.APPLICATION_JSON_TYPE.getSubtype().equals(mt.getSubtype())) { return MediaType.APPLICATION_JSON_TYPE; } } return null; }
Example 11
Source File: FHIRProviderUtil.java From FHIR with Apache License 2.0 | 5 votes |
public static MediaType getMediaType(String acceptHeader) { MediaType mediaType = null; try { mediaType = FHIRMediaType.valueOf(acceptHeader); } catch (IllegalArgumentException e) { // ignore } if (mediaType != null) { MediaType outMediaType = null; if (mediaType.isCompatible(FHIRMediaType.APPLICATION_FHIR_JSON_TYPE)) { outMediaType = FHIRMediaType.APPLICATION_FHIR_JSON_TYPE; } else if (mediaType.isCompatible(FHIRMediaType.APPLICATION_JSON_TYPE)) { outMediaType = MediaType.APPLICATION_JSON_TYPE; } else if (mediaType.isCompatible(FHIRMediaType.APPLICATION_FHIR_XML_TYPE)) { outMediaType = FHIRMediaType.APPLICATION_FHIR_XML_TYPE; } else if (mediaType.isCompatible(FHIRMediaType.APPLICATION_XML_TYPE)) { outMediaType = MediaType.APPLICATION_XML_TYPE; } else { outMediaType = FHIRMediaType.APPLICATION_FHIR_JSON_TYPE; } // Need to get the charset setting from the acceptHeader if there if (mediaType.getParameters() != null && mediaType.getParameters().get("charset") != null) { outMediaType = outMediaType.withCharset(mediaType.getParameters().get("charset")); } return outMediaType; } // default return FHIRMediaType.APPLICATION_FHIR_JSON_TYPE; }
Example 12
Source File: MCRContentXMLWriter.java From mycore with GNU General Public License v3.0 | 4 votes |
@Override protected MediaType getTransfomerFormat() { return MediaType.APPLICATION_XML_TYPE; }
Example 13
Source File: TestRMWebServicesAppsModification.java From big-c with Apache License 2.0 | 4 votes |
@Test(timeout = 120000) public void testSingleAppKill() throws Exception { rm.start(); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048); String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }; MediaType[] contentTypes = { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE }; for (String mediaType : mediaTypes) { for (MediaType contentType : contentTypes) { RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName); amNodeManager.nodeHeartbeat(true); AppState targetState = new AppState(YarnApplicationState.KILLED.toString()); Object entity; if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) { entity = appStateToJSON(targetState); } else { entity = targetState; } ClientResponse response = this .constructWebResource("apps", app.getApplicationId().toString(), "state").entity(entity, contentType).accept(mediaType) .put(ClientResponse.class); if (!isAuthenticationEnabled()) { assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus()); continue; } assertEquals(Status.ACCEPTED, response.getClientResponseStatus()); if (mediaType.equals(MediaType.APPLICATION_JSON)) { verifyAppStateJson(response, RMAppState.FINAL_SAVING, RMAppState.KILLED, RMAppState.KILLING, RMAppState.ACCEPTED); } else { verifyAppStateXML(response, RMAppState.FINAL_SAVING, RMAppState.KILLED, RMAppState.KILLING, RMAppState.ACCEPTED); } String locationHeaderValue = response.getHeaders().getFirst(HttpHeaders.LOCATION); Client c = Client.create(); WebResource tmp = c.resource(locationHeaderValue); if (isAuthenticationEnabled()) { tmp = tmp.queryParam("user.name", webserviceUserName); } response = tmp.get(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); assertTrue(locationHeaderValue.endsWith("/ws/v1/cluster/apps/" + app.getApplicationId().toString() + "/state")); while (true) { Thread.sleep(100); response = this .constructWebResource("apps", app.getApplicationId().toString(), "state").accept(mediaType) .entity(entity, contentType).put(ClientResponse.class); assertTrue((response.getClientResponseStatus() == Status.ACCEPTED) || (response.getClientResponseStatus() == Status.OK)); if (response.getClientResponseStatus() == Status.OK) { assertEquals(RMAppState.KILLED, app.getState()); if (mediaType.equals(MediaType.APPLICATION_JSON)) { verifyAppStateJson(response, RMAppState.KILLED); } else { verifyAppStateXML(response, RMAppState.KILLED); } break; } } } } rm.stop(); }
Example 14
Source File: TestRMWebServicesAppsModification.java From hadoop with Apache License 2.0 | 4 votes |
@Test public void testSingleAppKillInvalidState() throws Exception { rm.start(); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048); String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }; MediaType[] contentTypes = { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE }; String[] targetStates = { YarnApplicationState.FINISHED.toString(), "blah" }; for (String mediaType : mediaTypes) { for (MediaType contentType : contentTypes) { for (String targetStateString : targetStates) { RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName); amNodeManager.nodeHeartbeat(true); ClientResponse response; AppState targetState = new AppState(targetStateString); Object entity; if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) { entity = appStateToJSON(targetState); } else { entity = targetState; } response = this .constructWebResource("apps", app.getApplicationId().toString(), "state") .entity(entity, contentType).accept(mediaType) .put(ClientResponse.class); if (!isAuthenticationEnabled()) { assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus()); continue; } assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); } } } rm.stop(); }
Example 15
Source File: TestApiContentInterface.java From entando-components with GNU Lesser General Public License v3.0 | 4 votes |
public void testCreateNewContentFromXml() throws Throwable { MediaType mediaType = MediaType.APPLICATION_XML_TYPE; this.testCreateNewContent(mediaType, "ALL4"); }
Example 16
Source File: Rest.java From hop with Apache License 2.0 | 4 votes |
public boolean init() { if ( super.init() ) { data.resultFieldName = environmentSubstitute( meta.getFieldName() ); data.resultCodeFieldName = environmentSubstitute( meta.getResultCodeFieldName() ); data.resultResponseFieldName = environmentSubstitute( meta.getResponseTimeFieldName() ); data.resultHeaderFieldName = environmentSubstitute( meta.getResponseHeaderFieldName() ); // get authentication settings once data.realProxyHost = environmentSubstitute( meta.getProxyHost() ); data.realProxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 ); data.realHttpLogin = environmentSubstitute( meta.getHttpLogin() ); data.realHttpPassword = Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( meta.getHttpPassword() ) ); if ( !meta.isDynamicMethod() ) { data.method = environmentSubstitute( meta.getMethod() ); if ( Utils.isEmpty( data.method ) ) { logError( BaseMessages.getString( PKG, "Rest.Error.MethodMissing" ) ); return false; } } data.trustStoreFile = environmentSubstitute( meta.getTrustStoreFile() ); data.trustStorePassword = environmentSubstitute( meta.getTrustStorePassword() ); String applicationType = Const.NVL( meta.getApplicationType(), "" ); if ( applicationType.equals( RestMeta.APPLICATION_TYPE_XML ) ) { data.mediaType = MediaType.APPLICATION_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_JSON ) ) { data.mediaType = MediaType.APPLICATION_JSON_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_OCTET_STREAM ) ) { data.mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_XHTML ) ) { data.mediaType = MediaType.APPLICATION_XHTML_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_FORM_URLENCODED ) ) { data.mediaType = MediaType.APPLICATION_FORM_URLENCODED_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_ATOM_XML ) ) { data.mediaType = MediaType.APPLICATION_ATOM_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_SVG_XML ) ) { data.mediaType = MediaType.APPLICATION_SVG_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_TEXT_XML ) ) { data.mediaType = MediaType.TEXT_XML_TYPE; } else { data.mediaType = MediaType.TEXT_PLAIN_TYPE; } try { setConfig(); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "Rest.Error.Config" ), e ); return false; } return true; } return false; }
Example 17
Source File: TestApiDataObjectInterface.java From entando-core with GNU Lesser General Public License v3.0 | 4 votes |
public void testGetXmlDataObject() throws Throwable { MediaType mediaType = MediaType.APPLICATION_XML_TYPE; this.testGetDataObject(mediaType, "admin", "ALL4", "it"); }
Example 18
Source File: Rest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (RestMeta) smi; data = (RestData) sdi; if ( super.init( smi, sdi ) ) { data.resultFieldName = environmentSubstitute( meta.getFieldName() ); data.resultCodeFieldName = environmentSubstitute( meta.getResultCodeFieldName() ); data.resultResponseFieldName = environmentSubstitute( meta.getResponseTimeFieldName() ); data.resultHeaderFieldName = environmentSubstitute( meta.getResponseHeaderFieldName() ); // get authentication settings once data.realProxyHost = environmentSubstitute( meta.getProxyHost() ); data.realProxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 ); data.realHttpLogin = environmentSubstitute( meta.getHttpLogin() ); data.realHttpPassword = Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( meta.getHttpPassword() ) ); if ( !meta.isDynamicMethod() ) { data.method = environmentSubstitute( meta.getMethod() ); if ( Utils.isEmpty( data.method ) ) { logError( BaseMessages.getString( PKG, "Rest.Error.MethodMissing" ) ); return false; } } data.trustStoreFile = environmentSubstitute( meta.getTrustStoreFile() ); data.trustStorePassword = environmentSubstitute( meta.getTrustStorePassword() ); String applicationType = Const.NVL( meta.getApplicationType(), "" ); if ( applicationType.equals( RestMeta.APPLICATION_TYPE_XML ) ) { data.mediaType = MediaType.APPLICATION_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_JSON ) ) { data.mediaType = MediaType.APPLICATION_JSON_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_OCTET_STREAM ) ) { data.mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_XHTML ) ) { data.mediaType = MediaType.APPLICATION_XHTML_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_FORM_URLENCODED ) ) { data.mediaType = MediaType.APPLICATION_FORM_URLENCODED_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_ATOM_XML ) ) { data.mediaType = MediaType.APPLICATION_ATOM_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_SVG_XML ) ) { data.mediaType = MediaType.APPLICATION_SVG_XML_TYPE; } else if ( applicationType.equals( RestMeta.APPLICATION_TYPE_TEXT_XML ) ) { data.mediaType = MediaType.TEXT_XML_TYPE; } else { data.mediaType = MediaType.TEXT_PLAIN_TYPE; } try { setConfig(); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "Rest.Error.Config" ), e ); return false; } return true; } return false; }
Example 19
Source File: TestApiI18nLabelInterface.java From entando-core with GNU Lesser General Public License v3.0 | 4 votes |
public void testGetXmlLabel() throws Throwable { MediaType mediaType = MediaType.APPLICATION_XML_TYPE; this.testGetLabel(mediaType, "admin", "PAGE_TITLE"); }
Example 20
Source File: TestApiI18nLabelInterface.java From entando-core with GNU Lesser General Public License v3.0 | 4 votes |
public void testCreateNewLabelFromXml() throws Throwable { MediaType mediaType = MediaType.APPLICATION_XML_TYPE; this.testCreateNewLabel(mediaType); }