cancel
Showing results for 
Search instead for 
Did you mean: 

Restful Webservice on Application Server Java

Former Member
0 Kudos

Hi,

i'm trying to create Restful Webservices on the Netweaver Java Application Server with JAX-RS.

The Classes are annotated correctly.

                 package pkg;

@Path(value = "/Calculate")

public class Calculate{

    @Path("/{x}&{y}")

    @GET

    @Produces(MediaType.TEXT_PLAIN)

    public String sum(@PathParam("x") int x, @PathParam("y") int y) {

        return Integer.toString(x + y);

    }

}

               and in the web.xml:

<servlet>

        <servlet-name>Servlet</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>testpkg</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

  <servlet-mapping>

        <servlet-name>Servlet</servlet-name>

        <url-pattern>/rest/*</url-pattern>

    </servlet-mapping>

However, if i deploy on a glassfish server it works.

The Java AS only writes "404 - not found".

Any Suggestions? - Thank you.

Regards,

Michael

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Michael,

is it deployed correctly on server is there any warning while deployment? If yes please can you post the log?

Regards

Former Member
0 Kudos

There is a warning during deployment.

Description:

                    1. Warning occurred on server 9711850 during deploy of sap.com/TestServiceProjectEAR : Web Class Existence Test: com.sap.ASJ.webjlin.000006 servlet class "com.sun.jersey.spi.container.servlet.ServletContainer" cannot be found in the application class path. Possible reasons: 1) package or class name not correct; 2) missing referenced component (application or library); 3) missing reference to component (application or library)., file: TestServiceProject.war#WEB-INF/web.xml, severity: warning

CSN component of deployment item is not available

                    2. Warning exception has been returned while the [sap.com/TestServiceProjectEAR] was starting. Warnings:[

][

Warning occurred on server 9711850 during startApp of sap.com/TestServiceProjectEAR : Cannot load servlet [com.sun.jersey.spi.container.servlet.ServletContainer]. Error is: [java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

It says that "com.sun.jersey.spi.container.servlet.ServletContainer" referenced in the web.xml cannot be found. Although i have included the "jersey-core", "jersey-server" and "jersey-servlet" libraries in the web-project and marked them as exported.

My Web-Project is named "TestServiceProject" and my EAR "TestServiceProjectEAR". I am trying to call the service like "http://localhost:50000/TestServiceProject/rest/Calculate/5&4".

Thanks

Former Member
0 Kudos

>> Although i have included the "jersey-core", "jersey-server" and "jersey-servlet" libraries in the web-project and marked them as exported.

Be more specific in what steps you performed to add libraries to web project? Check in generated WAR archive that all required jersey libraries exists in WEB-INF/lib folder. If not you need to add them to WEB-INF/lib folder.

Former Member
0 Kudos

Hi Michael,

Did you included the required dependancies properly in both web module and ear? Can you please elaborate what steps did you followed to include the dependancies. It looks like the dependancies are missing from ear or not properly configured. can you post the web.xml and application.xml ?

Regards

Former Member
0 Kudos

Be more specific in what steps you performed to add libraries to web project? Check in generated WAR archive that all required jersey libraries exists in WEB-INF/lib folder. If not you need to add them to WEB-INF/lib folder.

Right Click on Web Project -> Properties -> Java Build Path -> Add External JARs -> add the 3 jersey jars....

Then Java EE Modules -> Web Libraries -> Check the 3 jersey libraries -> apply -> ok.

In The generated WAR there are all 3 libraries in the WEB-INF/lib folder.

Did you included the required dependancies properly in both web module and ear?

No i haven't. But if i do (Right Click on the EAR Project -> Properties -> Java EE Module Dependencies -> Add External JARS -> add all three), this changes nothing.

can you post the web.xml and application.xml?

application.xml

<?xml version="1.0" encoding="ASCII"?>

<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">

  <display-name>TestServiceProjectEAR</display-name>

  <module>

    <web>

      <web-uri>TestServiceProject.war</web-uri>

      <context-root>TestServiceProject</context-root>

    </web>

  </module>

</application>

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>TestServiceProject</display-name>

 

    <servlet>

        <servlet-name>ServletAdaptor</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>pkg</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

  <servlet-mapping>

        <servlet-name>ServletAdaptor</servlet-name>

        <url-pattern>/rest/*</url-pattern>

    </servlet-mapping>

   

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

</web-app>

Should i eventually upload the whole project?

Thanks!

Former Member
0 Kudos

Hi Michael,

You should create external library dc's and use that DC as dependency for web module instead of configuring build path. SAP Dc's doesn't always work by adding external jar's and I assume that is the problem for class not found exception and thats why it works in glassfish its not sap WAS server.

Regards

Former Member
0 Kudos

Hi Jeetendra,

ok thanks. I created an external library dc and added the librarys to the public parts like here:  http://help.sap.com/saphelp_nw70/helpdata/DE/5a/2e2f4234135433e10000000a155106/content.htm

How can i set the dependency in my web-project for that dc?

Thanks.

Michael

Former Member
0 Kudos

Hi Michael,

The web module where you created the servlet for consuming jersey api. Right click on that and on the development component menu click in show in -> component properties

On the dependancy tab please click on add and select the library dc -

Regards

Former Member
0 Kudos

Yes, please attach WAR archive.

Former Member
0 Kudos

The web module where you created the servlet for consuming jersey api. Right click on that and on the development component menu click in show in -> component properties

If i right click on my web Project -> Development Component i only have 2 options "Migrate to Software Component" and "Convert Project to Development Component".

Yes, please attach WAR archive.

Can anyone have a look at my projects? Cannot make it work. (I deleted the newly created external library dc in this archive).

https://dl.dropboxusercontent.com/u/60236785/ServiceProject.zip

I cannot upload it cause of invalid content type. If we find a solution i will post it, so anyone else who reads this could understand it.

Thanks.

Former Member
0 Kudos

Hi Michael,

Looks like you have developed the project in Eclipse instead of NWDS or have not created the development component but the application project. If I am right can you please create a DC (Development component) in NWDS or convert your project to DC as per the 2nd option. Mean while I will have a look on provided project and will update you once I am done.

Regards

Former Member
0 Kudos

Remove Class-Path attribute from META-INF/MANIFEST.MF in web project. Build it, deploy and try again.

Former Member
0 Kudos

Looks like you have developed the project in Eclipse instead of NWDS or have not created the development component but the application project.

I developed it in nwds. I created a dynamic web project with a enterprise application project. Isn't that right so far?

Well, i created a external library dc, published the libraries into "public part" section, converted my web project to a development component and added the external library dc as a dependency... Is that correct?

Remove Class-Path attribute from META-INF/MANIFEST.MF in web project. Build it, deploy and try again.

This changes nothing.

Thanks!

Former Member
0 Kudos

Hi Michael,

Yes you did it right now after adding the dependancy deploy and check please revert in case any issue. You can create a web module as DC by following below mentioned steps -

Select Development component from the list -

Select web module from java EE list -

Create the web module in your LocalDevelopment track.

Regards

Former Member
0 Kudos

In that case create a shared library for jersey jars only, deploy it on server and reference it in your application in application-j2ee-engine.xml.

Using Shared Libraries

Former Member
0 Kudos

Hi,

well... I throwed all over.. Then i created a Enterprise Application Development Component, a WebModule Development Component and a External Library Development Component.

As Dependency in the EA DC i added the Web DC. In the Web DC i added the External Library DC.

In the External Library Development Component i have the 3 jersey libraries in the "lib" folder and published it to public part.

Why the hell isnt it working? I have compile time errors on my REST class. The Classes are not found. I think it's because a mistake with the libraries...?

Thanks.

Former Member
0 Kudos

What is your SAP NetWeaver version?

Former Member
0 Kudos

sap as java systeminfo:

SAP Java Server VM
SAP AG
1.6.0_29
6.1.037 1.6-b11
7.31.3710.240936.2013010515490

Netweaver Developer Studio 7.3 EHP1

Former Member
0 Kudos

Ok. As quick test do the following. Take your original application and add jersey libraries as bundled libraries to application (TestServiceEAR in your case) as described in Using Bundled Libraries. Do not worry about that you will have jersey libraries 2 times (in EAR and WAR). Build application and deploy it on AS Java server. Attach deploy log here.

Answers (3)

Answers (3)

manigram
Active Participant
0 Kudos

Hi ,

Have you deployed the "JAX-RS" related jar files in Server, Because as you saying that this program is working correctly in Glass fish but not in application sever. Due to this reason it might throw error.

Regards,

Manigandan

Former Member
0 Kudos

Is value testpkg valid for com.sun.jersey.config.property.packages parameter? According to above code snippet it's need to be pkg not testpkg.

Former Member
0 Kudos

What a bad mistake. Now i've corrected it, but doesn't work anyway.

Same message "404 - not found".

Thanks.

Former Member
0 Kudos

What URL you use to call service? Also check that application was correctly deployed on server.

Former Member
0 Kudos

Doesn't anyone have an answer?