• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

REST Service - How to send XML Request from Chrome or Intellij's REST Explorer?

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a basic question, perhaps I'm confused, but I have a simple JAX-RS application and we want to send an XML Request, like you would do in Chrome or from any REST explorer.

I have a test "client" program running that works, but it has commands like this:

Response response = client.target("http://localhost:8080/services/customers")
.request().post(Entity.xml(xml));

(using the project's jetty server.)

But, I want to call the service directly from the REST explorer.

So, if you have an XML Request like the one in the JAX-RS 2.0 Book (ch 3), how would you "POST" it to the JAX-RS Service?

Here's the XML Request from the book, from the client code class:

String xml = "<customer>"
+ "<first-name>Bill</first-name>"
+ "<last-name>Burke</last-name>"
+ "<street>256 Clarendon Street</street>"
+ "<city>Boston</city>"
+ "<state>MA</state>"
+ "<zip>02115</zip>"
+ "<country>USA</country>"
+ "</customer>";

So, said another way, I just want to call the REST web service with a REST client and pass the XML Request for a POST.

I took the commented Customer string above and used this as a test to POST as the customer XML:

The REQUEST I USED:
===============

<customer>
<first-name>Bill</first-name>
<last-name>Burke</last-name>
<street>256 Clarendon Street</street>
<city>Boston</city>
<state>MA</state>
<zip>02115</zip>
<country>USA</country>
</customer>

==================

Then, in Intellij's REST Explorer, I have the path to the customer (and the web apps name), like this:

http://localhost:8080/jaxrs-2.0-workbook-ex03_1-2.0/services/customers

(this URL path is for the deployed service in Tomcat.)

I put the Customer XML from above in as the Request and tried to do a POST.

But I get an "Empty Response" return (but not an error).

The application class has this setup:

@ApplicationPath("/services")
public class ShoppingApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();

----------

Here's the actual code in the service class:

@Path("/customers")
public class CustomerResource
.
.
.
@POST
@Consumes("application/xml")
public Response createCustomer(InputStream is)
{
Customer customer = readCustomer(is);
customer.setId(idCounter.incrementAndGet());
customerDB.put(customer.getId(), customer);
System.out.println("Created customer " + customer.getId());
return Response.created(URI.create("/customers/" + customer.getId())).build() ;

}

For simplicity, this example uses a ConncurrentHashMap as a "database".

-----

Do I need to wrap the Request XML with some tag to help things along or am I totally confused?

Thanks very much in advance.

- mike
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic