本文整理汇总了Java中javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.APPLICATION_JSON_TYPE属性的具体用法?Java MediaType.APPLICATION_JSON_TYPE怎么用?Java MediaType.APPLICATION_JSON_TYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.ws.rs.core.MediaType
的用法示例。
在下文中一共展示了MediaType.APPLICATION_JSON_TYPE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get_GetOneBreweryWithParameter_ThroughLdApi
@Test
public void get_GetOneBreweryWithParameter_ThroughLdApi() {
// Arrange
TupleQueryResultBuilder builder =
new TupleQueryResultBuilder("naam", "sinds", "fte", "oprichting", "plaats").resultSet(
DBEERPEDIA.BROUWTOREN_NAME, DBEERPEDIA.BROUWTOREN_YEAR_OF_FOUNDATION,
DBEERPEDIA.BROUWTOREN_FTE, DBEERPEDIA.BROUWTOREN_DATE_OF_FOUNDATION,
DBEERPEDIA.BROUWTOREN_PLACE).resultSet(DBEERPEDIA.MAXIMUS_NAME,
DBEERPEDIA.MAXIMUS_YEAR_OF_FOUNDATION, DBEERPEDIA.MAXIMUS_FTE,
DBEERPEDIA.MAXIMUS_DATE_OF_FOUNDATION, DBEERPEDIA.MAXIMUS_PLACE);
SparqlHttpStub.returnTuple(builder);
MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
// Act
Response response = target.path("/dbp/ld/v1/tuple-brewery").queryParam("id",
DBEERPEDIA.MAXIMUS_NAME).request().accept(mediaType).get();
// Assert
assertThat(response.getStatus(), equalTo(Status.OK.getStatusCode()));
assertThat(response.getMediaType(), equalTo(mediaType));
assertThat(response.getLength(), greaterThan(0));
}
示例2: createMessage
/**
* 受信/送信メッセージEntityを作成する.
* @param uriInfo URL情報
* @param reader リクエストボディ
* @return response情報
*/
protected Response createMessage(UriInfo uriInfo,
Reader reader) {
// response用URLに__ctlを追加する
UriInfo resUriInfo = PersoniumCoreUtils.createUriInfo(uriInfo, 2, "__ctl");
// Entityの作成を Producerに依頼
OEntityWrapper oew = getOEntityWrapper(reader, odataResource, CtlSchema.getEdmDataServicesForMessage().build());
EntityResponse res = getOdataProducer().createEntity(getEntitySetName(), oew);
// レスポンスボディを生成する
OEntity ent = res.getEntity();
MediaType outputFormat = MediaType.APPLICATION_JSON_TYPE;
List<MediaType> contentTypes = new ArrayList<MediaType>();
contentTypes.add(MediaType.APPLICATION_JSON_TYPE);
String key = AbstractODataResource.replaceDummyKeyToNull(ent.getEntityKey().toKeyString());
String responseStr = renderEntityResponse(resUriInfo, res, "json", contentTypes);
// 制御コードのエスケープ処理
responseStr = escapeResponsebody(responseStr);
ResponseBuilder rb = getPostResponseBuilder(ent, outputFormat, responseStr, resUriInfo, key);
return rb.build();
}
示例3: decideOutputFormatFromHeaderValues
/**
* Acceptヘッダの指定から出力フォーマットを決定する.
* @param format Acceptヘッダの指定値
* @return 出力フォーマット("application/json" or "application/atom+xml")
*/
private MediaType decideOutputFormatFromHeaderValues(String acceptHeaderValue) {
MediaType mediaType = null;
StringTokenizer st = new StringTokenizer(acceptHeaderValue, ",");
while (st.hasMoreTokens()) {
String accept = truncateAfterSemicolon(st.nextToken());
if (isAcceptXml(accept)) {
mediaType = MediaType.APPLICATION_ATOM_XML_TYPE;
} else if (isAcceptJson(accept)) {
if (mediaType == null) {
mediaType = MediaType.APPLICATION_JSON_TYPE;
}
} else {
throw PersoniumCoreException.OData.UNSUPPORTED_MEDIA_TYPE.params(acceptHeaderValue);
}
}
return mediaType;
}
示例4: getAppropriateMediaType
/**
* Determines the appropriate media type based on what is requested. If wildcard
* use JSON.
*
* @return media type appropriate for request
*/
private MediaType getAppropriateMediaType() {
final List<MediaType> acceptableMediaTypes = headers.getAcceptableMediaTypes();
for (final MediaType mediaType : acceptableMediaTypes) {
if (mediaType.equals(MediaType.WILDCARD_TYPE)) {
return MediaType.APPLICATION_JSON_TYPE;
} else if (SUPPORTED_MEDIA_TYPES.contains(mediaType)) {
return mediaType;
}
}
return MediaType.APPLICATION_JSON_TYPE;
}
示例5: decideOutputFormatFromQueryValue
/**
* クエリでの指定($format)から出力フォーマットを決定する.
* @param format $formatの指定値
* @return 出力フォーマット("application/json" or "application/atom+xml")
*/
private MediaType decideOutputFormatFromQueryValue(String format) {
MediaType mediaType = null;
if (format.equals(FORMAT_ATOM)) {
// $formatの指定がatomである場合
mediaType = MediaType.APPLICATION_ATOM_XML_TYPE;
} else if (format.equals(FORMAT_JSON)) {
mediaType = MediaType.APPLICATION_JSON_TYPE;
} else {
throw PersoniumCoreException.OData.FORMAT_INVALID_ERROR.params(format);
}
return mediaType;
}
示例6: checkCellListResponse
/**
* CellのJson形式のリストのフォーマットチェック.
* @param response DcResponseオブジェクト
* @param contentType レスポンスのContentType
*/
public final void checkCellListResponse(PersoniumResponse response, MediaType contentType) {
// Cell作成のレスポンスチェック
// 200になることを確認
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
// DataServiceVersionのチェック
Header[] resDsvHeaders = response.getResponseHeaders(ODataConstants.Headers.DATA_SERVICE_VERSION);
assertEquals(1, resDsvHeaders.length);
assertEquals("2.0", resDsvHeaders[0].getValue());
// ContentTypeのチェック
Header[] resContentTypeHeaders = response.getResponseHeaders(HttpHeaders.CONTENT_TYPE);
assertEquals(1, resContentTypeHeaders.length);
String value = resContentTypeHeaders[0].getValue();
String[] values = value.split(";");
assertEquals(contentType.toString(), values[0]);
if (contentType == MediaType.APPLICATION_JSON_TYPE) {
// レスポンスボディのJsonもチェックが必要
checkCellListResponse(response.bodyAsJson());
} else if (contentType == MediaType.APPLICATION_ATOM_XML_TYPE) {
// TODO レスポンスボディのチェック
fail("Not Implemented.");
// checkCellXML(response.bodyAsXml());
}
}
示例7: checkDomainListResponse
/**
* DomainのJson形式のリストのフォーマットチェック.
* @param response DcResponseオブジェクト
* @param contentType レスポンスのContentType
*/
public final void checkDomainListResponse(PersoniumResponse response, MediaType contentType) {
// Cell取得のレスポンスチェック
// 200になることを確認
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
// DataServiceVersionのチェック
Header[] resDsvHeaders = response.getResponseHeaders(ODataConstants.Headers.DATA_SERVICE_VERSION);
assertEquals(1, resDsvHeaders.length);
assertEquals("2.0", resDsvHeaders[0].getValue());
// ContentTypeのチェック
Header[] resContentTypeHeaders = response.getResponseHeaders(HttpHeaders.CONTENT_TYPE);
assertEquals(1, resContentTypeHeaders.length);
String value = resContentTypeHeaders[0].getValue();
String[] values = value.split(";");
assertEquals(contentType.toString(), values[0]);
if (contentType == MediaType.APPLICATION_JSON_TYPE) {
// レスポンスボディのJsonもチェックが必要
checkDomainListResponse(response.bodyAsJson());
} else if (contentType == MediaType.APPLICATION_ATOM_XML_TYPE) {
// レスポンスボディのチェック
fail("Not Implemented.");
// checkCellXML(response.bodyAsXml());
}
}
示例8: RudderClient
public RudderClient(String url) {
this.client = new RestClient(Application.RUDDER, url,
MediaType.APPLICATION_JSON_TYPE);
}
示例9: JsonTupleEntityWriter
JsonTupleEntityWriter() {
super(MediaType.APPLICATION_JSON_TYPE);
}
示例10: JsonLdGraphEntityWriter
JsonLdGraphEntityWriter() {
super(RDFFormat.JSONLD, MediaTypes.LDJSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
}
示例11: testSingleAppKill
@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();
}
示例12: testSingleAppKillInvalidState
@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();
}
示例13: testAppMove
@Test(timeout = 90000)
public void testAppMove() throws Exception {
client().addFilter(new LoggingFilter(System.out));
boolean isCapacityScheduler =
rm.getResourceScheduler() instanceof CapacityScheduler;
// default root queue allows anyone to have admin acl
CapacitySchedulerConfiguration csconf =
new CapacitySchedulerConfiguration();
String[] queues = { "default", "test" };
csconf.setQueues("root", queues);
csconf.setCapacity("root.default", 50.0f);
csconf.setCapacity("root.test", 50.0f);
csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
csconf.setAcl("root.test", QueueACL.ADMINISTER_QUEUE, "someuser");
rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());
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);
AppQueue targetQueue = new AppQueue("test");
Object entity;
if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
entity = appQueueToJSON(targetQueue);
} else {
entity = targetQueue;
}
ClientResponse response =
this
.constructWebResource("apps", app.getApplicationId().toString(),
"queue").entity(entity, contentType).accept(mediaType)
.put(ClientResponse.class);
if (!isAuthenticationEnabled()) {
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
continue;
}
assertEquals(Status.OK, response.getClientResponseStatus());
String expectedQueue = "test";
if(!isCapacityScheduler) {
expectedQueue = "root.test";
}
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
verifyAppQueueJson(response, expectedQueue);
} else {
verifyAppQueueXML(response, expectedQueue);
}
Assert.assertEquals(expectedQueue, app.getQueue());
// check unauthorized
app = rm.submitApp(CONTAINER_MB, "", "someuser");
amNodeManager.nodeHeartbeat(true);
response =
this
.constructWebResource("apps", app.getApplicationId().toString(),
"queue").entity(entity, contentType).accept(mediaType)
.put(ClientResponse.class);
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
if(isCapacityScheduler) {
Assert.assertEquals("default", app.getQueue());
}
else {
Assert.assertEquals("root.someuser", app.getQueue());
}
}
}
rm.stop();
}