Skip to content

Commit

Permalink
RESTEASY-1118
Browse files Browse the repository at this point in the history
  • Loading branch information
patriot1burke committed Oct 23, 2014
1 parent 7b9e238 commit a489c8c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
Expand Up @@ -77,9 +77,24 @@ else if (requestContext.getUriInfo().getPath().contains("setrequesturi1"))
requestContext.setRequestUri(
requestContext.getUriInfo().getRequestUriBuilder().path("uri").build());
}
else if (requestContext.getUriInfo().getPath().contains("setrequesturi2"))
{
requestContext.setRequestUri(URI.create("http://localhost:888/otherbase"), URI.create("http://xx.yy:888/base/resource/sub"));
UriInfo info = requestContext.getUriInfo();
abortWithEntity(requestContext, info.getAbsolutePath().toASCIIString());

}


}

protected void abortWithEntity(ContainerRequestContext requestContext, String entity) {
StringBuilder sb = new StringBuilder();
sb.append(entity);
Response response = Response.ok(sb.toString()).build();
requestContext.abortWith(response);
}

}

static Client client;
Expand Down Expand Up @@ -119,10 +134,18 @@ public void testSchemaChange() {
@Test
public void testResolve()
{
URI base = URI.create("http://localhost:888/otherbase");
URI uri = URI.create("http://xx.yy:888/base/resource/sub");
{
URI base = URI.create("http://localhost:888/otherbase");
URI uri = URI.create("http://xx.yy:888/base/resource/sub?foo=bar");

System.out.println(base.resolve(uri));
}
{
URI base = URI.create("https://localhost:888/base");
URI uri = URI.create("https://localhost:888/base/resource/change");

System.out.println(base.resolve(uri));
System.out.println(base.resolve(uri));
}

}

Expand All @@ -136,5 +159,13 @@ public void testUriOverride()
Assert.assertEquals("OK", response.readEntity(String.class));

}
@Test
public void testUriOverride2()
{
Response response = client.target(generateURL("/base/resource/setrequesturi2")).request().get();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals("http://xx.yy:888/base/resource/sub", response.readEntity(String.class));

}

}
Expand Up @@ -102,21 +102,9 @@ public ResteasyUriInfo(URI base, URI relative)

public void setUri(URI base, URI relative)
{
String contextPath = base.getRawPath();
String relativePath = relative.getRawPath();

if (relativePath.startsWith(contextPath))
{
relativePath = relativePath.substring(contextPath.length());

}
else
{
relativePath = "";
}

String absoluteUri = UriBuilder.fromUri(base).path(relativePath).replaceQuery(null).toTemplate();
initialize(absoluteUri, relative.getRawQuery(), contextPath);
URI rel = base.resolve(relative);
String absoluteUri = UriBuilder.fromUri(rel).replaceQuery(null).toTemplate();
initialize(absoluteUri, rel.getRawQuery(), base.getRawPath());
}

protected void processPath()
Expand Down

0 comments on commit a489c8c

Please sign in to comment.