private void addSecurityHandler(HttpContext context) { SecurityConstraint constraint = new SecurityConstraint(); constraint.setName(SecurityConstraint.__BASIC_AUTH); constraint.addRole("user"); constraint.setAuthenticate(true); context.addSecurityConstraint("/tests/html/basicAuth/*", constraint); HashUserRealm realm = new HashUserRealm("MyRealm"); realm.put("alice", "foo"); realm.addUserToRole("alice", "user"); context.setRealm(realm); SecurityHandler sh = new SecurityHandler(); context.addHandler(sh); }
/** * Send Forbidden. Method called to send forbidden response. Default implementation calls * sendError(403) */ protected void sendForbid(HttpRequest request, HttpResponse response, URI uri) throws IOException { response.sendError(HttpResponse.__403_Forbidden, "Forbidden for Proxy"); }
@Override protected void handle(String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { response.setContentType(request.getContentType()); response.addField("X-Test-Header", "test value"); IOUtils.copy(request.getInputStream(), response.getOutputStream()); }
final SocketListener listener = new SocketListener( 6060 ); listener.start();
public void stopServer() throws InterruptedException { wsLogger.info("Connections=" + fServer.getConnections()); wsLogger.info("ConnectionsOpen=" + fServer.getConnectionsOpen()); wsLogger.info("ConnectionsRequests=" + fServer.getRequests()); if (listener2 != null) { wsLogger.info("ACCEPTQUESIZE=" + listener2.getAcceptQueueSize()); } fServer.stop(true); }
@TearDown @SuppressWarnings("unused") private void tearDown() throws Exception { handler.stop(); server.getContext().removeHandler(handler); }
public void setThreads(int min, int max) { listener.setMinThreads(min); listener.setMaxThreads(max); }
@Override public OutputStream openStream() { return response.getOutputStream(); } }.asCharSink(Charset.forName(UTF_8)).write(mockResponseBodies.get(numInteractions++));
public void handle(String pathInContext, String pathParams, HttpRequest req, HttpResponse resp) throws IOException { HTTPDecoupledClientInputStreamContext ctx = new HTTPDecoupledClientInputStreamContext(req); responseCallback.dispatch(ctx); resp.commit(); req.setHandled(true); } }
@Override public InputStream openStream() throws IOException { return request.getInputStream(); } }.read();
/** Sets all the don't-cache headers on the HttpResponse */ private void setAlwaysCacheHeaders(HttpResponse res) { res.setField(HttpFields.__CacheControl, "max-age=29723626"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.YEAR, 1); res.setField(HttpFields.__Expires, HttpFields.formatDate(calendar, false)); res.setField(HttpFields.__LastModified, HttpFields.__01Jan1970); res.removeField(HttpFields.__Pragma); res.setField(HttpFields.__ETag, "foo"); }
protected void customizeRequest(Socket socket, HttpRequest request) { super.customizeRequest(socket,request); URI uri=request.getURI(); // Convert the URI to a proxy URL uri.setScheme("https"); uri.setHost(_addr.getHost()); uri.setPort(_addr.getPort()); }
/** * Get the port that the server is on * @return the port */ public int getPort() { return listener.getPort(); }
@Override protected void handle(String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { response.setContentType(request.getContentType()); response.addField("X-Test-Header", "test value"); IOUtils.copy(request.getInputStream(), response.getOutputStream()); }
@TearDown @SuppressWarnings("unused") private void tearDown() throws Exception { handler.stop(); server.getContext().removeHandler(handler); }
/** * Send not found. Method called to send not found response. Default implementation calls * sendError(404) */ protected void sendNotFound(HttpResponse response) throws IOException { response.sendError(HttpResponse.__404_Not_Found, "Not found"); }
@Override protected void handle(String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException { response.setContentType(request.getContentType()); response.addField("X-Test-Header", "test value"); IOUtils.copy(request.getInputStream(), response.getOutputStream()); }
@TearDown @SuppressWarnings("unused") private void tearDown() throws Exception { handler.stop(); server.getContext().removeHandler(handler); }