本文整理汇总了Java中org.restlet.engine.header.Header类的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Header类属于org.restlet.engine.header包,在下文中一共展示了Header类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterHandle
import org.restlet.engine.header.Header; //导入依赖的package包/类
@Override
protected void afterHandle(Request request, Response response) {
if (!Method.OPTIONS.equals(request.getMethod())) {
final Map<String, Object> responseAttributes = response.getAttributes();
@SuppressWarnings("unchecked")
Series<Header> responseHeaders = (Series<Header>) responseAttributes.get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series<Header>(Header.class);
responseAttributes.put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", "*");
// responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,DELETE,OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Accept,Accept-Version,Content-Type,Api-Version,Authorization");
responseHeaders.add("Access-Control-Allow-Credentials", "true");
// responseHeaders.add("Access-Control-Max-Age", "60");
}
// }
super.afterHandle(request, response);
}
示例2: addAllowOrigin
import org.restlet.engine.header.Header; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void addAllowOrigin()
{
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null)
{
responseHeaders = new Series<>(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", "*");
responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
responseHeaders.add("Access-Control-Allow-Credentials", "false");
responseHeaders.add("Access-Control-Max-Age", "60");
}
示例3: getIP
import org.restlet.engine.header.Header; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public String getIP()
{
final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers");
final String realIp = headers.getFirstValue("X-Real-IP", true);
if (realIp != null)
return realIp;
else
return getRequest().getClientInfo().getAddress();
}
示例4: getURL
import org.restlet.engine.header.Header; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Reference getURL()
{
final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers");
final String realURL = headers.getFirstValue("X-Real-URL", true);
if (realURL != null)
return new Reference(realURL);
else
return getRequest().getOriginalRef();
}
示例5: addAllowOrigin
import org.restlet.engine.header.Header; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void addAllowOrigin()
{
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null)
{
responseHeaders = new Series<Header>(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", "*");
responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
responseHeaders.add("Access-Control-Allow-Credentials", "false");
responseHeaders.add("Access-Control-Max-Age", "60");
}
示例6: addCustomHeaders
import org.restlet.engine.header.Header; //导入依赖的package包/类
protected void addCustomHeaders() {
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
// allow request from other origins
responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
}
示例7: doOptions
import org.restlet.engine.header.Header; //导入依赖的package包/类
@Options
public void doOptions() {
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", "*");
responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
responseHeaders.add("Access-Control-Max-Age", "60");
}
示例8: addExtraHeaders
import org.restlet.engine.header.Header; //导入依赖的package包/类
public static void addExtraHeaders(Response response) {
Series<Header> responseHeaders = (Series<Header>)response.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
response.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders);
}
responseHeaders.add(new Header(HDR_CONTROLLER_HOST, getHostName()));
responseHeaders.add(new Header(HDR_CONTROLLER_VERSION, getControllerVersion()));
}
示例9: getHeaders
import org.restlet.engine.header.Header; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Series<Header> getHeaders(Response response) {
Series<Header> headers = (Series<Header>) response.getAttributes().get("org.restlet.http.headers");
if (headers == null) {
headers = new Series<>(Header.class);
response.getAttributes().put("org.restlet.http.headers", headers);
}
return headers;
}
示例10: testHeaders
import org.restlet.engine.header.Header; //导入依赖的package包/类
@Test
public void testHeaders() {
OntopiaTestResource request = new OntopiaTestResource(Method.GET, getUrl(null), defaultMediatype);
request.request();
Series<Header> headers = HeaderUtils.getHeaders(request.getResponse());
Assert.assertNotNull(headers);
Assert.assertEquals("v1", headers.getFirstValue("X-Ontopia-API-Version"));
Assert.assertEquals("n.o.t.r.OntopiaRestApplication", headers.getFirstValue("X-Ontopia-Application"));
Assert.assertEquals("n.o.t.r.v1.topic.TopicsResource", headers.getFirstValue("X-Ontopia-Resource"));
Assert.assertEquals("topics.ltm", headers.getFirstValue("X-Ontopia-Topicmap"));
}
示例11: addCustomHeaders
import org.restlet.engine.header.Header; //导入依赖的package包/类
protected void addCustomHeaders()
{
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
//allow request from other origins
responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
}
示例12: doOptions
import org.restlet.engine.header.Header; //导入依赖的package包/类
@Options
public void doOptions()
{
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", "*");
responseHeaders.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
responseHeaders.add("Access-Control-Max-Age", "60");
}
示例13: addRestletHeader
import org.restlet.engine.header.Header; //导入依赖的package包/类
/**
* Adds a HTTP header to a Restlet ClientResource OAUTH bearer is a pain via
* restlet on GAE, so we set it ourselves.
*/
public static void addRestletHeader(ClientResource client, String key, String value) {
@SuppressWarnings("unchecked")
Series<Header> headers = (Series<Header>) client.getRequestAttributes().get("org.restlet.http.headers");
if (headers == null) {
headers = new Series<Header>(Header.class);
client.getRequestAttributes().put("org.restlet.http.headers", headers);
}
headers.add(key, value);
}
示例14: getHeaderValue
import org.restlet.engine.header.Header; //导入依赖的package包/类
protected String getHeaderValue(String headerName,Request request,Series<Header> headers) {
if (headerName.equals("Host")) {
Reference hostRef = request.getHostRef();
return hostRef==null ? null : hostRef.toString();
} else {
return headers==null ? null : headers.getFirstValue(headerName);
}
}
示例15: addAccessControl
import org.restlet.engine.header.Header; //导入依赖的package包/类
protected void addAccessControl(Response response) {
Series<Header> responseHeaders = (Series<Header>)response.getAttributes().get("org.restlet.http.headers");
if (responseHeaders==null) {
responseHeaders = new Series<Header>(Header.class);
response.getAttributes().put("org.restlet.http.headers",responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", origin);
responseHeaders.add("Access-Control-Allow-Headers",allowHeaders);
}