Search in sources :

Example 1 with PathSegment

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

the class UriRoutingContextTest method testGetPathSegmentsMultipleSlash.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
     */
@Test
public void testGetPathSegmentsMultipleSlash() {
    final UriInfo ui = createContext("/p//p//p//", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(7, segments.size());
    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;
    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 2 with PathSegment

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

the class UriRoutingContextTest method testGetPathSegmentsMultipleSlashmulitpleMatrix.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
     */
@Test
public void testGetPathSegmentsMultipleSlashmulitpleMatrix() {
    final UriInfo ui = createContext("/;x=1;y=1/;x=2;y=2/;x=3;y=3", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(3, segments.size());
    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;
    segment = psi.next();
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    assertEquals("1", m.getFirst("x"));
    assertEquals("1", m.getFirst("y"));
    segment = psi.next();
    m = segment.getMatrixParameters();
    assertEquals("2", m.getFirst("x"));
    assertEquals("2", m.getFirst("y"));
    segment = psi.next();
    m = segment.getMatrixParameters();
    assertEquals("3", m.getFirst("x"));
    assertEquals("3", m.getFirst("y"));
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 3 with PathSegment

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

the class UriRoutingContextTest method testGetPathSegmentsGeneral.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
     */
@Test
public void testGetPathSegmentsGeneral() {
    final UriInfo ui = createContext("/p1;x=1;y=1/p2;x=2;y=2/p3;x=3;y=3", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(3, segments.size());
    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;
    segment = psi.next();
    assertEquals("p1", segment.getPath());
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    assertEquals("1", m.getFirst("x"));
    assertEquals("1", m.getFirst("y"));
    segment = psi.next();
    assertEquals("p2", segment.getPath());
    m = segment.getMatrixParameters();
    assertEquals("2", m.getFirst("x"));
    assertEquals("2", m.getFirst("y"));
    segment = psi.next();
    assertEquals("p3", segment.getPath());
    m = segment.getMatrixParameters();
    assertEquals("3", m.getFirst("x"));
    assertEquals("3", m.getFirst("y"));
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 4 with PathSegment

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

the class UriRoutingContextTest method testGetPathSegmentsMultipleMatrix.

/**
     * Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}.
     */
@Test
public void testGetPathSegmentsMultipleMatrix() {
    final UriInfo ui = createContext("/p;x=1;x=2;x=3", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(1, segments.size());
    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;
    segment = psi.next();
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    List<String> values = m.get("x");
    for (int i = 0; i < m.size(); i++) {
        assertEquals(Integer.valueOf(i + 1).toString(), values.get(i));
    }
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 5 with PathSegment

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

the class UriConnegFilter method filter.

@Override
public void filter(final ContainerRequestContext rc) throws IOException {
    final UriInfo uriInfo = rc.getUriInfo();
    // Quick check for a '.' character
    String path = uriInfo.getRequestUri().getRawPath();
    if (path.indexOf('.') == -1) {
        return;
    }
    final List<PathSegment> l = uriInfo.getPathSegments(false);
    if (l.isEmpty()) {
        return;
    }
    // Get the last non-empty path segment
    PathSegment segment = null;
    for (int i = l.size() - 1; i >= 0; i--) {
        segment = l.get(i);
        if (segment.getPath().length() > 0) {
            break;
        }
    }
    if (segment == null) {
        return;
    }
    final int length = path.length();
    // Get the suffixes
    final String[] suffixes = segment.getPath().split("\\.");
    for (int i = suffixes.length - 1; i >= 1; i--) {
        final String suffix = suffixes[i];
        if (suffix.length() == 0) {
            continue;
        }
        final MediaType accept = mediaTypeMappings.get(suffix);
        if (accept != null) {
            rc.getHeaders().putSingle(HttpHeaders.ACCEPT, accept.toString());
            final int index = path.lastIndexOf('.' + suffix);
            path = new StringBuilder(path).delete(index, index + suffix.length() + 1).toString();
            suffixes[i] = "";
            break;
        }
    }
    for (int i = suffixes.length - 1; i >= 1; i--) {
        final String suffix = suffixes[i];
        if (suffix.length() == 0) {
            continue;
        }
        final String acceptLanguage = languageMappings.get(suffix);
        if (acceptLanguage != null) {
            rc.getHeaders().putSingle(HttpHeaders.ACCEPT_LANGUAGE, acceptLanguage);
            final int index = path.lastIndexOf('.' + suffix);
            path = new StringBuilder(path).delete(index, index + suffix.length() + 1).toString();
            suffixes[i] = "";
            break;
        }
    }
    if (length != path.length()) {
        rc.setRequestUri(uriInfo.getRequestUriBuilder().replacePath(path).build());
    }
}
Also used : MediaType(javax.ws.rs.core.MediaType) PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo)

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