Ejemplo n.º 1
0
 public static MockHttpRequest deepCopy(HttpRequest request) throws IOException {
   MockHttpRequest mock = new MockHttpRequest();
   mock.uri = request.getUri();
   mock.httpHeaders = (ResteasyHttpHeaders) request.getHttpHeaders();
   mock.httpMethod = request.getHttpMethod();
   byte[] bytes = ReadFromStream.readFromStream(1024, request.getInputStream());
   mock.inputStream = new ByteArrayInputStream(bytes);
   return mock;
 }
Ejemplo n.º 2
0
  private static MockHttpRequest initWithUri(URI absoluteUri, URI baseUri) {
    if (baseUri == null) baseUri = EMPTY_URI;
    MockHttpRequest request = new MockHttpRequest();
    request.httpHeaders = new ResteasyHttpHeaders(new CaseInsensitiveMap<String>());
    // request.uri = new UriInfoImpl(absoluteUri, absoluteUri, absoluteUri.getPath(),
    // absoluteUri.getQuery(), PathSegmentImpl.parseSegments(absoluteUri.getPath()));

    // remove query part
    URI absolutePath = UriBuilder.fromUri(absoluteUri).replaceQuery(null).build();
    // path must be relative to the application's base uri
    URI relativeUri = baseUri.relativize(absoluteUri);
    relativeUri =
        UriBuilder.fromUri(relativeUri.getRawPath())
            .replaceQuery(absoluteUri.getRawQuery())
            .build();

    request.uri = new ResteasyUriInfo(baseUri, relativeUri);
    return request;
  }