Jouramie
Jouramie

Reputation: 214

ClassNotFoundException when running IBM code example

I'll eventually have write some custom data in my notes documents. But before that I wanted to see how it works, so I've copied/pasted the example from IBM Knowledge Center about replace/getItemValueCustomData in two seperated agent.

Problem is that when I try to read the custom data, the Read Agent throw that exception :

java.lang.ClassNotFoundException: customData.IntIntString
    at java.lang.Class.forName(Class.java:291)
    at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:619)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1609)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1768)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:364)
    at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
    at JavaAgent.NotesMain(JavaAgent.java:14)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)

Here is the code :

Write agent :

import customData.IntIntString;
import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {
            Session session = getSession();
            AgentContext agentContext = session.getAgentContext();

            IntIntString iis = new IntIntString();
            iis.setData(1, 2, "String1");

            Document doc = agentContext.getDocumentContext();
            doc.replaceItemValueCustomData("IntIntStringItem", "IntIntStringType", iis);
            doc.save();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Read agent :

import intIntString.IntIntString;
import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {
            Session session = getSession();
            AgentContext agentContext = session.getAgentContext();

            Document doc = agentContext.getDocumentContext();
            if (doc.hasItem("IntIntStringItem")) {
                IntIntString iis = (IntIntString) doc.getItemValueCustomData("IntIntStringItem", "IntIntStringType");
                iis.show();
            } else {
                System.out.println("No item IntIntStringItem in document");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

IntIntString class :

package customData;

import java.io.Serializable;

public class IntIntString implements Serializable {

    private static final long serialVersionUID = 6875473472063311349L;

    private int int1;
    private int int2;
    private String string1;

    public void setData(int i1, int i2, String s1) {
        int1 = i1;
        int2 = i2;
        string1 = s1;
    }

    public void show() {
        System.out.println("Int1 = " + int1);
        System.out.println("Int2 = " + int2);
        System.out.println("String1 = " + string1);
    }
}

Bytes wrotes by the Agent :

.  I  n  t  I  n  t  S  t  r  i  n  g  T  y  p  e  .  .  .
10 49 6E 74 49 6E 74 53 74 72 69 6E 67 54 79 70 65 AC ED 00 
.  s  r  .  .  c  u  s  t  o  m  D  a  t  a  .  I  n  t  I
05 73 72 00 17 63 75 73 74 6F 6D 44 61 74 61 2E 49 6E 74 49 
n  t  S  t  r  i  n  g  _  j  .  .  .  .  .  .  .  .  .  I
6E 74 53 74 72 69 6E 67 5F 6A 96 B1 EC F4 8D F5 02 00 03 49 
.  .  i  n  t  1  I  .  .  i  n  t  2  L  .  .  s  t  r  i
00 04 69 6E 74 31 49 00 04 69 6E 74 32 4C 00 07 73 74 72 69 
n  g  1  t  .  .  L  j  a  v  a  /  l  a  n  g  /  S  t  r
6E 67 31 74 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72
i  n  g  ;  x  p  .  .  .  .  .  .  .  .  t  .  .  S  t  r
69 6E 67 3B 78 70 00 00 00 01 00 00 00 02 74 00 07 53 74 72 
i  n  g  1
69 6E 67 31    

Do I miss something or is IBM drunk?

Link to the examples : replaceItemValueCustomData method, getItemValueCustomData method.


Edit : Tried to define the "IntIntString" class in the "Agent" class, but that did not work, nor put the class in a .jar and import it.


Edit 2 : As suggested in comments, I tried to declare the class public in the agent. For some reason when I tried that I had to implements Serializable in the agent, which I did. Still got the same exception.

Then I tried to declare it public in a separate file (because public classes need their own file) in the "customData" package, but that didn't work either.

Also tried to read the field when the document is open in read mode. I got that exception and the field erased (saw that from document property) :

NotesException: Supplied Data type name does not match stored CustomData type
    at lotus.domino.local.Document.NgetItemValueCustomData(Native Method)
    at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
    at JavaAgent.NotesMain(JavaAgent.java:14)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)

Seams that the field is not read/write correctly, Data type should match.

Code updated.

Upvotes: 3

Views: 1019

Answers (2)

Knut Herrmann
Knut Herrmann

Reputation: 30970

Create a jar file from custom class IntIntString

import java.io.Serializable;

// Define custom data
public class IntIntString implements Serializable {
    private static final long serialVersionUID = 1L;
    int int1;
    int int2;
    String string1;

    public void setData(int i1, int i2, String s1) {
        int1 = i1;
        int2 = i2;
        string1 = s1;
    }

    public void show() {
        System.out.println("Int1 = " + int1);
        System.out.println("Int2 = " + int2);
        System.out.println("String1 = " + string1);
    }
}

and put the jar file into folder

  • domino/jvm/lib/ext (Domino Server - for backend and runOnServer agents)
  • notes/jvm/lib/ext (Notes Client - for agents started on client side)

This way, ObjectInputStream can find the custom class IntIntString as it is globally available in agent's JVM. This is the missing piece in IBM's documentation of replaceItemValueCustomData/getItemValueCustomData.

Upvotes: 5

Duston
Duston

Reputation: 1641

Here's what I did...

  1. Created a Java agent called WriteAgent
  2. Under Src->(default package), created a new class called IntIntString.java
  3. Pasted in your code as is
  4. Again under Src->(default package), created a new class called JavaAgent.java
  5. Pasted in your WriteAgent class without the import to customData;

Compiled and ran without error and updated the document.

Upvotes: 2

Related Questions