Quantcast
Channel: SCN : Popular Discussions - Java Development
Viewing all articles
Browse latest Browse all 518

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

$
0
0

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


Viewing all articles
Browse latest Browse all 518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>