@Override public void doHandle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { LOG.debug("jettyhandler, handle();"); try { // wrap the request so 'getInputStream()' can be called multiple times filter.doFilter(new HttpRequestWrapper(request), response, null); baseRequest.setHandled(true); } catch (NotConsumedException ignore) { // TODO : Not use an exception in order to be faster. baseRequest.setHandled(false); } }
@Test public void testBasic() throws Exception { ServiceHandler handler = new ServiceHandler(); Service service = new Service(); handler.registerWebService(service); Request baseRequest = org.easymock.classextension.EasyMock.createMock(Request.class); HttpServletRequest request = createMock(HttpServletRequest.class); HttpServletResponse response = createMock(HttpServletResponse.class); expect(baseRequest.isHandled()).andReturn(false); expect(request.getMethod()).andReturn("GET"); expect(request.getPathInfo()).andReturn("/"); expect(request.getParameter("bar")).andReturn("bar2"); expect(request.getParameter("baz")).andReturn(null); expect(request.getHeader("Content-Length")).andReturn("103"); expect(response.isCommitted()).andReturn(false).anyTimes(); baseRequest.setHandled(true); org.easymock.classextension.EasyMock.replay(baseRequest); replay(request, response); handler.handle(null, baseRequest, request, response); org.easymock.classextension.EasyMock.verify(baseRequest); verify(request, response); }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (!H2O.ARGS.ldap_login) { return; } String loginName = request.getUserPrincipal().getName(); if (!loginName.equals(H2O.ARGS.user_name)) { Log.warn( "Login name (" + loginName + ") does not match cluster owner name (" + H2O.ARGS.user_name + ")"); sendResponseError( response, HttpServletResponse.SC_UNAUTHORIZED, "Login name does not match cluster owner name"); baseRequest.setHandled(true); } }
@Override public void handle( String target, Request request, HttpServletRequest httpRequest, HttpServletResponse response) throws IOException, ServletException { response.setContentType(Const.JSON); Service service = getService(request); Module module = getModule(request, service); GetVersionData data = new GetVersionData(); Future artifactFuture = executorService.submit( new ReadModuleArtifactVersionsRunnable(service, module, data, moduleArtifactHelper)); Future configFuture = executorService.submit( new ReadModuleConfigVersionsRunnable(module, data, moduleConfigHelper)); while (!artifactFuture.isDone() || !configFuture.isDone()) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } toJson(response, data); response.setStatus(200); request.setHandled(true); }
/** * Handle a request. * * @param target The target of the request - either a URI or a name. * @param baseRequest The original unwrapped request object. * @param request The request either as the {@link Request} object or a wrapper of that request. * @param response The response as the {@link org.eclipse.jetty.server.Response} object or a * wrapper of that request. * @throws IOException in case of IO error. */ @SuppressWarnings("unchecked") @Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { if (baseRequest.isHandled()) { return; } Route route = findRoute(request.getMethod(), request.getPathInfo()); if (route == null) { return; } Object param = getRouteParam(request, route); try { beginTransaction(); Response<?> handlerResponse = route.handle(param, new RouteParameters(route.getRouteParams(request.getPathInfo()))); commitTransaction(); writeHttpResponse(request, response, handlerResponse); } catch (HttpErrorException httpError) { commitTransaction(); writeHttpError(response, httpError); } catch (Exception exception) { rollBackTransaction(); writeInternalError(response, exception); } baseRequest.setHandled(true); }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getWriter().println("<h1>Hello World</h1>"); }
/** {@inheritDoc} */ @Override public void handle(String target, Request req, HttpServletRequest srvReq, HttpServletResponse res) throws IOException, ServletException { if (log.isDebugEnabled()) log.debug("Handling request [target=" + target + ", req=" + req + ", srvReq=" + srvReq + ']'); if (target.startsWith("/ignite")) { processRequest(target, srvReq, res); req.setHandled(true); } else if (target.startsWith("/favicon.ico")) { if (favicon == null) { res.setStatus(HttpServletResponse.SC_NOT_FOUND); req.setHandled(true); return; } res.setStatus(HttpServletResponse.SC_OK); res.setContentType("image/x-icon"); res.getOutputStream().write(favicon); res.getOutputStream().flush(); req.setHandled(true); } else { if (dfltPage == null) { res.setStatus(HttpServletResponse.SC_NOT_FOUND); req.setHandled(true); return; } res.setStatus(HttpServletResponse.SC_OK); res.setContentType("text/html"); res.getWriter().write(dfltPage); res.getWriter().flush(); req.setHandled(true); } }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); if (request.getMethod().equals("POST")) { final String jsonRequest = request.getHeader("request"); final String jsonResponse = jsonHandler.apply(jsonRequest); baseRequest.setHandled(true); response.getWriter().println(jsonResponse); } }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (response.isCommitted() || baseRequest.isHandled()) { return; } baseRequest.setHandled(true); response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.sendRedirect("/realtime"); }
@Override public void handle( String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { httpServletResponse.setContentType("text/html; charset=UTF-8"); httpServletResponse.getOutputStream().write("Noop!".getBytes()); httpServletResponse.setStatus(HttpServletResponse.SC_OK); request.setHandled(true); }
/** * Handle a request. * * @param target The target of the request - either a URI or a name. * @param baseRequest The original unwrapped request object. * @param request The request either as the {@link Request} object or a wrapper of that request. * @param response The response as the {@link org.eclipse.jetty.server.Response} object or a * wrapper of that request. * @throws IOException in case of IO error. */ @Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { if (baseRequest.isHandled() || !"GET".equals(request.getMethod())) { return; } if (!request.getPathInfo().endsWith(getSuffixeName())) { return; } try { InputStream resource = AbstractCompilerHandler.class.getResourceAsStream( publicResourcePath + request.getPathInfo()); if (resource != null) { String result = compile(convertStreamToString(resource)); baseRequest.setHandled(true); response.setContentType(getContentType()); response.setStatus(HttpServletResponse.SC_OK); response.getOutputStream().print(result); response.getOutputStream().flush(); response.getOutputStream().close(); } } catch (CompileErrorException exception) { LOGGER.warn("Compile error on {}", request.getPathInfo()); LOGGER.warn("Compile error", exception.getCause()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); exception.getCause().printStackTrace(printWriter); response.getOutputStream().print(writer.toString()); response.getOutputStream().close(); baseRequest.setHandled(true); } }
@Override // !!! note that this gets called for missing pages, but not if exceptions are thrown; // exceptions are handled separately public void handle( String target, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { request.setHandled(true); httpServletResponse .getWriter() .println( String.format("<h1>Page doesn't exist: %s</h1>", request.getUri().getDecodedPath())); }
@Override public void handle( String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); try { TimeUnit.MILLISECONDS.sleep(timeout); IO.copy(request.getInputStream(), response.getOutputStream()); } catch (InterruptedException x) { throw new ServletException(x); } }
public void handle( String s, org.eclipse.jetty.server.Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("GET".equalsIgnoreCase(request.getMethod())) { response.addHeader("target", r.getHttpURI().getPath()); response.setStatus(HttpServletResponse.SC_OK); } else { // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } r.setHandled(true); }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String kk = request.getParameter("kk"); String status = request.getParameter("status"); log.info("------------, target = " + target + " , kk = " + kk + " , status = " + status); response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); PrintWriter out = response.getWriter(); out.println("<h1>Hello World</h1>"); out.println("status: " + status); }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { OutputStream out = response.getOutputStream(); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(); writer.write("hello world"); writer.flush(); response.setContentLength(writer.size()); writer.writeTo(out); out.flush(); baseRequest.setHandled(true); }
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setStatus(200); response.setContentType("text/plain; charset=UTF-8"); response.getWriter().println("URI=" + request.getRequestURI()); String user = request.getRemoteUser(); response.getWriter().println("user="******"test_parameter") != null) response.getWriter().println(request.getParameter("test_parameter")); }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); // cross domain response.setHeader("Access-Control-Allow-Origin", "*"); if (target.startsWith("/reboot")) { reboot(); } else if (target.startsWith("/start")) { start(request, response); } else if (target.startsWith("/queue")) { queue(request, response); } else if (target.startsWith("/new")) { newServer(request, response); } else if (target.startsWith("/delete")) { delete(); } else if (target.startsWith("/force-delete")) { forceDelete(); } else if (target.startsWith("/kill")) { kill(target.replace("/kill ", "")); } else if (target.startsWith("/errors")) { errors(response); } else if (target.startsWith("/databases")) { databases(response); } else if (target.startsWith("/failover")) { failover(request, response); } else if (target.startsWith("/finished")) { finished(request, response); } else if (target.startsWith("/logs")) { getLog(request, response); } }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("/wind-speed".equals(target)) { try { String windSpeed = parseWindSpeed(forecastIoFor(LONDON_LATITUDE, LONDON_LONGITUDE)) + "mph"; response.setContentType("text/html; charset=utf-8"); response.setStatus(SC_OK); response.getWriter().print(windSpeed); baseRequest.setHandled(true); } catch (JSONException e) { throw new ServletException(e); } } }
public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (baseRequest.isHandled()) { return; } _counter.increment(); response.setContentType("text/plain"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); writer.println("===TEST RESPONSE==="); baseRequest.setHandled(true); }
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; if (baseRequest.getMethod().equals("GET")) { status = handleGet(baseRequest, response); } response.setStatus(status); } catch (Exception e) { LOG.error(e, "Exception when handling request %s", target); e.printStackTrace(response.getWriter()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { response.flushBuffer(); baseRequest.setHandled(true); } }
/** http://[server-url]:[server-port]/remove/[xmbc-image-path] */ @Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Params params = new Params(request); System.out.println("Attempting to remove image: " + params.getImageId()); Boolean removeResult = storageRepository.remove(URLDecoder.decode(params.getImageId(), "UTF-8")); if (removeResult) { System.out.println("Image removed succesfully, id: " + params.getImageId()); response.setStatus(HttpServletResponse.SC_OK); } else { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } baseRequest.setHandled(true); }
public void handle( String target, Request base_request, HttpServletRequest servlet_request, HttpServletResponse servlet_response) throws IOException, ServletException { if (!isParametersRequest(target)) { System.out.println("Wrong request!"); return; } servlet_response.setContentType("text/html;charset=utf-8"); servlet_response.setStatus(HttpServletResponse.SC_CREATED); String remoteHost = servlet_request.getRemoteAddr(); base_request.setHandled(true); servlet_response.getWriter().println("<h2>Hello World</h2>"); System.out.println("Got a connection from " + remoteHost + " " + target); }
@Override public void handle( String target, Request baseRequest, HttpServletRequest req, HttpServletResponse rsp) { try { String uri = req.getRequestURI(); AppMaker appMaker = AppMaker.create(sourceDir, uri); if (appMaker == null) { return; } baseRequest.setHandled(true); rsp.setHeader("cache-control", "no-cache"); logger.info(String.format("generating javascript for '%s'", uri)); rsp.setContentType("application/javascript"); rsp.getWriter().write(appMaker.getJavascript()); rsp.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void handle( final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); String postBody = null; if (request.getMethod().equalsIgnoreCase("post")) { try { postBody = HandlerUtils.inputStreamToString(request.getInputStream()); if (postBody == null || postBody.isEmpty()) { HandlerUtils.configureErrorResponse( response, HttpStatus.BAD_REQUEST_400, BAD_POST_REQUEST_MESSAGE); return; } } catch (Exception ex) { HandlerUtils.configureErrorResponse( response, HttpStatus.BAD_REQUEST_400, BAD_POST_REQUEST_MESSAGE); return; } } final StubResponse stubResponse = dataStore.findResponseFor(constructFullURI(request), request.getMethod(), postBody); if (stubResponse instanceof NullStubResponse) { final String error = generate404ErrorMessage(request, postBody); HandlerUtils.configureErrorResponse(response, HttpStatus.NOT_FOUND_404, error); return; } try { doHandle(response, stubResponse); } catch (Exception ex) { HandlerUtils.configureErrorResponse( response, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString()); } }
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); final Matcher detailsMainMatcher = Pattern.compile("/details/([0-9]+)/([0-9]+)/overview").matcher(target); final Matcher plotImageMatcher = Pattern.compile("/details/([0-9]+)/([0-9]+)/(.+)\\.png").matcher(target); final Matcher detailsFileMatcher = Pattern.compile("/details/([0-9]+)/([0-9]+)/(.+)").matcher(target); if (target.equals("/")) { final int currentRequestId = this.getNewRequestId(); this.handleMainPage(request, response, currentRequestId, false); } else if (target.equals("/full")) { final int currentRequestId = this.getNewRequestId(); this.handleMainPage(request, response, currentRequestId, true); } else if (detailsMainMatcher.matches()) { this.handleDetailsPage( request, response, Integer.parseInt(detailsMainMatcher.group(1)), Integer.parseInt(detailsMainMatcher.group(2))); } else if (plotImageMatcher.matches()) { this.handlePlotImage( request, response, Integer.parseInt(plotImageMatcher.group(1)), Integer.parseInt(plotImageMatcher.group(2)), plotImageMatcher.group(3)); } else if (detailsFileMatcher.matches()) { this.handleDetailFileRequest( request, response, Integer.parseInt(detailsFileMatcher.group(1)), Integer.parseInt(detailsFileMatcher.group(2)), detailsFileMatcher.group(3)); } }
@Override public void handle( String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (m_delay > 0) try { Thread.sleep(m_delay); } catch (InterruptedException e) { e.printStackTrace(); throw new ServletException("Unable to sleep()"); } response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getWriter().print(m_response); }
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (webSocketFactory.isUpgradeRequest(request, response)) { // We have an upgrade request if (webSocketFactory.acceptWebSocket(request, response)) { // We have a socket instance created baseRequest.setHandled(true); return; } // If we reach this point, it means we had an incoming request to upgrade // but it was either not a proper websocket upgrade, or it was possibly rejected // due to incoming request constraints (controlled by WebSocketCreator) if (response.isCommitted()) { // not much we can do at this point. return; } } super.handle(target, baseRequest, request, response); }
/** * Handle a request. * * @param target The target of the request - either a URI or a name. * @param baseRequest The original unwrapped request object. * @param request The request either as the {@link Request} object or a wrapper of that request. * The HttpChannel.getCurrentHttpChannel method can be used access the Request object if * required. * @param response The response as the Response object or a wrapper of that request. The * HttpChannel.getCurrentHttpChannel() method can be used access the Response object if * required. */ @Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { /* since we're not deciding what to do based on the `target`, we're going to do * the exact same thing for every page regardless of which path parameter they sent * in their HTTP request. */ System.out.println("target: " + target); System.out.println("baseRequest:" + baseRequest.toString()); System.out.println("request: " + request.toString()); /* this sets the `Content-Type` HEADER in the HTTP response */ response.setContentType("text/html; charset=utf-8"); /* this sets the STATUS CODE in the HTTP response */ response.setStatus(HttpServletResponse.SC_OK); /* this adds the text to the BODY of the HTTP response */ response.getWriter().println("<h1>Hello World</h1>"); /* I think this means that if we have this handler in a HandlerList, it will stop * passing the request to sequential handlers in that list because this one did * already handle it. */ baseRequest.setHandled(true); /* The `Date` is automatically added as a header because the default `HttpConfiguration` * does that. And the default `Server` we created, creates a default `ServerConnector` * which creates a default `HttpConnectionFactory`, which creates a default * `HttpConfiguration`. */ System.out.println("\nresponse:"); System.out.println("=============="); System.out.println(response.toString()); System.out.println("==============\n"); }
@Override public void handle( String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/plain;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); try { final String spath = decode(request.getParameter("path")); final Path path = Paths.get(spath); Set<PosixFilePermission> perms = Files.getPosixFilePermissions(path); for (PosixFilePermission posixFilePermission : perms) { response.getWriter().println(String.valueOf(posixFilePermission)); } } catch (Throwable ne) { response.getWriter().println("INALVID"); } }