0

Hi I Created simple restful web services and using JSON for respone and storing information.when i run the service in tomcat 7.0 i got 404 error in browser

PLS help me to fix the error

Service Class

package com.login.service;

import javax.ws.rs.Consumes;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

//Path Reference to access this interface
@Path("/Sample")
public class OrdersService {


        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1009)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:589)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoin
t.java:312)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Returning the Response

1 Answers1

1

Problem is here:

JSONObject userDetails = null;
try 
{
   userDetails.put("firstname", "Jagathesewaren");

you are invoking put method on null. Initialize userDetails object

JSONObject userDetails = new JSONObject();
try 
{
   userDetails.put("firstname", "Jagathesewaren");
Ilya
  • 29,135
  • 19
  • 110
  • 158
  • Hi llya first thanks for ur reply i updated the code as u mentioned above but i got same error again – Jagathesewaren Kuppuraj Oct 25 '13 at 06:36
  • @JagathesewarenKuppuraj `NullPointer`? In which line? – Ilya Oct 25 '13 at 06:51
  • TomCat ERROR i mentioned above – Jagathesewaren Kuppuraj Oct 25 '13 at 08:04
  • @JagathesewarenKuppuraj what error? Can you add stacktrace? – Ilya Oct 25 '13 at 08:05
  • in browser i got HTTP Status 500 - Internal Server Error in tomcat mentioned above how to add stacktrace can u tell me – Jagathesewaren Kuppuraj Oct 25 '13 at 08:17
  • @JagathesewarenKuppuraj it is in browser. What did you get on server sude? – Ilya Oct 25 '13 at 08:19
  • Oct 25, 2013 1:57:37 PM com.sun.jersey.spi.container.ContainerResponse write SEVERE: A message body writer for Java class org.codehaus.jettison.json.JSONObje ct, and Java type class org.codehaus.jettison.json.JSONObject, and MIME media ty pe application/xml was not found – Jagathesewaren Kuppuraj Oct 25 '13 at 08:35
  • @JagathesewarenKuppuraj this is new problem, with Jersey configuration. You can find solutions here http://stackoverflow.com/questions/7777661/java-jersey-jettison-message-body-reader-exception. Also eead this article http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/ – Ilya Oct 25 '13 at 09:03