本文整理汇总了Java中org.jboss.resteasy.core.Headers类的典型用法代码示例。如果您正苦于以下问题:Java Headers类的具体用法?Java Headers怎么用?Java Headers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Headers类属于org.jboss.resteasy.core包,在下文中一共展示了Headers类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntity
import org.jboss.resteasy.core.Headers; //导入依赖的package包/类
public static <T> T getEntity(ClientMessage msg, Class<T> type, Type genericType, ResteasyProviderFactory factory) {
int size = msg.getBodySize();
if (size <= 0)
return null;
byte[] body = new byte[size];
msg.getBodyBuffer().readBytes(body);
String contentType = msg.getStringProperty(HttpHeaderProperty.CONTENT_TYPE);
if (contentType == null) {
throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity");
}
MediaType ct = MediaType.valueOf(contentType);
MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct);
if (reader == null) {
throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType);
}
Providers current = ResteasyProviderFactory.getContextData(Providers.class);
ResteasyProviderFactory.pushContext(Providers.class, factory);
try {
return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body));
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
ResteasyProviderFactory.popContextData(Providers.class);
if (current != null)
ResteasyProviderFactory.pushContext(Providers.class, current);
}
}