Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clientConfig = new DefaultClientConfig();
- client = Client.create(clientConfig);
- resource = client.resource("http://localhost:8080");
- // lets get the XML as a String
- String text = resource("foo").accept("application/xml").get(String.class);
- private void updateCustomer(Customer customer) {
- try {
- URL url = new URL("http://www.example.com/customers");
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setDoOutput(true);
- connection.setInstanceFollowRedirects(false);
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type", "application/xml");
- OutputStream os = connection.getOutputStream();
- jaxbContext.createMarshaller().marshal(customer, os);
- os.flush();
- connection.getResponseCode();
- connection.disconnect();
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
- }
- WebResource resource = client.resource("http://www.example.com/customers");
- ClientResponse response = resource.type("application/xml");).put(ClientResponse.class, "<customer>...</customer.");
- System.out.println(response);
- // Make a GET request to "/lotto"
- String json = get("/lotto").asString()
- // Parse the JSON response
- List<String> winnderIds = with(json).get("lotto.winners.winnerId");
- // Make a POST request to "/shopping"
- String xml = post("/shopping").andReturn().body().asString()
- // Parse the XML
- Node category = with(xml).get("shopping.category[0]");
Add Comment
Please, Sign In to add comment