本文整理汇总了Java中org.mortbay.jetty.handler.AbstractHandler类的典型用法代码示例。如果您正苦于以下问题:Java AbstractHandler类的具体用法?Java AbstractHandler怎么用?Java AbstractHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractHandler类属于org.mortbay.jetty.handler包,在下文中一共展示了AbstractHandler类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MockOpenIDServer
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
public MockOpenIDServer(int port) {
super(port);
this.port = port;
setHandler(new AbstractHandler() {
public void handle(String target, HttpServletRequest request,
HttpServletResponse response, int dispatch)
throws IOException, ServletException {
MockOpenIDServer.this.requestParams.add(request.getParameterMap());
ParameterList params = new ParameterList();
params.set(new Parameter("ns",AssociationResponse.OPENID2_NS));
params.set(new Parameter("assoc_handle",String.valueOf(System.nanoTime())));
params.set(new Parameter("assoc_type",request.getParameter("openid.assoc_type")));
params.set(new Parameter("session_type",request.getParameter("openid.session_type")));
params.set(new Parameter("expires_in","1799"));
params.set(new Parameter("dh_server_public","eRm/Qn9lXQJc30ZQLtNFkrjQHuQCLyQ2fRNwLZTGVP50Lhx16EjksA6N0RvXzoJgY8/FdKioOYXKeWVvstHTUReXfF5EC9cnTVOFtTrMegJXHZIHdk+IITwsfGfTlVxMOc7DdCFOOMRWMOA9sYB5n5OoxnzYCob3vo39+Xytlcs="));
params.set(new Parameter("enc_mac_key","CY08gTx1u4XravtWT3V5Er4sG+o="));
response.getWriter().write(params.toString());
((Request) request).setHandled(true);
}
});
}
示例2: startJetty
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
@BeforeClass
public static void startJetty() throws Exception {
port = PortFactory.findFreePort();
server = new Server();
SslSocketConnector sslSocketConnector = new SslSocketConnector();
sslSocketConnector.setKeystore("src/test/resources/keystore");
sslSocketConnector.setKeyPassword("password");
sslSocketConnector.setPort(port);
server.setConnectors(new Connector[]{sslSocketConnector});
server.addHandler(new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
response.setStatus(Response.Status.OK.getStatusCode());
Request base_request = request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
base_request.setHandled(true);
}
});
server.start();
}
示例3: run
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
public void run() {
Handler handler = new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
throws java.io.IOException, javax.servlet.ServletException {
processor.process(request, response);
((Request) request).setHandled(true);
}
};
Server server = new Server(_port);
server.setHandler(handler);
try {
server.start();
System.out.println("HTTP Jetty Server Started on port " + _port);
server.join();
} catch (Exception e) {
System.out.println("Failed to start Jetty HTTP Server: " + e);
e.printStackTrace();
}
}
示例4: setUp
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
public void setUp() throws Exception
{
_handler=new RewriteHandler();
_server.setHandler(_handler);
_handler.setHandler(new AbstractHandler(){
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
{
response.setStatus(201);
request.setAttribute("target",target);
request.setAttribute("URI",request.getRequestURI());
request.setAttribute("info",request.getPathInfo());
}
});
_rule1 = new RewritePatternRule();
_rule1.setPattern("/aaa/*");
_rule1.setReplacement("/bbb");
_rule2 = new RewritePatternRule();
_rule2.setPattern("/bbb/*");
_rule2.setReplacement("/ccc");
_rule3 = new RewritePatternRule();
_rule3.setPattern("/ccc/*");
_rule3.setReplacement("/ddd");
_handler.setRules(new Rule[]{_rule1,_rule2,_rule3});
super.setUp();
}
示例5: newExitHandler
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
protected ContextHandler newExitHandler() {
ContextHandler ctx = new ContextHandler();
ctx.setContextPath("/exit");
ctx.setHandler(new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
throws IOException, ServletException {
System.exit(1);
}
});
return ctx;
}
示例6: start
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
public synchronized void start(int port, AbstractHandler... handlers) {
if (isRunning()) {
return;
}
// install shutdown hook to stop file server
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
stop();
}
}));
if (log.isInfoEnabled()) {
log.info("Starting file server");
}
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);
server.addConnector(connector);
HandlerList _handlers = new HandlerList();
List<AbstractHandler> list = new ArrayList<AbstractHandler>(Arrays.asList(handlers));
list.add(new DefaultHandler());
_handlers.setHandlers(list.toArray(new Handler[list.size()]));
server.setHandler(_handlers);
try {
server.start();
} catch (Exception e) {
throw new PaxmlRuntimeException("Cannot start file server", e);
}
this.port = connector.getLocalPort();
if (log.isInfoEnabled()) {
log.info("File server started at port: " + this.port);
}
}
示例7: JettyServer
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
/**
* Constructor.
* @param mgmtIfPort
* @param guiPort
* @param handler
* @param ipv6
*/
public JettyServer(int mgmtIfPort, int guiPort, AbstractHandler handler, boolean ipv6) {
// create the server
server = new Server();
// add the Management Interface connector
SelectChannelConnector conn1 = new SelectChannelConnector();
if (ipv6) {
conn1.setHost("::0");
} else {
conn1.setHost("0.0.0.0");
} // if else
conn1.setPort(mgmtIfPort);
server.addConnector(conn1);
if (guiPort != 0) {
// add the GUI connector
SelectChannelConnector conn2 = new SelectChannelConnector();
if (ipv6) {
conn2.setHost("::0");
} else {
conn2.setHost("0.0.0.0");
} // if else
conn2.setPort(guiPort);
server.addConnector(conn2);
} // if
// set the handler
server.setHandler(handler);
}
示例8: serverReturns500IsOk
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
@Test
public void serverReturns500IsOk() throws Exception {
server.setHandler(new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
throw new RuntimeException("If the server is really really broken");
}
});
assertCanConnect();
}
示例9: serverReturnsFailIsOk
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
@Test
public void serverReturnsFailIsOk() throws Exception {
server.setHandler(new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
response.getOutputStream().write("Server FAIL".getBytes());
}
});
assertCanConnect();
}
示例10: start
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
public void start() throws Exception {
// static files
final ResourceHandler staticHandler = new ResourceHandler();
staticHandler.setResourceBase("html");
Handler handler = new AbstractHandler() {
@Override
public void handle(String target, HttpServletRequest request,
HttpServletResponse response, int dispatch) {
try{
// timeunit
int timeunit = 1000; // second, divide millionsecond / 1000
String timeunitLabel = "second";
if (request.getParameter("u")!= null &&
request.getParameter("u").equalsIgnoreCase("m")) {
timeunit = 1000 * 60;
timeunitLabel = "minute";
}
// http request
if (target.equals("/")) {
printPageIndex(request, response);
} else if (target.equals("/simulate")) {
printPageSimulate(request, response, timeunit, timeunitLabel);
} else if (target.equals("/track")) {
printPageTrack(request, response, timeunit, timeunitLabel);
} else
// js/css request
if (target.startsWith("/js") || target.startsWith("/css")) {
response.setCharacterEncoding("utf-8");
staticHandler.handle(target, request, response, dispatch);
} else
// json request
if (target.equals("/simulateMetrics")) {
printJsonMetrics(request, response);
} else if (target.equals("/trackMetrics")) {
printJsonTrack(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
server = new Server(port);
server.setHandler(handler);
server.start();
}
示例11: newFileHandler
import org.mortbay.jetty.handler.AbstractHandler; //导入依赖的package包/类
public static AbstractHandler newFileHandler() {
return new AbstractHandler() {
@Override
public void handle(String path, HttpServletRequest request, HttpServletResponse res, int arg3)
throws IOException, ServletException {
if (path.startsWith("/")) {
path = path.substring(1);
}
String tmpFile = null;
InputStream in = null;
try {
if (path.startsWith(IN_MEM_IDENT)) {
// let a file be read for only once, otherwise memory
// could explode
String content = memFiles.remove(path);
in = new ByteArrayInputStream(content.getBytes("UTF-8"));
} else if (path.startsWith(TMP_FILE_IDENT)) {
tmpFile = path.substring(TMP_FILE_IDENT.length());
in = new FileInputStream(new File(TMP_DIR, tmpFile));
} else if (path.startsWith(CLASSPATH_IDENT)) {
in = new ClassPathResource(path.substring(CLASSPATH_IDENT.length())).getInputStream();
} else {
throw new IOException("Path with unknown identifier: " + path);
}
res.setStatus(HttpServletResponse.SC_OK);
res.setContentType("binary/x-paxml");
res.setHeader("Content-Disposition", "attachment; filename=\"" + path +"\"");
res.setHeader("Pragma", "");
res.setHeader("Cache-control", "");
IOUtils.copy(in, res.getOutputStream());
((Request) request).setHandled(true);
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("Cannot resolve path: " + path, e);
}
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
} finally {
IOUtils.closeQuietly(in);
if (tmpFile != null) {
new File(tmpFile).delete();
}
}
}
};
}