use of org.jboss.resteasy.specimpl.ResteasyUriInfo in project policies-ui-backend by RedHatInsights.
the class PagingUtilsTest method extractPagerInvalidOffset.
@Test
void extractPagerInvalidOffset() throws URISyntaxException {
UriInfo info = new ResteasyUriInfo(new URI("https://foo?offset=bar&limit=100"));
assertThrows(IllegalArgumentException.class, () -> {
PagingUtils.extractPager(info);
});
}
use of org.jboss.resteasy.specimpl.ResteasyUriInfo in project resteasy by resteasy.
the class HttpExchangeUtil method extractUriInfo.
public static ResteasyUriInfo extractUriInfo(HttpExchange exchange) {
String host = exchange.getLocalAddress().getHostName();
if (exchange.getLocalAddress().getPort() != 80 && exchange.getLocalAddress().getPort() != 443) {
host += ":" + exchange.getLocalAddress().getPort();
}
String uri = exchange.getRequestURI().toString();
String protocol = exchange.getHttpContext().getServer() instanceof HttpsServer ? "https" : "http";
URI absoluteURI = URI.create(protocol + "://" + host + uri);
String contextPath = exchange.getHttpContext().getPath();
String path = PathHelper.getEncodedPathInfo(absoluteURI.getRawPath(), contextPath);
if (!path.startsWith("/")) {
path = "/" + path;
}
URI baseURI = absoluteURI;
if (!path.trim().equals("")) {
String tmpContextPath = contextPath;
if (!tmpContextPath.endsWith("/"))
tmpContextPath += "/";
baseURI = UriBuilder.fromUri(absoluteURI).replacePath(tmpContextPath).replaceQuery(null).build();
} else {
baseURI = UriBuilder.fromUri(absoluteURI).replaceQuery(null).build();
}
URI relativeURI = UriBuilder.fromUri(path).replaceQuery(absoluteURI.getRawQuery()).build();
// System.out.println("path: " + path);
// System.out.println("query string: " + request.getQueryString());
ResteasyUriInfo uriInfo = new ResteasyUriInfo(baseURI, relativeURI);
return uriInfo;
}
use of org.jboss.resteasy.specimpl.ResteasyUriInfo in project resteasy by resteasy.
the class VertxRequestHandler method handle.
@Override
public void handle(HttpServerRequest request) {
request.bodyHandler(buff -> {
Context ctx = vertx.getOrCreateContext();
ResteasyUriInfo uriInfo = VertxUtil.extractUriInfo(request, servletMappingPrefix);
HttpServerResponse response = request.response();
VertxHttpResponse vertxResponse = new VertxHttpResponse(response, dispatcher.getProviderFactory(), request.method());
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx, request, uriInfo, dispatcher.getDispatcher(), vertxResponse, false);
if (buff.length() > 0) {
ByteBufInputStream in = new ByteBufInputStream(buff.getByteBuf());
vertxRequest.setInputStream(in);
}
try {
dispatcher.service(ctx, request, response, vertxRequest, vertxResponse, true);
} catch (Failure e1) {
vertxResponse.setStatus(e1.getErrorCode());
} catch (Exception ex) {
vertxResponse.setStatus(500);
LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), ex);
}
if (!vertxRequest.getAsyncContext().isSuspended()) {
try {
vertxResponse.finish();
} catch (IOException e) {
LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), e);
}
}
});
}
use of org.jboss.resteasy.specimpl.ResteasyUriInfo in project resteasy by resteasy.
the class ServletUtilTest method extractUriInfo_encoded.
@Test
public void extractUriInfo_encoded() {
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getContextPath()).thenReturn("");
when(request.getQueryString()).thenReturn(null);
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app/resource!"));
ResteasyUriInfo rui = ServletUtil.extractUriInfo(request, null);
assertEquals("", rui.getContextPath());
assertEquals("/app/resource!", rui.getPath());
request = mock(HttpServletRequest.class);
when(request.getContextPath()).thenReturn("");
when(request.getQueryString()).thenReturn(null);
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app/resource%21"));
rui = ServletUtil.extractUriInfo(request, null);
assertEquals("", rui.getContextPath());
assertEquals("/app/resource!", rui.getPath());
request = mock(HttpServletRequest.class);
when(request.getContextPath()).thenReturn("");
when(request.getQueryString()).thenReturn(null);
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app!/resource"));
rui = ServletUtil.extractUriInfo(request, null);
assertEquals("", rui.getContextPath());
assertEquals("/app!/resource", rui.getPath());
request = mock(HttpServletRequest.class);
when(request.getContextPath()).thenReturn("");
when(request.getQueryString()).thenReturn(null);
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app%21/resource"));
rui = ServletUtil.extractUriInfo(request, null);
assertEquals("", rui.getContextPath());
assertEquals("/app!/resource", rui.getPath());
}
use of org.jboss.resteasy.specimpl.ResteasyUriInfo in project resteasy by resteasy.
the class ServletUtilTest method extractUriInfo_simple.
@Test
public void extractUriInfo_simple() {
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getContextPath()).thenReturn("");
when(request.getQueryString()).thenReturn(null);
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app/resource"));
ResteasyUriInfo rui = ServletUtil.extractUriInfo(request, null);
assertEquals("", rui.getContextPath());
assertEquals("/app/resource", rui.getPath());
}
Aggregations