本文整理汇总了Java中org.restlet.data.Header类的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Header类属于org.restlet.data包,在下文中一共展示了Header类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: pullData
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Pulls data from CloudStack API
*
* @return JSON string
* @throws IOException
*/
private String pullData() throws IOException {
logger.trace("Starting to pull data from provided URL");
// create connection
Client client = new Client(Protocol.HTTP);
ClientResource cr = new ClientResource(url);
Request req = cr.getRequest();
// now header
Series<Header> headerValue = new Series<Header>(Header.class);
req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);
headerValue.add("Accept", "application/json");
headerValue.add("Content-Type", "application/json");
// fire it up
cr.get(MediaType.APPLICATION_JSON);
Representation output = cr.getResponseEntity();
logger.trace("Successfully pulled data from provided URL");
// and return response data
return output.getText();
}
开发者ID:icclab,项目名称:cyclops-udr,代码行数:30,代码来源:CloudStackDownloader.java
示例2: getRequestHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* The request headers
*
* @return The request headers
*/
@SuppressWarnings("unchecked")
public Series<Header> getRequestHeaders()
{
if( requestHeaders == null )
{
ConcurrentMap<String, Object> attributes = getRequest().getAttributes();
requestHeaders = (Series<Header>) attributes.get( HeaderConstants.ATTRIBUTE_HEADERS );
if( requestHeaders == null )
{
requestHeaders = new Series<Header>( Header.class );
attributes.put( HeaderConstants.ATTRIBUTE_HEADERS, requestHeaders );
}
}
return requestHeaders;
}
开发者ID:tliron,项目名称:prudence,代码行数:21,代码来源:ConversationService.java
示例3: getResponseHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* The extra response headers
*
* @return The extra response headers
*/
@SuppressWarnings("unchecked")
public Series<Header> getResponseHeaders()
{
if( responseHeaders == null )
{
ConcurrentMap<String, Object> attributes = getResponse().getAttributes();
responseHeaders = (Series<Header>) attributes.get( HeaderConstants.ATTRIBUTE_HEADERS );
if( responseHeaders == null )
{
responseHeaders = new Series<Header>( Header.class );
attributes.put( HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders );
}
}
return responseHeaders;
}
开发者ID:tliron,项目名称:prudence,代码行数:21,代码来源:ConversationService.java
示例4: wrapLinkHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Creates a collection of link headers based on response headers.
*
* @param headers
* The response headers
* @return A collection of link headers
*/
public static Collection<LinkHeader> wrapLinkHeaders( Series<Header> headers )
{
Collection<LinkHeader> linkHeaders = new ArrayList<LinkHeader>();
for( Header header : headers )
{
if( header.getName().equalsIgnoreCase( HEADER_LINK ) )
{
try
{
LinkHeader linkHeader = new LinkHeaderReader( header.getValue(), headers ).readValue();
linkHeaders.add( linkHeader );
}
catch( IOException x )
{
Context.getCurrentLogger().log( Level.WARNING, "Error during " + HEADER_LINK + " header parsing. Header: " + header.getValue(), x );
}
}
}
return linkHeaders;
}
开发者ID:tliron,项目名称:prudence,代码行数:28,代码来源:LinkHeader.java
示例5: removeLinkHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Removes all link headers with the specified reference from the response
* headers.
*
* @param headers
* The response headers
* @param reference
* The reference
* @return True if removed
*/
public static boolean removeLinkHeaders( Series<Header> headers, String reference )
{
boolean removed = false;
for( Iterator<Header> i = headers.iterator(); i.hasNext(); )
{
Header header = i.next();
if( header.getName().equalsIgnoreCase( HEADER_LINK ) )
{
try
{
LinkHeader linkHeader = new LinkHeaderReader( header.getValue(), headers ).readValueOnlyReference();
if( linkHeader.getReference().equals( reference ) )
{
i.remove();
removed = true;
}
}
catch( IOException x )
{
Context.getCurrentLogger().log( Level.WARNING, "Error during " + HEADER_LINK + " header parsing. Header: " + header.getValue(), x );
}
}
}
return removed;
}
开发者ID:tliron,项目名称:prudence,代码行数:36,代码来源:LinkHeader.java
示例6: getResponseHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Gets the response headers, making sure to create them if they don't
* exist.
*
* @param response
* The response
* @return The headers
*/
public static Series<Header> getResponseHeaders( Response response )
{
ConcurrentMap<String, Object> attributes = response.getAttributes();
@SuppressWarnings("unchecked")
Series<Header> headers = (Series<Header>) attributes.get( HeaderConstants.ATTRIBUTE_HEADERS );
if( headers == null )
{
headers = new Series<Header>( Header.class );
@SuppressWarnings("unchecked")
Series<Header> existing = (Series<Header>) attributes.putIfAbsent( HeaderConstants.ATTRIBUTE_HEADERS, headers );
if( existing != null )
headers = existing;
}
return headers;
}
开发者ID:tliron,项目名称:prudence,代码行数:24,代码来源:RestletUtil.java
示例7: configureRestForm
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Configures REST HTTP Request Forms.
*
* @param message the HTTP message to setup
* @return the message configured HTTP headers.
*/
@SuppressWarnings("unchecked")
public static Series<Header> configureRestForm(Message message) {
ConcurrentMap<String, Object> attrs = message.getAttributes();
Series<Header> headers = (Series<Header>) attrs.get(HEADERS_KEY);
if (headers == null) {
headers = new Series<Header>(Header.class);
Series<Header> prev = (Series<Header>) attrs.putIfAbsent(HEADERS_KEY, headers);
if (prev != null)
headers = prev;
}
headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW_ALL_FROM_ORIGIN);
message.getCacheDirectives().add(CacheDirective.noCache());
return headers;
}
开发者ID:jpinho,项目名称:soaba,代码行数:24,代码来源:RestletServer.java
示例8: pullData
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Pull data from provided URL
* @param url
* @return output string or empty string
*/
private String pullData(String url){
try {
ClientResource cr = new ClientResource(url);
Request req = cr.getRequest();
// now header
Series<Header> headerValue = new Series<Header>(Header.class);
req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);
headerValue.add("Accept", "application/json");
headerValue.add("Content-Type", "application/json");
// fire it up
cr.get(MediaType.APPLICATION_JSON);
Representation output = cr.getResponseEntity();
// return null or received text
return (output == null) ? "" : output.getText();
} catch (Exception ignored) {
return "";
}
}
开发者ID:icclab,项目名称:cyclops-rc,代码行数:27,代码来源:Puller.java
示例9: pullData
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Pull data from provided URL
* @param url
* @return output string or empty string
*/
private String pullData(String url) throws IOException {
Client client = new Client(Protocol.HTTP);
ClientResource cr = new ClientResource(url);
Request req = cr.getRequest();
// now header
Series<Header> headerValue = new Series<Header>(Header.class);
req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);
headerValue.add("Accept", "application/json");
headerValue.add("Content-Type", "application/json");
// fire it up
cr.get(MediaType.APPLICATION_JSON);
Representation output = cr.getResponseEntity();
// return null or received text
return (output == null) ? "" : output.getText();
}
开发者ID:icclab,项目名称:cyclops-rc,代码行数:24,代码来源:McnPuller.java
示例10: pullData
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Pull data from provided URL
*
* @param url
* @return output string
*/
private String pullData(String url) throws IOException {
Client client = new Client(Protocol.HTTP);
ClientResource cr = new ClientResource(url);
Request req = cr.getRequest();
// now header
Series<Header> headerValue = new Series<Header>(Header.class);
req.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, headerValue);
headerValue.add("Accept", "application/json");
headerValue.add("Content-Type", "application/json");
// fire it up
cr.get(MediaType.APPLICATION_JSON);
Representation output = cr.getResponseEntity();
// and return response data
return output.getText();
}
开发者ID:icclab,项目名称:cyclops-rc,代码行数:25,代码来源:AccountingClient.java
示例11: getResponseHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Returns the modifiable list of response headers.
*
* @return The modifiable list of response headers.
*/
@Override
public Series<Header> getResponseHeaders()
{
final Series<Header> result = super.getResponseHeaders();
if( !responseHeadersAdded )
{
final HttpResponse httpResponse = getHttpResponse();
if( httpResponse != null )
{
final HttpFields headers = httpResponse.getHeaders();
if( headers != null )
{
for( HttpField header : headers )
result.add( header.getName(), header.getValue() );
}
}
responseHeadersAdded = true;
}
return result;
}
开发者ID:tliron,项目名称:restlet-jetty9,代码行数:29,代码来源:JettyClientCall.java
示例12: getMeterList
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Returns the last persisted list of meters
* <p>
* Pseudo Code<br>
* 1. Receive the request for the list of meters<br>
* 2. Query the DB to get the list<br>
* 3. Return the list of meters
*
* @return Representation A JSON response containing the list of meters
*/
@Get
public String getMeterList() {
counter.increment(endpoint);
Gson gson = new Gson();
try {
String meterUrl = Loader.getSettings().getKeyStoneSettings().getCeilometerURL()+"/meters";
ClientResource meterResource = new ClientResource(meterUrl);
Series<Header> requestHeaders =
(Series<Header>) meterResource.getRequestAttributes().get("org.restlet.http.headers");
if (requestHeaders == null) {
requestHeaders = new Series<Header>(Header.class);
meterResource.getRequestAttributes().put("org.restlet.http.headers", requestHeaders);
}
KeystoneClient keystoneClient = new KeystoneClient();
logger.trace("Attempting to create the token");
String subjectToken = keystoneClient.generateToken();
requestHeaders.set("X-Auth-Token", subjectToken);
OpenstackMeter[] meters = gson.fromJson(meterResource.get(MediaType.APPLICATION_JSON).getText(), OpenstackMeter[].class);
return gson.toJson(meters);
} catch (Exception e) {
logger.error("Error while getting the Keystone Meters: "+e.getMessage());
return null;
}
}
开发者ID:icclab,项目名称:cyclops-udr,代码行数:44,代码来源:OpenstackMeterResource.java
示例13: getDoNotTrack
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Whether the client asked for do-not-track.
*
* @return Whether the client asked for do-not-track
*/
public boolean getDoNotTrack()
{
if( doNotTrack == null )
{
Header dnt = getRequestHeaders().getFirst( "DNT" );
doNotTrack = ( dnt != null ) && dnt.getValue().equals( "1" );
}
return doNotTrack;
}
开发者ID:tliron,项目名称:prudence,代码行数:15,代码来源:ConversationService.java
示例14: addDebugHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Adds the caching debug headers if enabled.
*
* @param cacheEntry
* The cache entry
* @param cacheKey
* The cache key
* @param executable
* The executable
* @param suffix
* The optional attribute suffix
*/
public void addDebugHeaders( String event, CacheEntry cacheEntry, String cacheKey, Executable executable, String suffix )
{
if( !attributes.isDebugCaching() )
return;
Series<Header> headers = cacheEntry.getHeaders();
if( headers == null )
headers = new Series<Header>( Header.class );
else
{
// Copy headers
Series<Header> newHeaders = new Series<Header>( Header.class );
for( Header header : headers )
newHeaders.add( header );
headers = newHeaders;
}
SimpleDateFormat format = new SimpleDateFormat( CACHE_EXPIRATION_HEADER_FORMAT );
format.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
// This will override headers set by includes
headers.set( CACHE_HEADER, event );
headers.set( CACHE_KEY_HEADER, cacheKey );
headers.set( CACHE_EXPIRATION_HEADER, format.format( cacheEntry.getExpirationDate() ) );
headers.removeAll( CACHE_TAGS_HEADER );
Set<String> cacheTags = getTags( executable, suffix, false );
if( cacheTags != null )
{
for( String cacheTag : cacheTags )
headers.add( CACHE_TAGS_HEADER, cacheTag );
}
// Apply headers
resource.getResponse().getAttributes().put( HeaderConstants.ATTRIBUTE_HEADERS, headers );
}
开发者ID:tliron,项目名称:prudence,代码行数:50,代码来源:CachingUtil.java
示例15: serializeHeaders
import org.restlet.data.Header; //导入依赖的package包/类
/**
* TODO: this can't be good! needs proper escaping!
*
* @param headers
* The headers
* @return The serialized headers
*/
private static String serializeHeaders( Series<Header> headers )
{
StringBuilder s = new StringBuilder();
for( Iterator<Header> i = headers.iterator(); i.hasNext(); )
{
Header header = i.next();
s.append( header.getName() );
s.append( "=" );
s.append( header.getValue() );
if( i.hasNext() )
s.append( '&' );
}
return s.toString();
}
开发者ID:tliron,项目名称:prudence,代码行数:22,代码来源:SqlCache.java
示例16: afterHandle
import org.restlet.data.Header; //导入依赖的package包/类
@Override
protected void afterHandle( Request request, Response response )
{
Series<Header> headers = RestletUtil.getResponseHeaders( response );
if( allowOrigin != null )
response.setAccessControlAllowOrigin( allowOrigin );
if( !allowMethods.isEmpty() )
response.setAccessControlAllowMethods( allowMethods );
if( !allowHeaders.isEmpty() )
response.setAccessControlAllowHeaders( allowHeaders );
if( maxAge > 0 )
headers.add( new Header( MAX_AGE_HEADER, Integer.toString( maxAge ) ) );
}
开发者ID:tliron,项目名称:prudence,代码行数:14,代码来源:CorsFilter.java
示例17: save
import org.restlet.data.Header; //导入依赖的package包/类
/**
* Saves the link header to the response headers.
*/
public void save()
{
remove();
Header header = new Header( HEADER_LINK, toHeaderValue() );
headers.add( header );
}
开发者ID:tliron,项目名称:prudence,代码行数:10,代码来源:LinkHeader.java
示例18: addHeaders
import org.restlet.data.Header; //导入依赖的package包/类
public void addHeaders(ClientResource client) {
Series<Header> reqHeaders = (Series<Header>)
client.getRequestAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
if (reqHeaders == null) {
reqHeaders = new Series(Header.class);
client.getRequestAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, reqHeaders);
}
Iterator it = headers.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
reqHeaders.add(new Header(pairs.getKey().toString(), pairs.getValue().toString() ));
}
}
开发者ID:valdasraps,项目名称:resthub,代码行数:16,代码来源:TestRequest.java
示例19: headersToFile
import org.restlet.data.Header; //导入依赖的package包/类
private void headersToFile(Series headers, String fileName) throws IOException {
Map map = new HashMap();
for (Object header1 : headers) {
Header header = (Header) header1;
map.put(header.getName(), header.getValue());
}
headersToFile(map, fileName);
}
开发者ID:valdasraps,项目名称:resthub,代码行数:9,代码来源:ServerChecks.java
示例20: compareHeaders
import org.restlet.data.Header; //导入依赖的package包/类
private void compareHeaders(Series headers, InputStream inputStream) throws IOException {
Map map = new HashMap();
for (Object header1 : headers) {
Header header = (Header) header1;
map.put(header.getName(), header.getValue());
}
compareHeaders(map, inputStream);
}
开发者ID:valdasraps,项目名称:resthub,代码行数:9,代码来源:ServerChecks.java
注:本文中的org.restlet.data.Header类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论