本文整理汇总了Java中org.eclipse.jetty.server.Request.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getHeader方法的具体用法?Java Request.getHeader怎么用?Java Request.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.Request
的用法示例。
在下文中一共展示了Request.getHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeResponse
import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
private void writeResponse(Request baseRequest, HttpServletResponse response, Object data) throws IOException{
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json; charset=utf-8");
String origin = baseRequest.getHeader("Origin");
if(origin != null) {
response.setHeader("Access-Control-Allow-Origin", origin);
}
PrintWriter out = response.getWriter();
out.println(jparser.toJson(data));
baseRequest.setHandled(true);
}
示例2: setUp
import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
/**
* Set up server with handler
*
* @param handler
* @return port
* @throws Exception
*/
public static String setUp(final Handler handler) throws Exception {
server = new Server();
if (handler != null)
server.setHandler(handler);
Connector connector = new SelectChannelConnector();
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
server.start();
proxy = new Server();
Connector proxyConnector = new SelectChannelConnector();
proxyConnector.setPort(0);
proxy.setConnectors(new Connector[] { proxyConnector });
ServletHandler proxyHandler = new ServletHandler();
RequestHandler proxyCountingHandler = new RequestHandler() {
@Override
public void handle(Request request, HttpServletResponse response) {
proxyHitCount.incrementAndGet();
String auth = request.getHeader("Proxy-Authorization");
auth = auth.substring(auth.indexOf(' ') + 1);
try {
auth = B64Code.decode(auth, CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
int colon = auth.indexOf(':');
proxyUser.set(auth.substring(0, colon));
proxyPassword.set(auth.substring(colon + 1));
request.setHandled(false);
}
};
HandlerList handlerList = new HandlerList();
handlerList.addHandler(proxyCountingHandler);
handlerList.addHandler(proxyHandler);
proxy.setHandler(handlerList);
ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
proxyHolder.setAsyncSupported(true);
proxy.start();
proxyPort = proxyConnector.getLocalPort();
return "http://localhost:" + connector.getLocalPort();
}