Search in sources :

Example 1 with AcceptableMediaType

use of org.glassfish.jersey.message.internal.AcceptableMediaType in project jersey by jersey.

the class AcceptMediaTypeProviderTest method testFirefoxAcceptHeader.

@Test
public void testFirefoxAcceptHeader() throws Exception {
    String header = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    List<AcceptableMediaType> l = HttpHeaderReader.readAcceptMediaType(header);
    assertEquals(7, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(1);
    assertEquals("application", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("application", m.getType());
    assertEquals("xhtml+xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(3);
    assertEquals("image", m.getType());
    assertEquals("png", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(4);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(5);
    assertEquals("text", m.getType());
    assertEquals("plain", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(6);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(1, m.getParameters().size());
}
Also used : AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) MediaType(javax.ws.rs.core.MediaType) AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) Test(org.junit.Test)

Example 2 with AcceptableMediaType

use of org.glassfish.jersey.message.internal.AcceptableMediaType in project jersey by jersey.

the class AcceptMediaTypeProviderTest method testWithStarAcceptHeader.

@Test
public void testWithStarAcceptHeader() throws Exception {
    String header = "application/xml;q=0.1, text/xml;q=0.2, *;q=0.3";
    List<AcceptableMediaType> l = HttpHeaderReader.readAcceptMediaType(header);
    assertEquals(3, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(1);
    assertEquals("text", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(2);
    assertEquals("application", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(1, m.getParameters().size());
}
Also used : AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) MediaType(javax.ws.rs.core.MediaType) AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) Test(org.junit.Test)

Example 3 with AcceptableMediaType

use of org.glassfish.jersey.message.internal.AcceptableMediaType in project jersey by jersey.

the class AcceptMediaTypeProviderTest method testFirefoxAcceptHeaderWithPrority2.

@Test
public void testFirefoxAcceptHeaderWithPrority2() throws Exception {
    String header = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    List<AcceptableMediaType> l = HttpHeaderReader.readAcceptMediaType(header, HttpHeaderReader.readQualitySourceMediaType(new String[] { "text/html;qs=0.8", "application/xml;qs=0.1" }));
    assertEquals(7, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(1);
    assertEquals("application", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("text", m.getType());
    assertEquals("xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(3);
    assertEquals("application", m.getType());
    assertEquals("xhtml+xml", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(4);
    assertEquals("image", m.getType());
    assertEquals("png", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(5);
    assertEquals("text", m.getType());
    assertEquals("plain", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(6);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(1, m.getParameters().size());
}
Also used : AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) MediaType(javax.ws.rs.core.MediaType) AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) Test(org.junit.Test)

Example 4 with AcceptableMediaType

use of org.glassfish.jersey.message.internal.AcceptableMediaType in project jersey by jersey.

the class AcceptMediaTypeProviderTest method testMediaTypeSpecifityHTTPExample2.

@Test
public void testMediaTypeSpecifityHTTPExample2() throws Exception {
    String header = "text/*, text/html;level=1, text/html, */*";
    List<AcceptableMediaType> l = HttpHeaderReader.readAcceptMediaType(header);
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(1);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("text", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(3);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(0, m.getParameters().size());
}
Also used : AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) MediaType(javax.ws.rs.core.MediaType) AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) Test(org.junit.Test)

Example 5 with AcceptableMediaType

use of org.glassfish.jersey.message.internal.AcceptableMediaType in project jersey by jersey.

the class AcceptMediaTypeProviderTest method testHttpURLConnectionAcceptHeaderWithPrority.

@Test
public void testHttpURLConnectionAcceptHeaderWithPrority() throws Exception {
    String header = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
    List<AcceptableMediaType> l = HttpHeaderReader.readAcceptMediaType(header, HttpHeaderReader.readQualitySourceMediaType(MediaType.TEXT_HTML));
    assertEquals(5, l.size());
    MediaType m;
    m = l.get(0);
    assertEquals("text", m.getType());
    assertEquals("html", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(1);
    assertEquals("image", m.getType());
    assertEquals("gif", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(2);
    assertEquals("image", m.getType());
    assertEquals("jpeg", m.getSubtype());
    assertEquals(0, m.getParameters().size());
    m = l.get(3);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(1, m.getParameters().size());
    m = l.get(4);
    assertEquals("*", m.getType());
    assertEquals("*", m.getSubtype());
    assertEquals(1, m.getParameters().size());
}
Also used : AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) MediaType(javax.ws.rs.core.MediaType) AcceptableMediaType(org.glassfish.jersey.message.internal.AcceptableMediaType) Test(org.junit.Test)

Aggregations

MediaType (javax.ws.rs.core.MediaType)17 AcceptableMediaType (org.glassfish.jersey.message.internal.AcceptableMediaType)17 Test (org.junit.Test)14 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)2 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 HttpMethod (javax.ws.rs.HttpMethod)1 NotAcceptableException (javax.ws.rs.NotAcceptableException)1 NotAllowedException (javax.ws.rs.NotAllowedException)1 NotSupportedException (javax.ws.rs.NotSupportedException)1 WriterModel (org.glassfish.jersey.message.WriterModel)1 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)1 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)1 Invocable (org.glassfish.jersey.server.model.Invocable)1