Note that there are some explanatory texts on larger screens.

plurals
  1. POJAX-RS JAXB JSON Response not working ( MessageBodyProviderNotFoundException)
    primarykey
    data
    text
    <p>I had been working for sometime to figure out how to create a JAX Restful Service... using the guide available here - <a href="https://jersey.java.net/documentation/latest/user-guide.html" rel="nofollow">Jersey</a></p> <p>As explained in Section 2.3.2, I had added the below dependency in Maven -</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt; &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt; &lt;version&gt;2.0&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>In web.xml</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;jersey.config.server.provider.classnames&lt;/param-name&gt; &lt;param-value&gt;org.glassfish.jersey.filter.LoggingFilter&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt; &lt;param-value&gt;com.hms.rs.controller.MyApp&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;url-pattern&gt;/services/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>and MyApp.java </p> <pre><code>public class MyApp extends Application{ @Override public Set&lt;Class&lt;?&gt;&gt; getClasses() { return new HashSet&lt;Class&lt;?&gt;&gt;() {{ // Add your resources. System.out.println("From the Myapp..."); add(Patient.class); add(PatientController.class); // Add LoggingFilter. add(LoggingFilter.class); }}; } } </code></pre> <p>Patient.java - </p> <pre><code>@XmlRootElement(name = "Patient") public class Patient { private String patientFName; private String patientLName; private int patientAge; private String patientSex; private String patientParentSpouse; private String patientQual; private String patientOccupation; private String patientComments; public Patient() { } Setters and Getters.... } </code></pre> <p>PatientController.java - </p> <pre><code>@Path("/ManagePatient") public class PatientController { @GET @Path("/getPatient") @Produces(MediaType.APPLICATION_XML) public Patient printPatient() { System.out.println("Hello.... from the PatientController"); Patient ptnt = new Patient(); ptnt.setPatientFName("FirstN"); ptnt.setPatientLName("LName"); ptnt.setPatientAge(30); ptnt.setPatientSex("M"); ptnt.setPatientParentSpouse("ParentSpuse"); ptnt.setPatientQual("engg"); ptnt.setPatientOccupation("software"); ptnt.setPatientComments("comments here"); System.out.println("Patient = " + ptnt); //return ptnt.toString(); return ptnt; } </code></pre> <p>When I try to access this via browser @ localhost:8080/HMS_Web/services/ManagePatient/getPatient</p> <p>I am getting</p> <pre><code>javax.servlet.ServletException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class com.hms.app.ui.beans.Patient, genericType=class com.hms.app.ui.beans.Patient. </code></pre> <p>and I also see the below warning in the logs-</p> <pre><code>WARNING: A provider com.hms.app.ui.beans.Patient registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.hms.app.ui.beans.Patient will be ignored. </code></pre> <p>If Jersey 2.0 supports JAXB based xml or json support as mentioned @ section "8.1.1.2. JAXB based JSON support" in the Jersey guide, I am not sure why I am receiving the Provider errors. </p> <p>Could any JAX-WS expert help me understand and also provide me direction on how to resolve this situation? </p> <p>Thank you in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload