本文整理汇总了Java中com.sun.jersey.core.header.LinkHeader类的典型用法代码示例。如果您正苦于以下问题:Java LinkHeader类的具体用法?Java LinkHeader怎么用?Java LinkHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LinkHeader类属于com.sun.jersey.core.header包,在下文中一共展示了LinkHeader类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAll
import com.sun.jersey.core.header.LinkHeader; //导入依赖的package包/类
/**
* Goes over all GitHub pages and return all pages union.
*
* @param webResource of first page
* @param entityType type of entities
* @return union
*/
protected <T> List<T> getAll(WebResource webResource, Class<T[]> entityType, ClientFilter filter)
{
List<T> result = new LinkedList<T>();
WebResource cursor = webResource;
do
{
if (filter != null)
{
cursor.addFilter(filter);
}
WebResource.Builder builder = cursor.accept(MediaType.APPLICATION_JSON_TYPE);
ClientResponse clientResponse = builder.get(ClientResponse.class);
if (clientResponse.getStatus() < 300)
{
result.addAll(Arrays.asList(clientResponse.getEntity(entityType)));
LinkHeaders linkHeaders = getLinks(clientResponse);
LinkHeader nextLink = linkHeaders.getLink("next");
URI nextPage = nextLink != null ? nextLink.getUri() : null;
cursor = nextPage != null ? client.resource(nextPage) : null;
}
else
{
throw new UniformInterfaceException(clientResponse);
}
}
while (cursor != null);
return result;
}
示例2: loadLinks
import com.sun.jersey.core.header.LinkHeader; //导入依赖的package包/类
protected List<Link> loadLinks(ClientResponse response, E entity) {
ArrayList<Link> links = new ArrayList<Link>();
//if there's a location, we'll consider it a "self" link.
if (response.getLocation() != null) {
links.add(new Link(Rel.SELF, new org.gedcomx.common.URI(response.getLocation().toString())));
}
//initialize links with link headers
List<String> linkHeaders = response.getHeaders().get("Link");
if (linkHeaders != null) {
for (String header : linkHeaders) {
LinkHeader lh = LinkHeader.valueOf(header);
for (String rel : lh.getRel()) {
Link link = new Link(rel, lh.getUri() == null ? null : org.gedcomx.common.URI.create(lh.getUri().toString()));
link.setTemplate(lh.getParams().getFirst("template"));
link.setTitle(lh.getParams().getFirst("title"));
link.setAccept(lh.getParams().getFirst("accept"));
link.setAllow(lh.getParams().getFirst("allow"));
link.setHreflang(lh.getParams().getFirst("hreflang"));
link.setType(lh.getParams().getFirst("type"));
links.add(link);
}
}
}
//load the links from the main data element
SupportsLinks mainElement = getMainDataElement();
if (mainElement != null && mainElement.getLinks() != null) {
links.addAll(mainElement.getLinks());
}
//load links at the document level
if(entity != mainElement && entity instanceof SupportsLinks && ((SupportsLinks) entity).getLinks() != null) {
links.addAll(((SupportsLinks)entity).getLinks());
}
return links;
}
示例3: addLink
import com.sun.jersey.core.header.LinkHeader; //导入依赖的package包/类
protected void addLink(String rel, Pagination p, ContainerRequest req,
ContainerResponse res) {
if (p.getPage()>= 0 && p.getLimit() >= 0) {
URI uri = req.getRequestUriBuilder()
.replaceQueryParam(RESTConstants.LIMIT, p.getLimit())
.replaceQueryParam(RESTConstants.PAGE, p.getPage())
.build();
MediaType type = res.getMediaType();
LinkHeader header = LinkHeader.uri(uri).type(type).rel(rel).build();
res.getHttpHeaders().add(LINK_HEADER, header.toString());
}
}