HttpRequestFactory { public static HttpRequest newJDiscRequest(CurrentContainer container, HttpServletRequest servletRequest) { try { HttpRequest httpRequest = HttpRequest.newServerRequest( container, getUri(servletRequest), HttpRequest.Method.valueOf(servletRequest.getMethod()), HttpRequest.Version.fromString(servletRequest.getProtocol()), new InetSocketAddress(servletRequest.getRemoteAddr(), servletRequest.getRemotePort()), getConnection(servletRequest).getCreatedTimeStamp()); httpRequest.context().put(ServletRequest.JDISC_REQUEST_X509CERT, getCertChain(servletRequest)); return httpRequest; } catch (Utf8Appendable.NotUtf8Exception e) { throw createBadQueryException(e); } }  static HttpRequest newJDiscRequest(CurrentContainer container, HttpServletRequest servletRequest); static URI getUri(HttpServletRequest servletRequest); static void copyHeaders(HttpServletRequest from, HttpRequest to);  }
@Test public final void testIllegalQuery() { try { HttpRequestFactory.newJDiscRequest( new MockContainer(), createMockRequest("http", "example.com", "/search", "query=\"contains_quotes\"")); fail("Above statement should throw"); } catch (RequestException e) { assertThat(e.getResponseStatus(), is(Response.Status.BAD_REQUEST)); } }
@Test public final void illegal_host_throws_requestexception1() { try { HttpRequestFactory.newJDiscRequest( new MockContainer(), createMockRequest("http", "?", "/foo", "")); fail("Above statement should throw"); } catch (RequestException e) { assertThat(e.getResponseStatus(), is(Response.Status.BAD_REQUEST)); } }
@Test public final void illegal_host_throws_requestexception2() { try { HttpRequestFactory.newJDiscRequest( new MockContainer(), createMockRequest("http", ".", "/foo", "")); fail("Above statement should throw"); } catch (RequestException e) { assertThat(e.getResponseStatus(), is(Response.Status.BAD_REQUEST)); } }
@Test public final void illegal_host_throws_requestexception3() { try { HttpRequestFactory.newJDiscRequest( new MockContainer(), createMockRequest("http", "*", "/foo", "")); fail("Above statement should throw"); } catch (RequestException e) { assertThat(e.getResponseStatus(), is(Response.Status.BAD_REQUEST)); } }
@Test public final void illegal_unicode_in_query_throws_requestexception() { try { HttpRequestFactory.newJDiscRequest( new MockContainer(), createMockRequest("http", "example.com", "/search", "query=%c0%ae")); fail("Above statement should throw"); } catch (RequestException e) { assertThat(e.getResponseStatus(), is(Response.Status.BAD_REQUEST)); assertThat(e.getMessage(), equalTo("Query violates RFC 2396: Not valid UTF8! byte C0 in state 0")); } }