I think you missed adding the @XmlRootElement annotation on your
RegistrationContext class.
The JAXB entity provider checks for that annotation to be present.
Rajesh T <Rajesh.Thiagarajan_at_Sun.COM>
Sent by: Rajesh.Thiagarajan_at_Sun.COM
04/11/2008 08:50 AM
Please respond to
users_at_jersey.dev.java.net
To
users_at_jersey.dev.java.net
cc
Subject
MIME media type, application/xml, was not found - exception
Hi,
I am trying to return a JAXB Object from the sample program. I tried to
modifying the Samples bundles with jersy
Here is the exception I am getting. Any help appreciated.
Exception :
PWC1406: Servlet.service() for servlet WSRP REST Interface threw
exceptionjava.lang.IllegalArgumentException: A message body writer for
Java type, class com.sun.portal.wsrp.common.stubs.v2.RegistrationContext,
and MIME media type, application/xml, was not found at
com.sun.ws.rest.impl.application.MessageBodyFactory.getMessageBodyWriter(MessageBodyFactory.java:153)
at
com.sun.ws.rest.spi.container.AbstractContainerResponse.writeEntity(AbstractContainerResponse.java:257)
at
com.sun.ws.rest.spi.container.AbstractContainerResponse.writeEntity(AbstractContainerResponse.java:235)
at
com.sun.ws.rest.impl.container.servlet.HttpResponseAdaptor.commitAll(HttpResponseAdaptor.java:127)
at
com.sun.ws.rest.spi.container.servlet.ServletContainer.service(ServletContainer.java:141)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.
web.connector.grizzly.DefaultProcessorTask.invokeAdapter
(DefaultProcessorTask.java:637) at com.sun.enterprise.
web.connector.grizzly.DefaultProcessorTask.doProcess
(DefaultProcessorTask.java:568) at com.sun.enterprise.
web.connector.grizzly.DefaultProcessorTask.process
(DefaultProcessorTask.java:813) at com.sun.enterprise.
web.connector.grizzly.DefaultReadTask.executeProcessorTask
(DefaultReadTask.java:341) at com.sun.enterprise.
web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask
(DefaultReadTask.java:214) at com.sun.enterprise.
web.portunif.PortUnificationPipeline
$PUTask.doTask(PortUnificationPipeline.java:380) at
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run
(SSLWorkerThread.java:106)
Here is the program :
import com.sun.portal.wsrp.common.stubs.v2.RegistrationContext;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.GET;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.Path;
@Path("/registration")
public class RegistrationRS {
@GET
@ProduceMime({"application/json", "application/xml"})
public RegistrationContext getRegistration (){
RegistrationContext regContext = new RegistrationContext();
regContext.setRegistrationHandle("dummy-rest");
regContext.setRegistrationState("valid".getBytes());
return regContext;
}
}
Here is the JAXBObject :
package com.sun.portal.wsrp.common.stubs.v2;
import javax.xml.bind.annotation.XmlAccessType;import
javax.xml.bind.annotation.XmlAccessorType;import
javax.xml.bind.annotation.XmlElement;import
javax.xml.bind.annotation.XmlType;
/** * <p>Java class for RegistrationContext complex type. * * <p>The
following schema fragment specifies the expected content contained within
this class. * * <pre> * <complexType name="RegistrationContext"> *
<complexContent> * <extension base="{urn:oasis
:names:tc:wsrp:v2:types}RegistrationState"> * <sequence> *
<element name="registrationHandle" type="{
http://www.w3.org/2001/XMLSchema}string"/> * </sequence> *
</extension> * </complexContent> * </complexType> *
</pre> * * */_at_XmlAccessorType(XmlAccessType.FIELD)@XmlType(name =
"RegistrationContext", propOrder = { "registrationHandle"})public class
RegistrationContext extends RegistrationState{
@XmlElement(required = true) protected String registrationHandle;
/** * Gets the value of the registrationHandle property. *
* @return * possible object is * {_at_link String } *
*/ public String getRegistrationHandle() { return
registrationHandle; }
/** * Sets the value of the registrationHandle property. *
* @param value * allowed object is * {_at_link String }
* */ public void setRegistrationHandle(String value) {
this.registrationHandle = value; }
}
Here is the Provider :
package com.sun.portal.wsrp.producer.registration.impl;
import com.sun.portal.wsrp.common.stubs.v2.RegistrationContext;import
com.sun.ws.rest.impl.json.JSONJAXBContext;import
com.sun.ws.rest.spi.service.ContextResolver;import java.util.Arrays;import
java.util.HashMap;import java.util.HashSet;import java.util.Map;import
java.util.Set;import javax.xml.bind.JAXBContext;import
javax.ws.rs.ext.Provider;
@Providerpublic final class WSRPContextResolver implements
ContextResolver<JAXBContext> { private final JAXBContext context;
private final Set<Class> types; private final Class[] cTypes =
{RegistrationContext.class}; public WSRPContextResolver() throws
Exception { Map<String, Object> props = new HashMap<String,
Object>(); props.put(JSONJAXBContext.JSON_NOTATION,
"BADGERFISH"); props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING,
Boolean.FALSE); this.types = new HashSet(Arrays.asList(cTypes));
this.context = new JSONJAXBContext(cTypes, props); } public
JAXBContext getContext(Class<?> objectType) { return
(types.contains(objectType)) ? context : null; }}
regards
Rajesh T