Search in sources :

Example 61 with UriInfo

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());
}
Also used : UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 62 with UriInfo

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();
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Message(org.apache.cxf.message.Message) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) UriInfoImpl(org.apache.cxf.jaxrs.impl.UriInfoImpl)

Example 63 with UriInfo

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));
        }
    }
}
Also used : UriInfo(javax.ws.rs.core.UriInfo)

Example 64 with UriInfo

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);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) ServletRequest(javax.servlet.ServletRequest) HttpHeaders(javax.ws.rs.core.HttpHeaders) MediaType(javax.ws.rs.core.MediaType) UriInfo(javax.ws.rs.core.UriInfo) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Example 65 with UriInfo

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());
}
Also used : Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)105 Response (javax.ws.rs.core.Response)50 Test (org.junit.Test)49 URI (java.net.URI)32 Test (org.testng.annotations.Test)21 Map (java.util.Map)15 MediaType (javax.ws.rs.core.MediaType)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Context (javax.ws.rs.core.Context)12 Request (org.apache.atlas.catalog.Request)12 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)12 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)12 MetadataService (org.apache.atlas.services.MetadataService)12 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)12 PathParam (javax.ws.rs.PathParam)11 ArrayList (java.util.ArrayList)10 Api (io.swagger.annotations.Api)8 ApiOperation (io.swagger.annotations.ApiOperation)8