Hi,
I was trying to execute the following code simultaneously using two threads. But it executed only the first thread and it got stuck with the second thread while it was exceuting the line stub.beginSession(). Please comment on this.
try {
// Setup the parameters
RunScriptParameters runScriptParams = new RunScriptParameters();
runScriptParams.setScriptLanguage("javascript");
runScriptParams.setScriptText("alert('hello world')");
BasicClientConfig basicClientConfig = new BasicClientConfig();
SimpleChain httpChain = new SimpleChain();
httpChain.addHandler(new CommonsHTTPSender());
basicClientConfig.deployTransport("http", httpChain);
// Make a service
Service inDesignService = new ServiceLocator(basicClientConfig);
ServiceStub stub = (ServiceStub) inDesignService
.getService(new URL("http://127.0.0.1:8470"));
UnsignedInt sessionID = stub.beginSession();
System.out.println("begin session : " + sessionID.toString());
// Set sessionID into header so that server knows run scripts in
// a session context.
SOAPHeaderElement header = new SOAPHeaderElement(
"http://ns.adobe.com/InDesign/soap/", "sessionID");
header.addTextNode(sessionID.toString());
stub.setHeader(header);
IntHolder errorNumber = new IntHolder(0);
StringHolder errorString = new StringHolder();
DataHolder results = new DataHolder();
// Execute the script
stub.runScript(runScriptParams, errorNumber, errorString, results);
if (errorNumber.value == 0) {
System.out.println("Script success");
if (results.value.getData() == null)
System.out.println(": Script reported no errors");
else
System.out.println(" ("
+ results.value.getData().getClass().getName()
+ "): " + results.value.getData());
} else {
System.err.println("Error number: " + errorNumber.value);
if (!errorString.value.equals(null))
System.err.println(errorString.value);
}
try {
stub.endSession(sessionID);
} catch (NullPointerException e) {
}
System.out.println("end session : " + sessionID.toString());
} catch (IllegalArgumentException e) {
} catch (IOException e) {
System.err.println(e.getMessage());
} catch (Exception e) {
System.err.println(e.getMessage());
}
Thanks And Best Regards,
Dinesh.