Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to call a (selfmade) Java REST Webservice in Netweaver? What's the URL?

Dear experts,

currently I'm trying out REST webservices in the Netweaver environment. I tried some how-to-start-manuals and built my first REST Webservice as an EJB with EAR project.

For testing the webservice I used a simple Client class with console output. Unfortunately it always says

"GET http://...~lib~ws~rest/rest/testMessage returned a response status of 404 Not Found".

I wanted to call the REST URL in the Browser as well, but I also got the 404 error.

For the URL "http://...~lib~ws~rest/" I get a 403 "Forbidden" error. For me this means the URL for my EAR ist correct, but forbidden to show. But if it is correct, why don't the REST-URLs work?

Here is the code for my Webservice (project name "lib/ws/rest", resp. "lib/ws/rest/ear"):

package testWebservice;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

@Path("/testMessage")

public class TestWebserviceRest {

    @GET

    @Produces(MediaType.TEXT_PLAIN)

    public String messageText() {

        return "Yea! It's working!";

    }

    @GET

    @Produces(MediaType.TEXT_HTML)

    public String messageHtml() {

        return "<html> " + "<title>" + "testMessage" + "</title>"

            + "<body><h1>" + "Yea! It's working!"

            + "</body></h1>" + "</html> ";

    }

}

Here is the code for my testclass to run locally:

package testWebservice.rest.client;

import java.net.URI; 

import javax.ws.rs.core.MediaType;

import javax.ws.rs.core.UriBuilder;

import com.sun.jersey.api.client.Client;

import com.sun.jersey.api.client.ClientResponse;

import com.sun.jersey.api.client.WebResource;

import com.sun.jersey.api.client.config.ClientConfig;

import com.sun.jersey.api.client.config.DefaultClientConfig;

public class RestTestClient { 

  

      public static void main(String[] args) {

         

        ClientConfig config = new DefaultClientConfig();

        Client client = Client.create(config);

        WebResource service = client.resource(getBaseURI());

       

        // Fluent interfaces

        System.out.println(service.path("rest").path("testMessage").accept(MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());

        // Get plain text

        System.out.println(service.path("rest").path("testMessage").accept(MediaType.TEXT_PLAIN).get(String.class));

        // The HTML

        System.out.println(service.path("rest").path("testMessage").accept(MediaType.TEXT_HTML).get(String.class));

      }

      private static URI getBaseURI() {

        return UriBuilder.fromUri("http://...lib~ws~rest").build();

      }  

}

Is the URL wrong?

How to "build" the right URl for a REST webservice in Netweaver?

Or is there another problem I didn't find?

I appreciate every hint and hope your your support.

Thank you

Jana

Former Member
Former Member replied

Oh yes, I forgot:

The final, correct REST service URL-pattern wiht this last information will be:

http://host:portnumber/context-root/url-pattern/Path

where the context-root is to be found in application.xml of the EAR, the url-pattern in the web.xml of the WAR and the path is annotated on the Webservice-class. Each of these components of the URL can be changed as you like.

Regards

Jana

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question