本文整理汇总了Java中com.sun.jersey.spi.container.ContainerResponse.getEntity方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerResponse.getEntity方法的具体用法?Java ContainerResponse.getEntity怎么用?Java ContainerResponse.getEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.spi.container.ContainerResponse
的用法示例。
在下文中一共展示了ContainerResponse.getEntity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import com.sun.jersey.spi.container.ContainerResponse; //导入方法依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
Collection<Object> contentTypes = response.getHttpHeaders().get("Content-Type");
//LOGGER.debug("content types {}", contentTypes);
if (null != contentTypes) {
for (Object contentType : contentTypes) {
if (contentType.equals(APPLICATION_X_PROTOBUF_TYPE) && !shouldSkipWrapping(response.getEntity())) {
LOGGER.debug("Content type is x-protobuf, wrap response entity");
ResponseCodeEntityWrapper<Object> wrapper = new ResponseCodeEntityWrapper<>(response.getStatus(), response.getEntity());
response.setEntity(wrapper, response.getEntityType());
break;
}
}
}
return response;
}
示例2: addRequestIdToResponse
import com.sun.jersey.spi.container.ContainerResponse; //导入方法依赖的package包/类
/**
* Private helper that adds the request-id to the response payload.
* @param response
*/
private void addRequestIdToResponse(ContainerResponse response) {
// The request-id to be injected in the response
String requestId = StaashRequestContext.getRequestId();
// The key response attributes
int status = response.getStatus();
MediaType mediaType = response.getMediaType();
if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
String message = (String)response.getEntity();
JsonObject json = new JsonObject(message);
json.putString("request-id", requestId);
Response newJerseyResponse = Response.status(status).type(mediaType).entity(json.toString()).build();
response.setResponse(newJerseyResponse);
}
// Add the request id to the response regardless of the media type,
// this allows non json responses to have a request id in the response
response.getHttpHeaders().add("x-nflx-staash-request-id", requestId);
}
示例3: filter
import com.sun.jersey.spi.container.ContainerResponse; //导入方法依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request,
ContainerResponse response) {
Object entity = response.getEntity();
if (entity instanceof BaseEntity) {
Date lastModified = getLastModificationTime((BaseEntity) entity);
if (lastModified != null) {
ResponseBuilder b = request.evaluatePreconditions(lastModified);
if (b != null) {
response.setResponse(b.build());
} else {
MultivaluedMap<String, Object> headers = response.getHttpHeaders();
headers.putSingle(HttpHeaders.LAST_MODIFIED, lastModified);
}
}
}
return response;
}
示例4: filter
import com.sun.jersey.spi.container.ContainerResponse; //导入方法依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest containerRequest, ContainerResponse containerResponse) {
if (null == containerResponse.getEntity())
return containerResponse;
if (!containerResponse.getEntity().getClass().isAnnotationPresent(XmlRootElement.class))
return containerResponse;
XmlRootElement annotation = containerResponse.getEntity().getClass().getAnnotation(XmlRootElement.class);
String name = annotation.name();
if (null == name || name.equals("##default"))
return containerResponse;
StringWriter sw = new StringWriter();
try {
JAXBContext c = getJAXBContext(containerResponse.getEntity().getClass());
Marshaller marshaller = c.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
marshaller.marshal(containerResponse.getEntity(), sw);
String xml = sw.toString();
xml = xml.replace(String.format("<%s>", name), String.format("<%s xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\">", name));
// DL: removed this log line, as it was spewing very large messages when user has several buckets
// LOG.debug(xml);
containerResponse.setEntity(xml);
LOG.debug("http headers: " + containerResponse.getHttpHeaders());
// set the content-length otherwise the server seems to set the Content-Encoding to chunked which some
// clients don't like
MultivaluedMap<String, Object> requestHeaders = containerResponse.getHttpHeaders();
requestHeaders.remove(HttpHeaders.CONTENT_LENGTH);
requestHeaders.add(HttpHeaders.CONTENT_LENGTH, xml.length());
} catch (JAXBException e) {
LOG.error("error formatting xml", e);
ResponseBuilder responseBuilder = Response.serverError();
responseBuilder.entity(e.getMessage());
throw new WebApplicationException(responseBuilder.build());
}
return containerResponse;
}
示例5: filter
import com.sun.jersey.spi.container.ContainerResponse; //导入方法依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest req,
ContainerResponse res) {
Object entity = res.getEntity();
if (entity instanceof Paginated) {
Paginated<?> p = (Paginated) entity;
if (p.isPaginated()) {
insertLinks(p, req, res);
insertRangeHeader(p, res);
}
}
return res;
}