APISonar


javax.ws.rs.client.Entity.xml

> javax > ws > rs > client > Entity > xml
javax APIs ws APIs rs APIs client APIs Entity APIs xml APIs

Example 1
public void postWithValidation() throws Exception {
        Book book = new Book();
        book.setId(-1);
        book.setName(null);
        Response response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
        Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());

        book = new Book();
        book.setId(3212);
        book.setName("A Book");
        response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
        Assert.assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
        Assert.assertNotNull(response.getLocation());
    }
Example 2
public void testThatValidationConstraintsAreViolatedWithBook(Map<String, String> param, StringBuilder ret) throws Exception {
        String uri = getAddress("bookstore/books/direct");

        BookWithValidation request = new BookWithValidation("BeanVal");
        int code;
        try {
            WebTarget target = client.target(uri);
            Response resp = target.request().accept("application/xml").post(Entity.xml(request));
            code = resp.getStatus();
        } catch (Exception e) {
            code = -1;
        }
        assertEquals(Status.BAD_REQUEST.getStatusCode(), code);
        ret.append("OK");
    }
Example 3
public void testPost() throws Exception {
      ResteasyWebTarget target = client.target(generateURL(""));
      String xmlInput = "<?xml version=\"1.0\"?><abstractJaxbClassPerson><name>bill</name></abstractJaxbClassPerson>";
      Response response = target.request().post(Entity.xml(xmlInput));
      Assert.assertEquals(HttpResponseCodes.SC_NO_CONTENT, response.getStatus());
      response.close();

      ResteasyWebTarget target2 = client.target(generateURL("/customer"));
      Response response2 = target2.request().post(Entity.entity(customerXml, "application/xml"));
      Assert.assertEquals(204, response2.getStatus());
      response2.close();
   }
Example 4
public void testRetrieveBookCustomMethodAsync() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/retrieve";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        Future<Book> book = wc.async().method("RETRIEVE", Entity.xml(new Book("Retrieve", 123L)),
                                              Book.class);
        assertEquals("Retrieve", book.get().getName());
        wc.close();
    }
Example 5
private void runTest(String url) throws Exception {
      JAXBContext ctx = JAXBContext.newInstance(SeeAlsoAnnotationRealFoo.class);
      StringWriter writer = new StringWriter();
      SeeAlsoAnnotationRealFoo foo = new SeeAlsoAnnotationRealFoo();
      foo.setName("bill");

      ctx.createMarshaller().marshal(foo, writer);

      String s = writer.getBuffer().toString();
      logger.info(s);

      ResteasyWebTarget target = client.target(generateURL(url));
      target.request().header("Content-Type", "application/xml").put(Entity.xml(s));
   }
Example 6
public void testBadWrapped() throws Exception {
      String xml = "<resteasy:map xmlns:resteasy=\"http://jboss.org/resteasy\">"
            + "<resteasy:entry key=\"bill\" xmlns=\"http://foo.com\">"
            + "<mapFoo name=\"bill\"/></resteasy:entry>"
            + "<resteasy:entry key=\"monica\" xmlns=\"http://foo.com\">"
            + "<mapFoo name=\"monica\"/></resteasy:entry>"
            + "</resteasy:map>";

      ResteasyWebTarget target = client.target(generateURL("/map/wrapped"));
      Response response = target.request().post(Entity.xml(xml));
      Assert.assertEquals(HttpResponseCodes.SC_BAD_REQUEST, response.getStatus());

   }
Example 7
public void testList() throws Exception {
      String xml = "<list>"
            + "<foo test=\"hello\"/></list>";

      ResteasyWebTarget target = client.target(generateURL("/list"));
      Response response = target.request().post(Entity.xml(xml));
      JaxbCollectionFoo[] list = response.readEntity(new javax.ws.rs.core.GenericType<JaxbCollectionFoo[]>() {
      });
      Assert.assertEquals("The response doesn't contain 1 item, which is expected", 1, list.length);
      Assert.assertEquals("The response doesn't contain correct element value", list[0].getTest(), "hello");
      response.close();

   }
Example 8
public void testWriter() {
      JAXBElement<String> element = new JAXBElement<String>(new QName(""),
            String.class, JaxbElementResource.class.getName());
      Response response = client.target(generateURL("/resource/standardwriter")).request().post(Entity.xml(element));
      Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
      response.close();
   }
Example 9
public void testPut() {
        final Response putResponse = target().request().put(Entity.xml(new Person("Jules", 12, "Paris")));
        assertEquals(204, putResponse.getStatus());
    }
Example 10
public void testXMLRootNoObjectFactoryJAXBElement(Map<String, String> param, StringBuilder ret) throws Exception {
        Person source = null;
        for (Iterator<Person> it = getPersonSource().iterator(); it.hasNext();) {
            source = it.next();
        }
        Response resp = client.target(getAddress("personjaxbelement")).request(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(Entity.xml(source));
        Person responseEntity = resp.readEntity(Person.class);

        verifyResponse(responseEntity, Person.class);
        ret.append("OK");
    }
Example 11
public void testXMLRootWithObjectFactoryList(Map<String, String> param, StringBuilder ret) throws Exception {
        List<Book> source = getBookSource();
        Response resp = client.target(getAddress("booklist")).request(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(Entity.xml(source));
        List<Book> responseEntity = resp.readEntity(new GenericType<List<Book>>() {});

        verifyResponse(responseEntity, Book.class);
        ret.append("OK");
    }
Example 12
public void testXml() {
      ResteasyClient client = (ResteasyClient)ClientBuilder.newClient();
      ResteasyWebTarget target = client.target(generateURL("/xml"));
      String response = target.request().post(Entity.xml(null), String.class);
      Assert.assertEquals("Wrong response", "", response);
      client.close();
   }
Example 13
public void testPostBookAsync(Map<String, String> param, StringBuilder ret) throws Exception {
        String address = getAddress("bookstore/bookheaders/simple/async");
        WebClient wc = createWebClientPost(address);
        Future<Book> future = wc.async().post(Entity.xml(new Book("Book", 126L)), Book.class);
        assertEquals(124L, future.get().getId());
        validatePostResponse(wc, true);
        ret.append("OK");
    }
Example 14
public void testMarshallering() throws Exception {

      String xmlStr = "<user xmlns=\"http://creaity.de/homecontrol/rest/types/v1\"> <id>id</id>"
              + " <credentials> <loginId>test</loginId> </credentials>"
              + " <roles><role>USER</role></roles></user>";

      ResteasyWebTarget target = client.target(generateURL("/service/users"));
      Response response = target.request().accept("application/xml").post(Entity.xml(xmlStr));
      UserType entity = response.readEntity(UserType.class);
      Assert.assertNotNull(entity);
      Assert.assertTrue("id DemoService_visited".equals(entity.getId()));
      response.close();
   }
Example 15
public void testPostBookProcessingException() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/";
        List<Object> providers = new ArrayList<Object>();
        providers.add(new FaultyBookWriter());
        WebClient wc = WebClient.create(address, providers);
        
        Future<Book> future = wc.async().post(Entity.xml(new Book()), Book.class);
        try {
            future.get();
            fail("Exception expected");
        } catch (ExecutionException ex) {
            assertTrue(ex.getCause() instanceof ProcessingException);
        }
        wc.close();
    }
Example 16
public void testXMLRootWithObjectFactoryJAXBElement(Map<String, String> param, StringBuilder ret) throws Exception {
        JAXBElement<Employee> source = getEmployeeSource();
        Response resp = client.target(getAddress("employeejaxbelement")).request(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(Entity.xml(source));
        JAXBElement<Employee> responseEntity = resp.readEntity(new GenericType<JAXBElement<Employee>>() {});

        verifyResponse(responseEntity, JAXBElement.class);
        ret.append("OK");
    }
Example 17
public void addCatalog() {
        Response response = services.getCatalogService().request().post(Entity.xml(catalogItem));

        Response.StatusType statusInfo = response.getStatusInfo();
        
        if (statusInfo.getStatusCode() == Response.Status.CREATED.getStatusCode())
            status = "User added successfully";
        else
            status = statusInfo.getReasonPhrase();
    }
Example 18
public void testSyncInvoker_post1(Map<String, String> param, StringBuilder ret) {
        String serverIP = param.get("serverIP");
        String serverPort = param.get("serverPort");
        ClientBuilder cb = ClientBuilder.newBuilder();
        Client c = cb.build();
        WebTarget t = c.target("http://" + serverIP + ":" + serverPort + "/bookstore/bookstore2/post1");
        Builder builder = t.request();
        Book book = new Book("Test book", 100);
        Response response = builder.post(Entity.xml(book));
        ret.append(response.readEntity(String.class));
        c.close();
    }
Example 19
public void testPost() {
        Response response = target(PATH).request(MediaType.APPLICATION_XML_TYPE).post(Entity.xml(new Person("John", "Doe")));
        Person person = response.readEntity(Person.class);
        assertEquals("John Doe", person.toString());
        response = target(PATH).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.xml(new Person("John", "Doe")));
        person = response.readEntity(Person.class);
        assertEquals("John Doe", person.toString());
    }
Example 20
public void testBeansPositive() throws Exception {
        final WebTarget target = target("getter-on-beans");
        final AnotherContactBean contactBean = new AnotherContactBean("jersey@example.com", null, "Jersey JAX-RS", null);

        final Response response = target.request().post(Entity.xml(contactBean));

        assertThat(response.getStatus(), equalTo(200));
        assertThat(response.readEntity(AnotherContactBean.class), equalTo(contactBean));
    }
Example 21
public void noMessageBodyReaderExistsTest() {
      WebTarget base = client.target(generateURL("/") + "senddata");

      thrown.expect(ProcessingException.class);
      base.request().post(Entity.xml(new ClientExceptionsData("test", "test")));

   }
Example 22
public void testPost() {
        final Person[] testData = new Person[] {new Person("Joseph", 23, "Nazareth"), new Person("Mary", 18, "Nazareth") };
        for (Person original : testData) {
            final Person postResponse = target().request().post(Entity.xml(original), Person.class);
            assertEquals(original, postResponse);
        }
    }