Java NullPointerException in Java Agent
NickName:Gerard Cruz Ask DateTime:2013-12-20T12:23:47

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.

Copyright Notice:Content Author:「Gerard Cruz」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20696245/java-nullpointerexception-in-java-agent

Answers
sasankad 2013-12-20T04:35:20

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",


Richard Schwartz 2013-12-20T14:42:26

You may still have a code problem, but you could also have a permissions problem. \n\nYour 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. ",


More about “Java NullPointerException in Java Agent” related questions

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.

Show Detail

HttpURLConnection: empty header causing NullPointerException in Notes Java Agent

A couple of months ago I wrote a Java Agent that synchs documents in Notes databases with tickets in a Redmine system. The agent opens a Notes document through an HttpURLConnection and it worked

Show Detail

Error: Exception thrown by the agent : java.lang.NullPointerException when starting Java application

I am starting a Java application with the following command line arguments: java -Dcom.sun.management.jmxremote.port=12312 \ -Dcom.sun.management.jmxremote.rmi.port=12313 \ -Dcom.sun.

Show Detail

NullPointerException when Starting an application with BTrace agent

I am using BTrace 1.2 and followed user guide from BTrace website. I have no problems using BTrace on running programs with command: btrace <pid> AllMethods.class but when I try to start

Show Detail

How to prevent NullPointerException in a Java Class in Domino agent

My assumption is that, checking if the first document is null should be enough to prevent a nullexception error but that is not the case. I cannot seem to find where the exception is coming from an...

Show Detail

How to prevent NullPointerException in the finally clause in a Java Class in Domino agent

Java debugging information only returns null without stating the actual cause of the error in the finally clause of the try/catch and not sure on how to get rid of this error message or the cause o...

Show Detail

Error Exception throw by agent :java.lang.Nullpointerexception when starting spark tracker on DSE

I am getting Error: Exception throw by agent :java.lang.Nullpointerexception when starting spark tracker on DSE 4.5 using: dse cassandra -k Any idea?

Show Detail

Java NullPointerException in agent based model

I am using the MASON library to run a simple agent-based model. As per specifications, I meant to access an agent's inspector by double-clicking on such agent in the Portrayal. However, when I do...

Show Detail

Java Agent Use Image Resource

I have got an Java Agent and I'm trying to use an ImageResource in the "JTreeCellRendererOpen" class from the "res" folder to show as image icon. ImageIcon icon = new ImageIcon(this.getClass().

Show Detail

NullPointerException in Java script library

I am making a first step into Java- trying to create a simple Java script library in Domino Designer 8.5.2 to perform SFTP file transfers using JSch 0.1.48. The library will be called from a LotusS...

Show Detail