Homr Zodyssey
Homr Zodyssey

Reputation: 768

How can I use the Broadleaf REST API?

I'm trying to use the REST APIs built into Broadleaf eCommerce. The instructions on their site say to add a reference to /WEB-INF/applicationContext-rest-api.xml in web.xml, but /WEB-INF/applicationContext-rest-api.xml doesn't exist. It was renamed on January 14, 2015 by @phillipuniverse. The current web.xml from the DemoSite has a reference to the new filename (applicationContext-rest-api-security.xml). So, it seems like nothing needs to be done to enable REST -- they are enabled by default.

However, when I try to access them, I get:

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'null' not supported

I really am sending a Content-Type header. This appears to be an incorrect exception based on a known bug in Jackson. It has something to do with types not being serializable.

I think that means the wrapper classes need to be fixed. They are what gets serialized. (right?) I'm trying to figure out if this is because I'm doing something wrong, or if it's a bug in BroadleafCommerce.

Also, I'm kinda new with Maven, so I'm not sure how to go about trying to fix this. The DemoSite pulls BroadLeafCommerce from a repo. How do I tell it to look at my local git clone of BroadleafCommerce? (I realize this is a different question, but it's related because it's the only way I can think of fixing the problem.)

Upvotes: 1

Views: 822

Answers (1)

phillipuniverse
phillipuniverse

Reputation: 2045

2 ways to fix your problem:

  1. Set a Content-Type HTTP header to either application/json (the default) or application/xml
  2. Remove all the consumes from all the endpoints except for ones that have an @RequestBody

For instance, if you have an endpoint annotated with:

@RequestMapping(value = "/cart", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) public class CartEndpoint extends org.broadleafcommerce.core.web.api.endpoint.order.CartEndpoint

You can replace that with: @RequestMapping(value = "/cart", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) public class CartEndpoint extends org.broadleafcommerce.core.web.api.endpoint.order.CartEndpoint

Upvotes: 1

Related Questions