Gerard Cruz
Gerard Cruz

Reputation: 649

Java NullPointerException in Java Agent

I'm developing a java agent. I have an NullPointerException error which I do believe should not happen.

Here is the debug console message:

java.lang.NullPointerException
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:719)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:646)
    at COM.ibm.JEmpower.applet.http.HttpURLConnection.getInputStream(HttpURLConnection.java:411)
    at COM.ibm.JEmpower.applet.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:703)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:399)
    at JavaAgent.NotesMain(JavaAgent.java:16)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)

This the code in the java agent

import lotus.domino.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
public class JavaAgent extends AgentBase {

    public void NotesMain() {
      String strAux = "[A Working URL]";
      try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();

          // (Your code goes here)

          HttpURLConnection httpCon = (HttpURLConnection) new URL(strAux).openConnection();

          httpCon.setRequestMethod("HEAD");
          httpCon.setConnectTimeout(20000);  
          httpCon.setReadTimeout(20000);

          httpCon.connect();

          System.out.println(HttpCon.getURL().toString());

          int responsecode = httpCon.getResponseCode();
          System.out.println("Response code is " + responsecode + " - " + httpCon.getResponseMessage());
      } catch(Exception e) {
          e.printStackTrace();
      }
    }

}

Basically the error points to System.out.println("Response code is " + httpCon.getResponseCode() + " - " + httpCon.getResponseMessage());.

The thing is that the URL is a working link since I've tried it by accessing in a browser.

What could be the possible reasons for this error? It doesn't work as well on a local notes db that I created for testing. However, in a normal java program not developed in notes, it works.

Upvotes: 0

Views: 3354

Answers (3)

Winner
Winner

Reputation: 11

  1. Close Notes/Designer
  2. Open Task Manager in Windows
  3. Find and kill all IBM Lotus Notes/Domino processes
  4. Try again

Worked for me

Upvotes: 1

Richard Schwartz
Richard Schwartz

Reputation: 14628

You may still have a code problem, but you could also have a permissions problem.

Your code is running as a Java agent on an IBM Lotus Domino server. That means it is subjected to restrictions on what it can do. There are three levels of control: restrictions imposed by Domino's AMGR task, restrictions assigned to your agent, and restrictions imposed by the JVM. Presuming that you are the signer of the agent, have you made sure that you have permission to run unrestricted agents (Security tab of the Server Document in the Domiono Directory)? And have you checked the settings on your agent (the Security tab of the Agent Properties dialog for your agent)? If you have all of those set properly, then you may have to look at the file jvm/lib/security/java.policy in your Domino server installation.

Upvotes: 1

sasankad
sasankad

Reputation: 3613

It's pointless getting the response code before you've sent anything. You're supposed to send the request first, then get the response code, then get the response if required

Upvotes: 2

Related Questions