Search in sources :

Example 46 with PathSegment

use of javax.ws.rs.core.PathSegment in project cxf by apache.

the class JAXRSUtilsTest method testMatrixAndPathSegmentParameters.

@Test
public void testMatrixAndPathSegmentParameters() throws Exception {
    Class<?>[] argType = { PathSegment.class, String.class };
    Method m = Customer.class.getMethod("testPathSegment", argType);
    Message messageImpl = createMessage();
    messageImpl.put(Message.REQUEST_URI, "/bar%20foo;p4=0%201");
    MultivaluedMap<String, String> values = new MetadataMap<String, String>();
    values.add("ps", "bar%20foo;p4=0%201");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), values, messageImpl);
    assertEquals("2 params should've been identified", 2, params.size());
    PathSegment ps = (PathSegment) params.get(0);
    assertEquals("bar foo", ps.getPath());
    assertEquals(1, ps.getMatrixParameters().size());
    assertEquals("0 1", ps.getMatrixParameters().getFirst("p4"));
    assertEquals("bar foo", params.get(1));
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) PathSegment(javax.ws.rs.core.PathSegment) Test(org.junit.Test)

Example 47 with PathSegment

use of javax.ws.rs.core.PathSegment in project cxf by apache.

the class JAXRSUtils method processMatrixParam.

private static Object processMatrixParam(Message m, String key, Class<?> pClass, Type genericType, Annotation[] paramAnns, String defaultValue, boolean decode) {
    List<PathSegment> segments = JAXRSUtils.getPathSegments((String) m.get(Message.REQUEST_URI), decode);
    if (!segments.isEmpty()) {
        MultivaluedMap<String, String> params = new MetadataMap<String, String>();
        for (PathSegment ps : segments) {
            MultivaluedMap<String, String> matrix = ps.getMatrixParameters();
            for (Map.Entry<String, List<String>> entry : matrix.entrySet()) {
                for (String value : entry.getValue()) {
                    params.add(entry.getKey(), value);
                }
            }
        }
        if ("".equals(key)) {
            return InjectionUtils.handleBean(pClass, paramAnns, params, ParameterType.MATRIX, m, false);
        }
        List<String> values = params.get(key);
        return InjectionUtils.createParameterObject(values, pClass, genericType, paramAnns, defaultValue, false, ParameterType.MATRIX, m);
    }
    return null;
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) PathSegment(javax.ws.rs.core.PathSegment) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 48 with PathSegment

use of javax.ws.rs.core.PathSegment in project cxf by apache.

the class PathSegmentImplTest method testPlainPathSegment.

@Test
public void testPlainPathSegment() {
    PathSegment ps = new PathSegmentImpl("bar");
    assertEquals("bar", ps.getPath());
    assertEquals(0, ps.getMatrixParameters().size());
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) Test(org.junit.Test)

Example 49 with PathSegment

use of javax.ws.rs.core.PathSegment in project cxf by apache.

the class PathSegmentImplTest method testPathSegmentWithDecodedMatrixParams.

@Test
public void testPathSegmentWithDecodedMatrixParams() {
    PathSegment ps = new PathSegmentImpl("bar%20foo;a=1%202");
    assertEquals("bar foo", ps.getPath());
    MultivaluedMap<String, String> params = ps.getMatrixParameters();
    assertEquals(1, params.size());
    assertEquals(1, params.get("a").size());
    assertEquals("1 2", params.get("a").get(0));
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) Test(org.junit.Test)

Example 50 with PathSegment

use of javax.ws.rs.core.PathSegment in project OpenOLAT by OpenOLAT.

the class SharedFolderWebService method getFiles.

public Response getFiles(Long repoEntryKey, List<PathSegment> path, UriInfo uriInfo, HttpServletRequest httpRequest, Request request) {
    RepositoryEntry re = repositoryManager.lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(re, true);
    if (container == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!repositoryManager.isAllowedToLaunch(RestSecurityHelper.getIdentity(httpRequest), RestSecurityHelper.getRoles(httpRequest), re)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    VFSLeaf leaf = null;
    for (PathSegment seg : path) {
        VFSItem item = container.resolve(seg.getPath());
        if (item instanceof VFSLeaf) {
            leaf = (VFSLeaf) item;
            break;
        } else if (item instanceof VFSContainer) {
            container = (VFSContainer) item;
        }
    }
    if (leaf != null) {
        Date lastModified = new Date(leaf.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            String mimeType = WebappHelper.getMimeType(leaf.getName());
            if (mimeType == null)
                mimeType = MediaType.APPLICATION_OCTET_STREAM;
            response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
        }
        return response.build();
    }
    List<VFSItem> items = container.getItems(new SystemItemFilter());
    int count = 0;
    LinkVO[] links = new LinkVO[items.size()];
    for (VFSItem item : items) {
        UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        UriBuilder repoUri = baseUriBuilder.path(SharedFolderWebService.class).path(repoEntryKey.toString()).path("files");
        for (PathSegment pathSegment : path) {
            repoUri.path(pathSegment.getPath());
        }
        String uri = repoUri.path(item.getName()).build().toString();
        links[count++] = new LinkVO("self", uri, item.getName());
    }
    return Response.ok(links).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) RepositoryEntry(org.olat.repository.RepositoryEntry) PathSegment(javax.ws.rs.core.PathSegment) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date) Response(javax.ws.rs.core.Response) LinkVO(org.olat.restapi.support.vo.LinkVO) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

PathSegment (javax.ws.rs.core.PathSegment)67 UriInfo (javax.ws.rs.core.UriInfo)19 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)12 Map (java.util.Map)11 UriBuilder (javax.ws.rs.core.UriBuilder)11 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 Response (javax.ws.rs.core.Response)9 HashMap (java.util.HashMap)7 List (java.util.List)7 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)6 URL (java.net.URL)5 TreeMap (java.util.TreeMap)5 UUID (java.util.UUID)5 OutputStream (java.io.OutputStream)4