org.mortbay.jetty.handler.AbstractHandler Java Examples

The following examples show how to use org.mortbay.jetty.handler.AbstractHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsumerManagerTest.java    From openid4java with Apache License 2.0 6 votes vote down vote up
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);	            
		}
	});
}
 
Example #2
Source File: JettyServer.java    From fiware-cygnus with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: SLSWebApp.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #4
Source File: SLSWebApp.java    From big-c with Apache License 2.0 4 votes vote down vote up
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();
}