javax.ws.rs.core.Response.notAcceptable()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中javax.ws.rs.core.Response.notAcceptable方法的一些代码示例,展示了Response.notAcceptable的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.notAcceptable方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:notAcceptable

Response.notAcceptable介绍

[英]Create a new ResponseBuilder for a not acceptable response.
[中]为不可接受的响应创建新的ResponseBuilder。

代码示例

代码示例来源:origin: jersey/jersey

@GET
public Response content() {
  if (content.isEmpty()) {
    return Response.noContent().build();
  }
  final Variant variant = request.selectVariant(supportedVariants);
  if (variant == null) {
    return Response.notAcceptable(supportedVariants).build();
  } else {
    return Response.ok(content, variant.getMediaType()).build();
  }
}

代码示例来源:origin: apache/incubator-pinot

@GET
@Produces({"application/hocon", "text/x-java-properties", "text/plain"})
@Path("/v2/tables/{tableName}")
@ApiOperation("Displays the configuration of a table")
public Response readTableConfiguration(@PathParam("tableName") String tableName, @Context Request request) {
 TableConfig offlineTableConfig =
   _resourceManager.getTableConfig(tableName, CommonConstants.Helix.TableType.OFFLINE);
 TableConfig realtimeTableConfig =
   _resourceManager.getTableConfig(tableName, CommonConstants.Helix.TableType.REALTIME);
 Schema tableSchema = _resourceManager.getTableSchema(tableName);
 if (offlineTableConfig == null && realtimeTableConfig == null) {
  return Response.status(Response.Status.NOT_FOUND).build();
 }
 CombinedConfig combinedConfig = new CombinedConfig(offlineTableConfig, realtimeTableConfig, tableSchema);
 String serializedConfig;
 List<Variant> variants =
   Variant.mediaTypes(APPLICATION_HOCON, TEXT_JAVA_PROPERTIES, MediaType.TEXT_PLAIN_TYPE).build();
 Variant variant = request.selectVariant(variants);
 if (variant == null) {
  return Response.notAcceptable(variants).build();
 } else if (APPLICATION_HOCON.equals(variant.getMediaType()) || MediaType.TEXT_PLAIN_TYPE
   .equals(variant.getMediaType())) {
  serializedConfig = Serializer.serializeToString(combinedConfig);
 } else if (TEXT_JAVA_PROPERTIES.equals(variant.getMediaType())) {
  serializedConfig = Serializer.serializeToPropertiesString(combinedConfig);
 } else {
  return Response.notAcceptable(variants).build();
 }
 return Response.ok(serializedConfig, variant).header("Content-Disposition", "inline").build();
}

代码示例来源:origin: com.sun.jersey/jersey-server

Variant v = request.selectVariant(vl);
if (v==null) {
  return Response.notAcceptable(vl).build();

代码示例来源:origin: resteasy/Resteasy

/**
* FIXME Comment this
*
* @param mediaType media type
* @return image reader
*/
public static ImageReader getImageReaderByMediaType(MediaType mediaType)
{
 Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType(mediaType.toString());
 ImageReader reader = null;
 while (readers.hasNext())
 {
   reader = (ImageReader) readers.next();
 }
 if (reader == null)
 {
   String[] availableTypes = ImageIO.getReaderMIMETypes();
   LogMessages.LOGGER.readerNotFound(mediaType, availableTypes);
   List<Variant> variants = ProviderHelper.getAvailableVariants(availableTypes);
   Response response = Response.notAcceptable(variants).status(Status.NOT_ACCEPTABLE).build();
   throw new WebApplicationException(response);
 }
 return reader;
}

代码示例来源:origin: schema-repo/schema-repo

protected Renderer getRenderer(String mediaType) {
 // browsers usually send more than one type separated by comma, and each type may have parameters after semicolon
 Renderer r;
 for (String singleMediaType : (mediaType == null || mediaType.isEmpty() ? WILDCARD : mediaType).split(", ?")) {
  singleMediaType = singleMediaType.split(";", 2)[0];
  r = rendererByMediaType.get(WILDCARD.equals(singleMediaType) ? getDefaultMediaType() : singleMediaType);
  if (r != null) {
   logger.debug("Handling request with Accept: {} using {}", mediaType, r);
   return r;
  }
 }
 logger.warn("No renderer configured for any of media types requested: {}, responding with the error status", mediaType);
 throw new WebApplicationException(Response.notAcceptable(supportedMediaTypes)
   .entity(format("Unsupported value of 'Accept' header: %s (supported values are %s)", mediaType, rendererByMediaType.keySet()))
   .build());
}

代码示例来源:origin: org.schemarepo/schema-repo-server

protected Renderer getRenderer(String mediaType) {
 // browsers usually send more than one type separated by comma, and each type may have parameters after semicolon
 Renderer r;
 for (String singleMediaType : (mediaType == null || mediaType.isEmpty() ? WILDCARD : mediaType).split(", ?")) {
  singleMediaType = singleMediaType.split(";", 2)[0];
  r = rendererByMediaType.get(WILDCARD.equals(singleMediaType) ? getDefaultMediaType() : singleMediaType);
  if (r != null) {
   logger.debug("Handling request with Accept: {} using {}", mediaType, r);
   return r;
  }
 }
 logger.warn("No renderer configured for any of media types requested: {}, responding with the error status", mediaType);
 throw new WebApplicationException(Response.notAcceptable(supportedMediaTypes)
   .entity(format("Unsupported value of 'Accept' header: %s (supported values are %s)", mediaType, rendererByMediaType.keySet()))
   .build());
}

代码示例来源:origin: eclipse/winery

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addInstanceState(InstanceStateApiData json) {
  String state = json.state;
  if (StringUtils.isEmpty(state)) {
    return Response.notAcceptable(null).build();
  }
  // InstanceState does not override "equals()", therefore we have to manually check for existance
  List<InstanceState> instanceStates = this.instanceStates.getInstanceState();
  Iterator<InstanceState> iterator = instanceStates.iterator();
  boolean found = false;
  while (iterator.hasNext() && !found) {
    if (iterator.next().getState().equals(state)) {
      found = true;
    }
  }
  if (found) {
    // no error, just return
    return Response.noContent().build();
  }
  InstanceState instanceState = new InstanceState();
  instanceState.setState(state);
  instanceStates.add(instanceState);
  return RestUtils.persist(this.typeResource);
}

代码示例来源:origin: org.jboss.resteasy/resteasy-core

/**
* FIXME Comment this
*
* @param mediaType media type
* @return image reader
*/
public static ImageReader getImageReaderByMediaType(MediaType mediaType)
{
 Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType(mediaType.toString());
 ImageReader reader = null;
 while (readers.hasNext())
 {
   reader = (ImageReader) readers.next();
 }
 if (reader == null)
 {
   String[] availableTypes = ImageIO.getReaderMIMETypes();
   LogMessages.LOGGER.readerNotFound(mediaType, availableTypes);
   List<Variant> variants = ProviderHelper.getAvailableVariants(availableTypes);
   Response response = Response.notAcceptable(variants).status(Status.NOT_ACCEPTABLE).build();
   throw new WebApplicationException(response);
 }
 return reader;
}

代码示例来源:origin: org.jboss.resteasy/resteasy-jaxrs-20

/**
* FIXME Comment this
*
* @param mediaType
* @return
*/
public static ImageReader getImageReaderByMediaType(MediaType mediaType)
{
 Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType(mediaType.toString());
 ImageReader reader = null;
 while (readers.hasNext())
 {
   reader = (ImageReader) readers.next();
 }
 if (reader == null)
 {
   String[] availableTypes = ImageIO.getReaderMIMETypes();
   LogMessages.LOGGER.readerNotFound(mediaType, availableTypes);
   List<Variant> variants = ProviderHelper.getAvailableVariants(availableTypes);
   Response response = Response.notAcceptable(variants).status(Status.NOT_ACCEPTABLE).build();
   throw new WebApplicationException(response);
 }
 return reader;
}

代码示例来源:origin: com.sun.jersey/jersey-bundle

Variant v = request.selectVariant(vl);
if (v==null) {
  return Response.notAcceptable(vl).build();

代码示例来源:origin: AtomGraph/Core

/**
 * Returns response builder for SPARQL result set.
 * 
 * @param resultSet result set
 * @param variants supported response variants
 * @return response builder
 */    
public ResponseBuilder getResponseBuilder(ResultSetRewindable resultSet, List<Variant> variants)
{
  if (resultSet == null) throw new IllegalArgumentException("ResultSetRewindable cannot be null");
  if (variants == null) throw new IllegalArgumentException("List<Variant> cannot be null");
  
  Variant variant = getRequest().selectVariant(variants);
  if (variant == null)
  {
    if (log.isTraceEnabled()) log.trace("Requested Variant {} is not on the list of acceptable Response Variants: {}", variant, variants);
    return javax.ws.rs.core.Response.notAcceptable(variants);
  }
  resultSet.reset();
  EntityTag entityTag = getEntityTag(resultSet, variant);
  resultSet.reset(); // ResultSet needs to be rewinded back to the beginning
  return getResponseBuilder(resultSet, entityTag, variant);
}

代码示例来源:origin: jersey/jersey-1.x

Variant v = request.selectVariant(vl);
if (v==null) {
  return Response.notAcceptable(vl).build();

代码示例来源:origin: org.fcrepo/fcrepo-http-api

return builder.type(acceptablePlainText).entity(location.toString()).build();
  return notAcceptable(mediaTypes(TEXT_PLAIN_TYPE).build()).build();
} else if (prefer.getReturn().getValue().equals("minimal")) {
  return builder.build();

代码示例来源:origin: org.aktin/broker-server

protected Response getRequest(int requestId, List<MediaType> accept) throws SQLException, IOException, NotFoundException{
  MediaType[] available = getTypeManager().createMediaTypes(getBroker().getRequestTypes(requestId));
  if( available.length == 0 ){
    throw new NotFoundException();
  }
  // find acceptable request definition
  RequestConverter rc = getTypeManager().buildConverterChain(accept, Arrays.asList(available));

  if( rc == null ){
    // no acceptable response type available
    return Response.notAcceptable(Variant.mediaTypes(available).build()).build();			
  }else{
    Reader def = getBroker().getRequestDefinition(requestId, rc.getConsumedType());
    // transform
    def = rc.transform(def);
    // output using UTF-8. The HTTP default charset ISO-8859-1 has some missing characters like e.g Euro sign.
    return Response.ok(def, MediaType.valueOf(rc.getProducedType()).withCharset("UTF-8")).build();
  }
}

代码示例来源:origin: niclashoyer/neo4j-sparql-extension

return Response.notAcceptable(acceptable).build();

代码示例来源:origin: org.fcrepo/fcrepo-http-api

return notAcceptable(VariantListBuilder.newInstance().mediaTypes(mediaType).build()).build();

代码示例来源:origin: org.gatein.management/gatein-management-rest

if (contentType == null)
  return Response.notAcceptable(Variant.mediaTypes(ContentTypeUtils.mediaTypes()).build()).build();

相关文章