0
votes

I am new (again, have not touched it in a while) to Java.

I have a simple (much more complex one is planned) HttpServlet class that I am tryng to call from a webpage either from a regular Notes form or csjs on an xPage.

package com.pnc.cld;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorld extends HttpServlet
{
    private static final long serialVersionUID = -2950148158748149L;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        System.out.println("doGet: Hello World!");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        System.out.println("doPost: Hello World!"); 
    }
}

I found this article here.

Which is orginally in Chinese so it makes it a bit hard to follow but from what I have been able to glean from it, you need a add a IServletFactory class which maps the servlet to your a url so it can be called in your browser.

But I am getting errors. This article fixed some of them

But I still still get a number of errors. One of them:

The type ServletFactory must implement the inherited abstract method IServletFactory.getServletMatch(String, String) ServletFactory.java

Also the article seems to say that you need to add com.ibm.xsp.adapter.servletFactory to the services directory but I can't find the file anywhere on my PC.

Are there any better articles or hopefully working example for calling an httpservlet out there?

2
Having stumbled across this a couple years after it was asked, there is more. As Stephan Wissel answered, the "better" approach is to write your servlets into an OSGi plugin. With some mild effort, you can pull this off inside an NSF. The caveats are that a java.pol edit is required to give your NSF Java code some broader security privileges, edit your notes.ini (or via Internet site) to allow PUT and DELETE methods, along with adding the lwpd jar to your DDE's build path as Sven Hasselbach points out (your link). My blog series on the subject: edm00se.io/servlet-series - Eric McCormick

2 Answers

1
votes

Maybe you should study the sample database from Sven's blog post. Switch the Domino Designer to the Java perspective and have a look at the "Code/Java" section. There you find 3 files. One of them handles the URLs and maps them to the servlet. The third one is stored within the META-INF folder and defines where the IServletFactory should lookup the ServletFactory class (the second file). The first file ist the servlet itself. But careful: we just got stuck with errors in the sample database, too. Pretty simple cause: in the servlet code a "static" exception is thrown :-D Remove that code and you are fine. We tested this on a 8.5.3 machine but I am sure it will do on older releases, too.

0
votes

Bruce, on Domino you need to implement a servlet OSGi style. Go steal the code from my webDAV for Domino project on OpenNTF. The servlet is definitely working!