I have a JAVA-EE project which uses "restlet-2.2" framework in my Intellij 13.1.4.
I want to deploy this project to apache tomcat server but I am having some problems.
Project structure
1.I have some JAVA classes which are basically different web services. All these classes extend ServerResource class. These classes have @Get methods inside them which will respond to the client request.
2.Then I have a class MyServer which extends Application class and in MyServer I have a Router class object which basically routes the requests to appropriate web-services depending on the URI.
3.web.xml - Intellij by defaults creates a web.xml with version="3.1" and adds nothing into it. So I modified that web.xml(Adding the web.xml below)
I have done the artifacts configurations and in my "war exploded" I have following structure
WEB-INF
--classes
-----| All compiled class files
--lib
-----| restlet jar files and json jar files (org.json.jar org.restlet.jar org.restlet.ext.json.jar org.restlet.ext.servlet.jar)
--web.xml
When I put this exploded war in my apache tomcat webapps folder and restart tomcat then I am able to access the html/css/js files. But my AJAX calls always give ERROR 404. I have tried all the solutions from stackoverflow and other websites but nothing helped.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/19L2NlC"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1drxgYl"
version="3.1">
<!-- Application class name -->
<context-param>
<param-name>org.restlet.application</param-name>
<param-value>
MyServer
</param-value>
</context-param>
<!-- Restlet adapter -->
<servlet>
<servlet-name>ServerServlet</servlet-name>
<servlet-class>
org.restlet.ext.servlet.ServerServlet
</servlet-class>
</servlet>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>ServerServlet</servlet-name>
<url-pattern>/Projects/*</url-pattern>
</servlet-mapping>
</web-app>
MyServer class
Router classpublic class MyServer extends Application{
public static void main(String []args)
{
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8080);
Application application = new MyServer();
// Attach the application to the component and start it
component.getDefaultHost().attach(application);
try {
component.start();
} catch (Exception e) {
e.printStackTrace();
}
}
//Method for attaching the URIs for web services
public synchronized Restlet createInboundRoot()
{
Router router = new Router(getContext());
//System.out.println("In router");
//Attaching URIsl
router.attach("/Projects/{projectID}/Enclosures/{enclID}/getStructure", StructureCalculations.class);
}
}
And my AJAX call URI looks like this
http://localhost:8080/Projects/p1/Enclosures/e1/getStructure?param1=x¶m2=y
Please help me!
Thank you
No comments:
Post a Comment