本文整理汇总了Java中javax.ws.rs.core.HttpHeaders.getHeaderString方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.getHeaderString方法的具体用法?Java HttpHeaders.getHeaderString怎么用?Java HttpHeaders.getHeaderString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.getHeaderString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AuthorizationService
import javax.ws.rs.core.HttpHeaders; //导入方法依赖的package包/类
public AuthorizationService(@Context HttpHeaders headers) {
authorization = false;
String token = headers.getHeaderString("Authorization");
if (token != null) {
try {
Session session = HibernateUtil.getSessionFactory().openSession();
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<User> criteria = builder.createQuery(User.class);
Root<User> root = criteria.from(User.class);
criteria.select(root);
criteria.where(builder.equal(root.get(User_.token), token));
authenticate = session.createQuery(criteria).getSingleResult();
if (authenticate != null)
authorization = true;
} catch (Exception e) {
}
}
}
示例2: getCorrelationId
import javax.ws.rs.core.HttpHeaders; //导入方法依赖的package包/类
@Override
public String getCorrelationId() {
HttpHeaders headers = ResteasyProviderFactory.getContextData(HttpHeaders.class);
String correlationId;
if (headers != null) {
correlationId = headers.getHeaderString(headerName);
if (correlationId != null) {
return correlationId;
}
}
// Fall back to MDC to support beadledom-jaxrs 1.0. Retrieving from the headers is preferred.
correlationId = MDC.get(mdcName);
return correlationId;
}
示例3: toExternalURI
import javax.ws.rs.core.HttpHeaders; //导入方法依赖的package包/类
private URI toExternalURI(final URI uri, final HttpHeaders headers) {
final String host = headers.getHeaderString("Host");
final String protocol = headers.getHeaderString("X-Forwarded-Proto");
final String context = headers.getHeaderString("context");
return URI.create(protocol + "://" + host + "/" + context + uri.getPath());
}
示例4: downloadFile
import javax.ws.rs.core.HttpHeaders; //导入方法依赖的package包/类
/**
* Respond with the binary data
*
* @param stagingUuid
* @param filename
* @return
*/
@Override
public Response downloadFile(HttpHeaders headers, String stagingUuid, String filepath)
{
final StagingFile stagingFile = getStagingFile(stagingUuid);
ensureFileExists(stagingFile, filepath);
try
{
final String etag = headers.getHeaderString(HttpHeaders.IF_NONE_MATCH);
if( etag != null )
{
String md5Checksum = fileSystemService.getMD5Checksum(stagingFile, filepath);
String quotedChecksum = "\"" + md5Checksum + "\"";
if( Objects.equals(etag, quotedChecksum) )
{
return Response.notModified(quotedChecksum).build();
}
}
final String modifiedSince = headers.getHeaderString(HttpHeaders.IF_MODIFIED_SINCE);
if( modifiedSince != null )
{
final Date lastModified = new Date(fileSystemService.lastModified(stagingFile, filepath));
if( Objects.equals(modifiedSince, DateUtil.formatDate(lastModified)) )
{
return Response.notModified().build();
}
}
final InputStream input = fileSystemService.read(stagingFile, filepath);
final String mimeType = mimeService.getMimeTypeForFilename(filepath);
return Response.ok().type(mimeType).entity(new StreamingOutput()
{
@Override
public void write(OutputStream output) throws IOException, WebApplicationException
{
try
{
ByteStreams.copy(input, output);
}
finally
{
Closeables.close(input, false);
}
}
}).build();
}
catch( IOException e )
{
throw Throwables.propagate(e);
}
}
示例5: getFile
import javax.ws.rs.core.HttpHeaders; //导入方法依赖的package包/类
@Override
public Response getFile(HttpHeaders headers, String uuid, String filepath)
{
final StagingFile stagingFile = getStagingFile(uuid);
ensureFileExists(stagingFile, filepath);
try
{
final String etag = headers.getHeaderString(HttpHeaders.IF_NONE_MATCH);
if( etag != null )
{
String md5Checksum = fileSystemService.getMD5Checksum(stagingFile, filepath);
String quotedChecksum = "\"" + md5Checksum + "\"";
if( Objects.equals(etag, quotedChecksum) )
{
return Response.notModified(quotedChecksum).build();
}
}
final String modifiedSince = headers.getHeaderString(HttpHeaders.IF_MODIFIED_SINCE);
if( modifiedSince != null )
{
final Date lastModified = new Date(fileSystemService.lastModified(stagingFile, filepath));
if( Objects.equals(modifiedSince, DateUtil.formatDate(lastModified)) )
{
return Response.notModified().build();
}
}
final InputStream input = fileSystemService.read(stagingFile, filepath);
final ResponseBuilder responseBuilder = makeResponseHeaders(uuid, filepath);
return responseBuilder.entity(new StreamingOutput()
{
@Override
public void write(OutputStream output) throws IOException, WebApplicationException
{
try
{
ByteStreams.copy(input, output);
}
finally
{
Closeables.close(input, false);
}
}
}).build();
}
catch( IOException e )
{
throw Throwables.propagate(e);
}
}