use of javax.ws.rs.core.Variant in project jersey by jersey.
the class VariantSelector method getVariantHolderList.
private static LinkedList<VariantHolder> getVariantHolderList(final List<Variant> variants) {
final LinkedList<VariantHolder> l = new LinkedList<>();
for (final Variant v : variants) {
final MediaType mt = v.getMediaType();
if (mt != null) {
if (mt instanceof QualitySourceMediaType || mt.getParameters().containsKey(Quality.QUALITY_SOURCE_PARAMETER_NAME)) {
final int qs = QualitySourceMediaType.getQualitySource(mt);
l.add(new VariantHolder(v, qs));
} else {
l.add(new VariantHolder(v));
}
} else {
l.add(new VariantHolder(v));
}
}
return l;
}
use of javax.ws.rs.core.Variant in project jersey by jersey.
the class ContainerRequest method selectVariant.
// JAX-RS request
@Override
public Variant selectVariant(final List<Variant> variants) throws IllegalArgumentException {
if (variants == null || variants.isEmpty()) {
throw new IllegalArgumentException(METHOD_PARAMETER_CANNOT_BE_NULL_OR_EMPTY);
}
final Ref<String> varyValueRef = Refs.emptyRef();
final Variant variant = VariantSelector.selectVariant(this, variants, varyValueRef);
this.varyValue = varyValueRef.get();
return variant;
}
use of javax.ws.rs.core.Variant in project jersey by jersey.
the class ResponseTest method variantTest.
/*
* Create an instance of Response using
* Response.status(int).variant(Variant).build()
* verify that correct status code is returned
*/
@Test
public void variantTest() {
Response resp;
int status = 200;
List<String> encoding = Arrays.asList("gzip", "compress");
List<String> lang = Arrays.asList("en-US", "en-GB", "zh-CN");
MediaType mt = new MediaType("text", "plain");
List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt).languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).encodings((String[]) encoding.toArray()).add().build();
String tmp;
for (Variant vt : vts) {
resp = Response.status(status).variant(vt).build();
tmp = verifyResponse(resp, null, status, encoding, lang, null, null, null, null);
if (tmp.endsWith("false")) {
System.out.println("### " + tmp);
fail();
}
}
}
use of javax.ws.rs.core.Variant in project jersey by jersey.
the class ResponseTest method testVariants.
// Reproducer for JERSEY-1553
@Test
public void testVariants() {
List<String> encoding = Arrays.asList("gzip", "compress");
List<Variant> list = Variant.VariantListBuilder.newInstance().mediaTypes(MediaType.TEXT_PLAIN_TYPE).languages(new Locale("en", "US"), new Locale("en", "GB")).encodings(encoding.toArray(new String[encoding.size()])).add().build();
final Response r1 = Response.ok().variants(list).build();
assertNotNull(r1);
assertNotNull(r1.getHeaderString(HttpHeaders.VARY));
final Response r2 = Response.ok().variants(list.toArray(new Variant[list.size()])).build();
assertNotNull(r2);
assertNotNull(r2.getHeaderString(HttpHeaders.VARY));
}
use of javax.ws.rs.core.Variant in project jersey by jersey.
the class ResponseTest method OkTest5.
/*
* Create an instance of Response using Response.ok(String, Variant).build()
* verify that correct status code is returned
*/
@Test
public void OkTest5() {
Response resp;
int status = 200;
String content = "Test Only";
List<String> encoding = Arrays.asList("gzip", "compress");
List<String> lang = Arrays.asList("en-US", "en-GB", "zh-CN");
MediaType mt = new MediaType("text", "plain");
List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt).languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).encodings((String[]) encoding.toArray()).add().build();
String tmp;
for (Variant vt : vts) {
resp = Response.ok(content, vt).build();
tmp = verifyResponse(resp, content, status, encoding, lang, null, null, null, null);
if (tmp.endsWith("false")) {
System.out.println("### " + tmp);
fail();
}
}
}
Aggregations