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));
}
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;
}
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());
}
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));
}
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();
}
Aggregations