@Override public void doSetHeader(String headerName, String header) { response.setValue(headerName, header); }
@Override public void doSetHeader(String headerName, String header) { response.setValue(headerName, header); }
@Override public void setHeader(String name, String value) { response.setValue(name, value); }
/** * This can be used to set a HTTP message header to this object. * The name and value of the HTTP message header will be used to * create a HTTP message header object which can be retrieved using * the <code>getValue</code> in combination with the get methods. * This will perform a <code>remove</code> using the issued header * name before the header value is set. * * @param name the name of the HTTP message header to be added * @param value the value the HTTP message header will have */ public void setValue(String name, String value) { response.setValue(name, value); }
/** * This can be used to set a HTTP message header to this object. * The name and value of the HTTP message header will be used to * create a HTTP message header object which can be retrieved using * the <code>getValue</code> in combination with the get methods. * This will perform a <code>remove</code> using the issued header * name before the header value is set. * * @param name the name of the HTTP message header to be added * @param value the value the HTTP message header will have */ public void setValue(String name, String value) { response.setValue(name, value); }
/** * This can be used to set a HTTP message header to this object. * The name and value of the HTTP message header will be used to * create a HTTP message header object which can be retrieved using * the <code>getValue</code> in combination with the get methods. * This will perform a <code>remove</code> using the issued header * name before the header value is set. * * @param name the name of the HTTP message header to be added * @param value the value the HTTP message header will have */ public void setValue(String name, String value) { response.setValue(name, value); }
protected void addStandardHeaders(Response response, String responseContentType) { long time = System.currentTimeMillis(); response.setValue("Content-Type", responseContentType); response.setValue("Server", "Fixd/1.0 (Simple 5.1.4)"); response.setDate("Date", time); response.setDate("Last-Modified", time); } }
/** * This is used to respond to the client with a HTTP 101 response * to indicate that the WebSocket handshake succeeeded. Once this * response has been sent all traffic between the client and * server will be with WebSocket frames as defined by RFC 6455. */ private void accept() throws IOException { long time = System.currentTimeMillis(); String accept = token.create(); response.setStatus(Status.SWITCHING_PROTOCOLS); response.setDescription(UPGRADE); response.setValue(CONNECTION, UPGRADE); response.setDate(DATE, time); response.setValue(SEC_WEBSOCKET_ACCEPT, accept); response.setValue(UPGRADE, WEBSOCKET); String header = response.toString(); byte[] message = header.getBytes("UTF-8"); trace.trace(WRITE_HEADER, header); writer.write(message); writer.flush(); } }
/** * This is used to respond to the client with a HTTP 101 response * to indicate that the WebSocket handshake succeeeded. Once this * response has been sent all traffic between the client and * server will be with WebSocket frames as defined by RFC 6455. */ private void accept() throws IOException { long time = System.currentTimeMillis(); String accept = token.create(); response.setStatus(Status.SWITCHING_PROTOCOLS); response.setDescription(UPGRADE); response.setValue(CONNECTION, UPGRADE); response.setDate(DATE, time); response.setValue(SEC_WEBSOCKET_ACCEPT, accept); response.setValue(UPGRADE, WEBSOCKET); String header = response.toString(); byte[] message = header.getBytes("UTF-8"); trace.trace(WRITE_HEADER, header); writer.write(message); writer.flush(); } }
/** * This is used to respond to the client with a HTTP 400 response * indicating the WebSocket handshake failed. No response body is * sent with the rejection message and the underlying TCP channel * is closed to prevent further use of the connection. */ private void reject() throws IOException { long time = System.currentTimeMillis(); response.setStatus(Status.BAD_REQUEST); response.setValue(CONNECTION, CLOSE); response.setDate(DATE, time); String header = response.toString(); byte[] message = header.getBytes("UTF-8"); trace.trace(WRITE_HEADER, header); writer.write(message); writer.flush(); writer.close(); }
/** * This is used to respond to the client with a HTTP 400 response * indicating the WebSocket handshake failed. No response body is * sent with the rejection message and the underlying TCP channel * is closed to prevent further use of the connection. */ private void reject() throws IOException { long time = System.currentTimeMillis(); response.setStatus(Status.BAD_REQUEST); response.setValue(CONNECTION, CLOSE); response.setDate(DATE, time); String header = response.toString(); byte[] message = header.getBytes("UTF-8"); trace.trace(WRITE_HEADER, header); writer.write(message); writer.flush(); writer.close(); }
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse cResponse) throws IOException { int code = cResponse.getStatus(); String text = Status.getDescription(code); String method = request.getMethod(); response.setCode(code); response.setDescription(text); if (!method.equalsIgnoreCase("HEAD") && contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (Map.Entry<String, List<Object>> e : cResponse.getHttpHeaders().entrySet()) { for (Object value : e.getValue()) { response.setValue(e.getKey(), ContainerResponse.getHeaderValue(value)); } } return response.getOutputStream(); }
String address = req.getAddress().toString(); if( address.equals(REDIRECT_PATH) ) { resp.setValue(HttpHeaders.LOCATION, REAL_ENDPOINT_PATH); resp.setCode(HttpURLConnection.HTTP_MOVED_PERM); } else if( address.equals(REDIRECT_URL) ) { resp.setValue(HttpHeaders.LOCATION, "http://localhost:" + port + REAL_ENDPOINT_PATH); resp.setCode(HttpURLConnection.HTTP_MOVED_TEMP); } else if( address.equals(REDIRECT_DOUBLE) ) { resp.setValue(HttpHeaders.LOCATION, "http://localhost:" + port + REDIRECT_URL); resp.setCode(HttpURLConnection.HTTP_SEE_OTHER); } else if( address.equals(REDIRECT_ENDLESS) ) { resp.setValue(HttpHeaders.LOCATION, "http://localhost:" + port + REDIRECT_ENDLESS); resp.setCode(HttpURLConnection.HTTP_SEE_OTHER); } else if( address.equals(REDIRECT_LOOP) ) { resp.setValue(HttpHeaders.LOCATION, "http://localhost:" + port + REDIRECT_LOOP_2); resp.setCode(HttpURLConnection.HTTP_MOVED_PERM); } else if( address.equals(REDIRECT_LOOP_2) ) { resp.setValue(HttpHeaders.LOCATION, "http://localhost:" + port + REDIRECT_LOOP); resp.setCode(HttpURLConnection.HTTP_MOVED_PERM); } else if( address.equals(DEFAULT_ENPOINT) ) { resp.setValue(HttpHeaders.LOCATION, "http://localhost:" + port + REDIRECT_URL); resp.setCode(HttpURLConnection.HTTP_MOVED_PERM); } else if( address.equals("/real/endpoint") ) { resp.setValue(HttpHeaders.CONTENT_TYPE, "text/plain");
@Override public void handle(Request request, Response response) { try { PrintStream body = response.getPrintStream(); long time = System.currentTimeMillis(); response.setValue("Content-Type", "text/plain"); response.setContentType("application/xml;charset=utf-8"); response.setDate("Date", time); response.setDate("Last-Modified", time); String path = request.getAddress().getPath().getPath(); log.trace("request path is {}", path); StatusAndContent statusAndContent = tryMatchPath(path); Status status = statusAndContent.status; response.setStatus(status); String content = statusAndContent.content; log.trace("mock container returning: status [{}], content [{}]", status, content); body.println(content); body.close(); } catch (Exception e) { e.printStackTrace(); response.setStatus(Status.INTERNAL_SERVER_ERROR); try { response.close(); } catch (IOException e1) { throw new RuntimeException(e1); } } }