private URI getBaseUri(final Request request) { try { final String hostHeader = request.getValue("Host"); if (hostHeader != null) { final String scheme = request.isSecure() ? "https" : "http"; return new URI(scheme + "://" + hostHeader + "/"); } else { final Address address = request.getAddress(); return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null, null); } } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
myRequestProcessor.process(request.getAddress().toString(), request.getClientAddress().getAddress().getHostAddress(), getRequestHandler(response)); } else { myMultiAnnounceRequestProcessor.process(request.getContent(), request.getAddress().toString(), request.getClientAddress().getAddress().getHostAddress(), getRequestHandler(response));
/** * This is used to acquire the address from the request line. * An address is the full URI including the scheme, domain, port * and the query parts. This allows various parameters to be * acquired without having to parse the raw request target URI. * * @return this returns the address of the request line */ public Address getAddress() { return request.getAddress(); }
/** * This is used to acquire the address from the request line. * An address is the full URI including the scheme, domain, port * and the query parts. This allows various parameters to be * acquired without having to parse the raw request target URI. * * @return this returns the address of the request line */ public Address getAddress() { return request.getAddress(); }
/** * This is used to acquire the address from the request line. * An address is the full URI including the scheme, domain, port * and the query parts. This allows various parameters to be * acquired without having to parse the raw request target URI. * * @return this returns the address of the request line */ public Address getAddress() { return request.getAddress(); }
@Override public String getFromAddress() { Address add = baseRequest.getAddress(); if (add == null) { return null; } return add.toString(); }
@Override public String toString() { return request.getMethod() + " " + request.getAddress().toString(); }
private URI getBaseUri(Request request) { try { final Address address = request.getAddress(); return new URI( address.getScheme(), null, address.getDomain(), address.getPort(), "/", null, null); } catch (URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
private URI getBaseUri(final Request request) { try { final String hostHeader = request.getValue("Host"); if (hostHeader != null) { final String scheme = request.isSecure() ? "https" : "http"; return new URI(scheme + "://" + hostHeader + "/"); } else { final Address address = request.getAddress(); return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null, null); } } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
} else { String host = baseRequest.getValue("Host"); Address a = baseRequest.getAddress(); if (host == null) { host = a.getDomain();
public static FullHttpRequest convert(final Request request) { byte[] data = null; try { final InputStream inputStream = request.getInputStream(); try { data = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } } catch (final IOException e) { LOGGER.error("IOException when getting request content.", e); } final FullHttpRequestImpl httpRequest = new FullHttpRequestImpl(); httpRequest.domain(request.getAddress().getDomain()); httpRequest.port(request.getAddress().getPort()); httpRequest.method(Method.valueOf(request.getMethod())); httpRequest.path(request.getPath().getPath()); if (data.length > 0) { httpRequest.content(data); } for (final String headerField : request.getNames()) { for (final String headerFieldValue : request.getValues(headerField)) { httpRequest.httpMessageHeader(headerField, headerFieldValue); } } for (final Entry<String, String> entry : request.getQuery().entrySet()) { httpRequest.queryParameter(entry.getKey(), entry.getValue()); } return httpRequest; }
public void handle( Request req, Response resp ) { try { PrintStream out = resp.getPrintStream(1024); String address = req.getAddress().toString(); if( address.equals(DEFAULT_ENPOINT) ) { String content = readInputStreamAsString(req.getInputStream()); JaxbCommandsRequest cmdsReq = (JaxbCommandsRequest) jaxbSerializationProvider.deserialize(content); String [] headerNames = { TEST_HEADER_NAME, ANOTHER_TEST_HEADER_NAME, NOT_SENT_HEADER_NAME }; List<String> headerValues = new ArrayList<String>(); for( String headerName : headerNames ) { String headerVal = req.getValue(headerName); if( headerVal != null ) { headerValues.add(headerVal); } } String output = handleJaxbCommandsRequest(cmdsReq, headerValues); resp.setCode(HttpURLConnection.HTTP_OK); out.print(output); } else { resp.setCode(HttpURLConnection.HTTP_BAD_REQUEST); } out.close(); } catch( Exception e ) { e.printStackTrace(); } }
@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); } } }
logger.debug(headers[0] + ": " + user + "/" + pass); String address = req.getAddress().toString(); if( address.equals(DEFAULT_ENDPOINT) ) { resp.setValue(HttpHeaders.CONTENT_TYPE, "text/plain");
public void handle( Request req, Response resp ) { try { PrintStream out = resp.getPrintStream(1024); String address = req.getAddress().toString(); if( address.equals(REDIRECT_PATH) ) { resp.setValue(HttpHeaders.LOCATION, REAL_ENDPOINT_PATH);