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