Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Ranch Hand
Posts: 1523
  • Mark post as helpful
  • send pies
  • 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 ="http://localhost:8080/services/customers")

(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:


<street>256 Clarendon Street</street>


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


(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:

public class ShoppingApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();


Here's the actual code in the service class:

public class CustomerResource
public Response createCustomer(InputStream is)
Customer customer = readCustomer(is);
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
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!