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;






public class TestWebserviceRest {



    public String messageText() {

        return "Yea! It's working!";




    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:





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


        // Get plain text


        // The HTML



      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


Former Member
Former Member replied

Oh yes, I forgot:

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


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.



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