use of javax.ws.rs.core.UriInfo in project cxf by apache.
the class UriInfoImplTest method testGetRequestURI.
@Test
public void testGetRequestURI() {
UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo", "n=1%202"), null);
assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo?n=1%202", u.getRequestUri().toString());
}
use of javax.ws.rs.core.UriInfo in project cxf by apache.
the class BookCxfContinuationStore method getContinuation.
private Continuation getContinuation(String name) {
ContinuationProvider provider = (ContinuationProvider) context.get(ContinuationProvider.class.getName());
if (provider == null) {
Message m = PhaseInterceptorChain.getCurrentMessage();
UriInfo uriInfo = new UriInfoImpl(m);
if (uriInfo.getAbsolutePath().toString().contains("/books/subresources/")) {
// when we suspend a CXF continuation from a sub-resource, the invocation will
// return directly to that object - and sub-resources do not have contexts supported
// by default - so we just need to depend on PhaseInterceptorChain
provider = (ContinuationProvider) m.get(ContinuationProvider.class.getName());
}
}
if (provider == null) {
throw new WebApplicationException(500);
}
synchronized (suspended) {
Continuation suspendedCont = suspended.remove(name);
if (suspendedCont != null) {
return suspendedCont;
}
}
return provider.getContinuation();
}
use of javax.ws.rs.core.UriInfo in project cxf by apache.
the class SwaggerUiServiceFilter method filter.
@Override
public void filter(ContainerRequestContext rc) throws IOException {
if (HttpMethod.GET.equals(rc.getRequest().getMethod())) {
UriInfo ui = rc.getUriInfo();
String path = ui.getPath();
int uiPathIndex = path.lastIndexOf("api-docs");
if (uiPathIndex >= 0) {
String resourcePath = uiPathIndex + 8 < path.length() ? path.substring(uiPathIndex + 8) : "";
rc.abortWith(uiService.getResource(ui, resourcePath));
}
}
}
use of javax.ws.rs.core.UriInfo in project cxf by apache.
the class WadlGenerator method doFilter.
protected void doFilter(ContainerRequestContext context, Message m) {
if (!"GET".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
return;
}
UriInfo ui = context.getUriInfo();
if (!ui.getQueryParameters().containsKey(WADL_QUERY)) {
if (stylesheetReference != null || !docLocationMap.isEmpty()) {
String path = ui.getPath(false);
if (path.startsWith("/") && path.length() > 0) {
path = path.substring(1);
}
if (stylesheetReference != null && path.endsWith(".xsl") || docLocationMap.containsKey(path)) {
context.abortWith(getExistingResource(m, ui, path));
}
}
return;
}
if (ignoreRequests) {
context.abortWith(Response.status(404).build());
return;
}
if (whiteList != null && whiteList.size() > 0) {
ServletRequest servletRequest = (ServletRequest) m.getContextualProperty("HTTP.REQUEST");
String remoteAddress = null;
if (servletRequest != null) {
remoteAddress = servletRequest.getRemoteAddr();
} else {
remoteAddress = "";
}
boolean foundMatch = false;
for (String addr : whiteList) {
if (addr.equals(remoteAddress)) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
context.abortWith(Response.status(404).build());
return;
}
}
HttpHeaders headers = new HttpHeadersImpl(m);
List<MediaType> accepts = headers.getAcceptableMediaTypes();
MediaType type = accepts.contains(WADL_TYPE) ? WADL_TYPE : accepts.contains(MediaType.APPLICATION_JSON_TYPE) ? MediaType.APPLICATION_JSON_TYPE : defaultWadlResponseMediaType;
Response response = getExistingWadl(m, ui, type);
if (response != null) {
context.abortWith(response);
return;
}
boolean isJson = isJson(type);
StringBuilder sbMain = generateWADL(getBaseURI(m, ui), getResourcesList(m, ui), isJson, m, ui);
m.getExchange().put(JAXRSUtils.IGNORE_MESSAGE_WRITERS, !isJson && ignoreMessageWriters);
Response r = Response.ok().type(type).entity(createResponseEntity(m, ui, sbMain.toString(), isJson)).build();
context.abortWith(r);
}
use of javax.ws.rs.core.UriInfo in project ORCID-Source by ORCID.
the class T1OrcidApiServiceImplLatestMetricsTest method testSearchByQueryXMLResultsReturned.
@Test
public void testSearchByQueryXMLResultsReturned() {
UriInfo uriInfo = mock(UriInfo.class);
t1OrcidApiService.setUriInfo(uriInfo);
MultivaluedMap<String, String> queryMaps = queryParams();
when(uriInfo.getQueryParameters()).thenReturn(queryMaps);
when(mockServiceDelegator.publicSearchByQuery(queryMaps)).thenReturn(orcidWithMultipleResults());
Response response = t1OrcidApiService.searchByQueryXML("orcid");
assertEquals(200, response.getStatus());
}
Aggregations