Question

I'm using Worklight (version 6.1.0.00-20131126-0630) and I've created a servlet in server-side package server/java/com.myproject.servlet

@WebServlet(name = "MyServlet", displayName = "MyServlet", urlPatterns = {  "/MyServlet/*" }, initParams = {
    @WebInitParam(name="targetUri", value="http://localhost:8080"),
    @WebInitParam(name="log", value="false"),
    @WebInitParam(name=ClientPNames.HANDLE_REDIRECTS, value="false")
    },
    loadOnStartup = 1)

public class MyServlet extends HttpServlet {
    private static final long serialVersionUID = 1966243950602823405L;

    @Override
    protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
            throws ServletException, IOException {
            super.service(arg0, arg1);

            //TODO: IMPLEMENTATION
    }
}  

What's the way to call my Servlet?

In many forum people say to call the servlet with an HTTP adapter. I suppose that when I run my worklightserver my servlet is instantiated by the worklight web container, so I think that I haven't to instantiate the Servlet inside an adapter procedure.

However what are the steps in order to call MyServlet service method from a common/mycall.js file in Worklight client-side?

Was it helpful?

Solution

You should not place the servlet within Worklight Server.

For your servlet to work while in Worklight Server, you will need to manually edit the web.xml file, otherwise the server will not recognize the servlet and will not listen to any incoming requests.

However, the web.xml is part of the .war file; this file is re-generated upon each build operation in Worklight Studio (in Eclipse, where the Worklight Server instance is part of), thus the web.xml is re-generated as well and your additions will be lost.

You need to deploy this servlet to some web server.

You can then reach it by using an HTTP adapter just like any other HTTP backend system. See the documentation for HTTP adapters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top