當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaType.equals方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.MediaType.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaType.equals方法的具體用法?Java MediaType.equals怎麽用?Java MediaType.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.MediaType的用法示例。


在下文中一共展示了MediaType.equals方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isWriteable

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@Override
public boolean isWriteable(final Class<?> type, final Type genericType,
        final Annotation[] annotations, final MediaType mediaType) {
    LOGGER.debug(
            "Checking to see if we can serialize type: {} to mimeType: {}",
            type.getName(), mediaType.toString());
    if (!DefaultRdfStream.class.isAssignableFrom(type)) {
        return false;
    }
    if (mediaType.equals(TEXT_HTML_TYPE)
            || (mediaType.getType().equals("application") && mediaType
                    .getSubtype().equals("html"))) {
        LOGGER.debug("Was asked for an HTML mimeType, returning false.");
        return false;
    }
    LOGGER.debug("Assuming that this is an attempt to retrieve RDF, returning true.");
    return true;
}
 
開發者ID:duraspace,項目名稱:lambdora,代碼行數:19,代碼來源:RdfStreamProvider.java

示例2: writeTo

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@Override
public void writeTo(Model t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
		MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
		throws IOException, WebApplicationException {
	
	Lang lang = null;
	
	if(mediaType.equals(KRFormat.N3_TYPE))
		lang = Lang.N3;
	else if(mediaType.equals(KRFormat.N_TRIPLE_TYPE))
		lang = Lang.NTRIPLES;
	else if(mediaType.equals(KRFormat.RDF_JSON_TYPE))
		lang = Lang.RDFJSON;
	else if(mediaType.equals(new MediaType("application", "json-ld")))
		lang = Lang.JSONLD;
	else lang = Lang.TURTLE;
	
	RDFDataMgr.write(entityStream, t, lang);
	
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:21,代碼來源:ModelWriter.java

示例3: getAppropriateMediaType

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
/**
 * 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;

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:20,代碼來源:JsonExceptionMapper.java

示例4: isWriteable

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
  // TODO condition
  return mediaType.equals(MediaType.APPLICATION_JSON_TYPE);
}
 
開發者ID:openknowledge,項目名稱:reactive-jax-rs,代碼行數:6,代碼來源:PublisherMessageBodyWriter.java

示例5: isReadable

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
  // TODO add condition
  return mediaType.equals(MediaType.APPLICATION_JSON_TYPE);
}
 
開發者ID:openknowledge,項目名稱:reactive-jax-rs,代碼行數:6,代碼來源:PublisherMessageBodyReader.java

示例6: isReadable

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return type.getAnnotation(XmlRootElement.class) != null && mediaType.equals(MediaType.APPLICATION_XML_TYPE);
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:5,代碼來源:XmlNamespaceIgnoringMessageBodyReader.java

示例7: testSingleAppKill

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:78,代碼來源:TestRMWebServicesAppsModification.java

示例8: testSingleAppKillInvalidState

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:45,代碼來源:TestRMWebServicesAppsModification.java

示例9: testAppMove

import javax.ws.rs.core.MediaType; //導入方法依賴的package包/類
@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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:80,代碼來源:TestRMWebServicesAppsModification.java


注:本文中的javax.ws.rs.core.MediaType.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。