Skip to Content
avatar image
Former Member

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;import;import;import;@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; import;  import;import;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


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jun 27, 2013 at 07:39 AM

    Hi Jana,

    take a look at this blog:

    There it is show how to create a REST-Service with Jersey.

    And there is one important hint: When you get a 403 then you possible have not assigned the security-constraints in the web.xml and web-j2ee-engine.xml

    For web.xml an example would be:

    <login-config>        <auth-method>FORM</auth-method>    </login-config><security-role>        <role-name>MyApplicationRole</role-name>    </security-role><security-constraint>        <display-name>MySecurityConstraint</display-name>        <web-resource-collection>            <web-resource-name>WebResource</web-resource-name>            <url-pattern>*</url-pattern>        </web-resource-collection><!--            Specify the role that all users must have to access the application        -->        <auth-constraint>            <role-name>MyApplicationRole</role-name>        </auth-constraint>        <user-data-constraint>            <transport-guarantee>NONE</transport-guarantee>        </user-data-constraint>    </security-constraint>

    In the web-j2ee-engine.xml you can use the the role-name and assign it to an existing server role like this:

    <security-role-map><role-name>MyApplicationRole</role-name>        <server-role-name>Administrators</server-role-name></security-role-map>

    Try to logon to an application like NWA on the server which is in the required role (Administrators). Then call the URL of your REST-Service from the same browser.

    This way you make sure that your user is authenticated and your service can notice this.

    Hope this helps.

    Best regards,

    Stefan Brauneis

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.