Saturday, April 11, 2015

Broadleaf commerce with Rest Api

Common errors that occured while working with broadleaf & Rest Api

1. 

Error:

SEVERE: A message body writer for Java class com.wrapper.CustomNameWrapper, and Java type class com.wrapper.CustomNameWrapper, and MIME media type application/xml was not found
Apr 11, 2015 9:58:06 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type are:
application/xml ->
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
  com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General


Cause:

The controller/endpoint class annotated with proper @Produces element but in the wrapper the following root element was missing :

Solution:


@XmlRootElement(name = "name")
@XmlAccessorType(value = XmlAccessType.FIELD)




2. 

Error:


SEVERE: Exception sending context destroyed event to listener instance of class org.broadleafcommerce.common.web.extensibility.MergeContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
         at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:171)
         at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090)
         at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064)
         at org.broadleafcommerce.common.web.extensibility.MergeXmlWebApplicationContext.doClose(MergeXmlWebApplicationContext.java:149)
         at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
         at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
         at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
         at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)
         at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)
         at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
         at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
         at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
         at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
         at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
         at java.util.concurrent.FutureTask.run(FutureTask.java:166)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
         at java.lang.Thread.run(Thread.java:722)



Cause/Solution:

The most common error that I faced till now was due the silly mistakes in the application-context.xml files. Be careful about your change in the config files rather try to do step by step instead of all in once. That is why I personally do not prefer the xml-based configurations and rely generally on on java-based configurations.

No comments:

Post a Comment