0

I am new to java web service. while writing sample web service using jax-rs am getting following error in stack trace. run a server which load a page as http status 404. I need to write simple web service for my understanding and then i have to access web service via restful client in android application. am here post my entire web service please help me.

pls lead me in right way. thanks in advance

Aug 26, 2014 6:55:04 AM org.apache.catalina.core.AprLifecycleListener init
 INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft\Web Platform Installer\;.
                Aug 26, 2014 6:55:04 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
                WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:webService' did not find a matching property.
                Aug 26, 2014 6:55:04 AM org.apache.coyote.AbstractProtocol init
                INFO: Initializing ProtocolHandler ["http-bio-8080"]
                Aug 26, 2014 6:55:04 AM org.apache.coyote.AbstractProtocol init
                INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
                Aug 26, 2014 6:55:04 AM org.apache.catalina.startup.Catalina load
                INFO: Initialization processed in 699 ms
                Aug 26, 2014 6:55:04 AM org.apache.catalina.core.StandardService startInternal
                INFO: Starting service Catalina
                Aug 26, 2014 6:55:04 AM org.apache.catalina.core.StandardEngine startInternal
                INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
                Aug 26, 2014 6:55:06 AM com.sun.jersey.api.core.PackagesResourceConfig init
                INFO: Scanning for root resource and provider classes in the packages:
                  webService
                Aug 26, 2014 6:55:06 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
                INFO: Root resource classes found:
                  class webService.myserviceClass
                Aug 26, 2014 6:55:06 AM com.sun.jersey.api.core.ScanningResourceConfig init
                INFO: No provider classes found.
                Aug 26, 2014 6:55:06 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
                INFO: Initiating Jersey application, version 'Jersey: 1.17.1 02/28/2013 03:28 PM'
                Aug 26, 2014 6:55:07 AM org.apache.coyote.AbstractProtocol start
                INFO: Starting ProtocolHandler ["http-bio-8080"]
                Aug 26, 2014 6:55:07 AM org.apache.coyote.AbstractProtocol start
                INFO: Starting ProtocolHandler ["ajp-bio-8009"]
                Aug 26, 2014 6:55:07 AM org.apache.catalina.startup.Catalina start
                INFO: Server startup in 2082 ms

web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <display-name>webService</display-name>


       <servlet>
        <servlet-name>Rest</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>webService</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Rest</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    </web-app>

myserviceClass.java

package webService;


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

    // Plain old Java Object it does not extend as class or implements 
    // an interface

    // The class registers its methods for the HTTP GET request using the @GET annotation. 
    // Using the @Produces annotation, it defines that it can deliver several MIME types,
    // text, XML and HTML. 

    // The browser requests per default the HTML MIME type.

    //Sets the path to base URL + /hello
    @Path("/hello")
    public class myserviceClass {

      // This method is called if TEXT_PLAIN is request
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String sayPlainTextHello() {
        return "Hello Jersey";
      }

      // This method is called if XML is request
      @GET
      @Produces(MediaType.TEXT_XML)
      public String sayXMLHello() {
        return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
      }

      // This method is called if HTML is request
      @GET
      @Produces(MediaType.TEXT_HTML)
      public String sayHtmlHello() {
        return "<html> " + "<title>" + "Hello Jersey" + "</title>"
            + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
      }

    } 
5
  • There are no errors in logs, add your web.xml file, your web-service code and what URL you are trying to access in your post. Commented Aug 26, 2014 at 12:11
  • i post my code pls help me Commented Aug 26, 2014 at 12:26
  • What URL you are trying to access? Commented Aug 26, 2014 at 12:39
  • localhost:8080/webService/WEB-INF/classes/webService/… Commented Aug 26, 2014 at 12:44
  • Try this url with your server up: localhost:8080/contextOfYourApplication/rest/hello - Since you have mapped in your web.xml to call the jersey servlet in /rest, and you mapped the path /hello in your class Commented Aug 26, 2014 at 12:56

2 Answers 2

2

The URL you have to access is of the format:

http://your_hostname:port-number/application-context-name/rest/path-name-of-your-web-service

<hostname> is localhost as the application is running on your machine

<port-number> is 8080 - default port for tomcat server

<application-context-name> is name of your application deployed in tomcat server, if you have named it as webService then application context name will be webService

rest -- this is the name of the jersey Servlet configured in your web.xml file, as per your xml it is rest

<path-name-of-your-web-service> -- this will be /hello as per your java web-service code.

So try with:

http://localhost:8080/webService/rest/hello
Sign up to request clarification or add additional context in comments.

5 Comments

i have one more question , i need to host my web service how can it be possible to access from another pc as a client.
If the machines are in same network, then you can access the same URL except that you need to change localhost to your hostname or IP address
i did , but i got "can't load webpage message"
yeah sure i will do it. i need ur help pls provide ur g+
sorry for that, you can always use SO or any queries, you will definitely get better help from experts.
0

I didn't see any error in your tomcat log. Bu I think there is no servlet for your web service which handle the request. (control web.xml) Or you are trying to access wrong context.

You can look this https://netbeans.org/kb/docs/websvc/jax-ws.html tutorial.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.