Problem with Domino servlet

Ok, I’m trying to run a simple servlet (actually I’ve tried several) on Domino and I keep getting a HTTP JVM: java.lang.ClassCastException: java.lang.String: java.lang.String error message on the console.

This happens at the same point each time. Here’s the servlet code:

import java.io.*;

import java.util.*;

import java.security.cert.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class PrintCert extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)

                           throws ServletException, IOException {

res.setContentType("text/plain");

PrintWriter out = res.getWriter();

out.println(“reading in cert”);

X509Certificate certs = (X509Certificate)

  req.getAttribute("javax.servlet.request.X509Certificate");

  out.println("read in cert");

if (certs != null) {

  for (int i = 0; i < certs.length; i++) {

  	String istr=Integer.toString(i);

    out.println("Client Certificate [" + istr+ "] = "

                    + certs[i].toString());

  }

}

else {

  if ("https".equals(req.getScheme())) {

    out.println("This was an HTTPS request, " +

                "but no client certificate is available");

  }

  else {

    out.println("This was not an HTTPS request, " +

                "so no client certificate is available");

  }

}

}

}

The line of code that causes this is:

X509Certificate certs = (X509Certificate)

I have an old SnoopServlet from Sun that has a similar line that gives me the same error.

Yes, I’m authenticating to the Domino server using an X.509 Certificate and I’ve verified that by submitting the current cert using the certpub database.

Subject: Problem with Domino servlet

I think the error is saying whatever is coming back from the getAttribute() call is a string, not an array of X509Certificate. Try something like this to find out what it actually is:
X509Certificate certs = null;

try

{

Object obj = request.getAttribute(“javax.servlet.request.X509Certificate”);

if (obj != null)

{

  out.println("<HR>object returned from javax.servlet.request.X509Certificate "

                    +obj.getClass()

                    +"<HR>");

  if (obj instanceof X509Certificate[])

     certs = (X509Certificate[])obj;

}

else

  out.println("getAttribute() failed to return "

                  +"javax.servlet.request.X509Certificate");      

}

catch (Throwable t)

{

t.printStackTrace(new PrintWriter(out));

}

Let us know what the output is for the above.

Joseph Millar

Principal Software Engineer

Brightline Technology

Subject: RE: Problem with Domino servlet

I added the code you posted to my servlet and sure enough, it returned class java.lang.String.

Ok, fine.

Problem is that it’s null. It seems that anything to do with a client certificate is null. That’s not good…

I tried this with the R6.5 servlet engine and also with Tomcat 4.0.6 running under Domino and get the same results.

Anyone got working Java code to access an X509 certificate presented from the browser?