OK. Well it makes no difference to the problem. I had hoped that Session was some way of maintaining authentication credentials, so perhaps by some miracle, passing the same Session from the main thread to the new thread would fix the problem.
I don’t have a IS 7, so it would be really interesting to me if someone could try this and tell me if it works there.
To reproduce:
Create a Java package “ThreadTest”.
Within ThreadTest, create a folder “ThreadTest”.
Create Java service “ThreadTest:testServiceFromThread”
Configure one input string field: “depth”
Main body of service:
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String s_depth = IDataUtil.getString( pipelineCursor, "depth" );
pipelineCursor.destroy();
int depth = Integer.parseInt(s_depth);
ThreadTest thread = new ThreadTest();
thread.setDepth(depth);
thread.start();
thread.logExcept();
In “Shared”:
- Extends field: “Thread”.
In “Source” field:
private int depth;
private Exception except;
public void logExcept() {
if(except != null) {
log("Depth = " + depth + " Exception : " + except.getMessage());
}
}
public void setDepth(int depth) {
this.depth = depth;
log("ThreadTest - outside thread - depth=" + depth);
}
public void run() {
log("ThreadTest - in thread - depth=" + depth);
}
private void log(String log) {
// input
IData input = IDataFactory.create();
IDataCursor inputCursor = input.getCursor();
IDataUtil.put( inputCursor, "message", log );
IDataUtil.put( inputCursor, "function", "function" );
IDataUtil.put( inputCursor, "level", "level" );
inputCursor.destroy();
// output
try {
Service.doInvoke( "pub.flow", "debugLog", input );
} catch (Exception e) {
this.except = e;
}
}
Run the service. Input value does not matter.
What I see:
“2008-09-22 11:56:40 GMT [ISP.0090.0004C] function – ThreadTest - outside thread - depth=1” is output as exected.
“2008-09-22 11:56:40 GMT [ISP.0090.0004C] function – "ThreadTest - in thread – depth=1” is not output – failed with “Access Denied” in the ServiceException.
Also, if I substitute “run” for “start”, the problem goes away (but I’m no longer creating a thread).
#Flow-and-Java-services#Integration-Server-and-ESB#webMethods