Search in sources :

Example 76 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class MultiPartWebAppTest method testApplicationWadl.

@Test
public void testApplicationWadl() throws Exception {
    final WebTarget target = target().path("application.wadl");
    final Response response = target.request().get();
    assertEquals(200, response.getStatus());
    final File tmpFile = response.readEntity(File.class);
    final DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
    bf.setNamespaceAware(true);
    bf.setValidating(false);
    if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
        bf.setXIncludeAware(false);
    }
    final DocumentBuilder b = bf.newDocumentBuilder();
    final Document d = b.parse(tmpFile);
    final XPath xp = XPathFactory.newInstance().newXPath();
    xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
    String val = (String) xp.evaluate("//wadl:resource[@path='part']/wadl:method[@name='POST']/wadl:request/wadl:representation/@mediaType", d, XPathConstants.STRING);
    assertEquals("multipart/form-data", val);
}
Also used : Response(javax.ws.rs.core.Response) XPath(javax.xml.xpath.XPath) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) WebTarget(javax.ws.rs.client.WebTarget) SimpleNamespaceResolver(org.glassfish.jersey.internal.util.SimpleNamespaceResolver) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 77 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class MultiPartWebAppTest method testFieldInjectedXmlJAXBPart.

@Test
public void testFieldInjectedXmlJAXBPart() {
    final WebTarget target = target().path("form-field-injected/xml-jaxb-part");
    final FormDataMultiPart mp = new FormDataMultiPart();
    mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("bean").fileName("bean").build(), new Bean("BEAN"), MediaType.APPLICATION_XML_TYPE));
    mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("string").fileName("string").build(), "STRING"));
    final String s = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
    assertEquals("STRING:string,BEAN:bean", s);
}
Also used : FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 78 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class JacksonTest method testEmptyArrayPresent.

@Test
public void testEmptyArrayPresent() {
    WebTarget target = target();
    String responseMsg = target.path("emptyArrayResource").request(MediaType.APPLICATION_JSON).get(String.class);
    assertTrue(responseMsg.replaceAll("[ \t]*", "").contains("[]"));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 79 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class JacksonTest method testJSONPBean.

@Test
@Ignore
public // TODO un-ignore once a JSON reader for "application/javascript" is supported
void testJSONPBean() {
    WebTarget target = target();
    NonJaxbBean responseMsg = target.path("nonJaxbResource").request("application/javascript").get(NonJaxbBean.class);
    assertNotNull(responseMsg);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Ignore(org.junit.Ignore) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 80 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class JacksonTest method testJSONPPresent.

@Test
public void testJSONPPresent() {
    WebTarget target = target();
    String responseMsg = target.path("nonJaxbResource").request("application/javascript").get(String.class);
    assertTrue(responseMsg.startsWith("callback("));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

WebTarget (javax.ws.rs.client.WebTarget)1393 Response (javax.ws.rs.core.Response)712 Test (org.junit.Test)702 Client (javax.ws.rs.client.Client)318 JerseyTest (org.glassfish.jersey.test.JerseyTest)297 Invocation (javax.ws.rs.client.Invocation)106 List (java.util.List)76 ProcessingException (javax.ws.rs.ProcessingException)71 Builder (javax.ws.rs.client.Invocation.Builder)71 ClientBuilder (javax.ws.rs.client.ClientBuilder)69 GenericType (javax.ws.rs.core.GenericType)64 ArrayList (java.util.ArrayList)61 IOException (java.io.IOException)59 Message (com.remswork.project.alice.model.support.Message)58 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)58 InputStream (java.io.InputStream)52 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)52 ClientConfig (org.glassfish.jersey.client.ClientConfig)52 Form (javax.ws.rs.core.Form)42 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)42