ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JavaCompute with external jar

Post new topic  Reply to topic Goto page 1, 2  Next
 JavaCompute with external jar « View previous topic :: View next topic » 
Author Message
accosun
PostPosted: Thu Nov 09, 2006 6:40 am    Post subject: JavaCompute with external jar Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

Hi!

I solved the problem with jar compiled with 1.5 JRE, and now I've got another one.

My external jar is a proxy, wich creates SOAP message, sends it to a WebService and then returns to my JavaCompute node an object with some data.

In my JCN I receive some XML data (MQ message) and forward this data as input attributes to that proxy. I should create an instance of special class ASGAdminWSClient (which is defined in an external jar).
But for unknown reason JCN cannot initializes it, I've got NullPointerException...

Here is a piece of my JCN code

public class MF_PROXY1_WS_JavaCompute extends MbJavaComputeNode {

public void evaluate(MbMessageAssembly contact admin) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");

MbMessage inMessage = contact admin.getMessage();

// create new message
MbMessage outMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,
outMessage);

// optionally copy message headers
copyMessageHeaders(inMessage, outMessage);

// ----------------------------------------------------------
// Add user code below

String login = (String)inMessage.evaluateXPath("string(message/login)");
String pass = (String)inMessage.evaluateXPath("string(message/password)");
String pSize = (String)inMessage.evaluateXPath("string(message/getAllRoles/portionSize)");


ASGAdminWSClient client = null;
try {
client = new ASGAdminWSClient();

**** client is null here!!! ********

} catch ( Exception e) {
System.out.println("Error in construct" + e.getMessage());
e.printStackTrace();
}
client.setUsername(login);

client.setPassword(pass);

Integer ppSize = Integer.valueOf(pSize);
int pInt=ppSize.intValue();

ru.fors.asg.ws.data.AppRoleSearchResult result = null;
try {
result = client.getAllRoles(pInt);
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ASGVerificationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ASGTechnicalException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ASGAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
result = client.getAllRoles(pInt);
} catch (Exception e) {
e.printStackTrace();
}

.....


I've written a static client, which performs the same functions and it WORKS!

Here it is:

* Date: Nov 9, 2006
* Time: 5:04:20 PM
* To change this template use File | Settings | File Templates.
*/
public class MakeAtest {
public static void main(String[] args) {
ASGAdminWSClient client = null;
try {
client = new ASGAdminWSClient();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
// set properties
client.setUsername("user");
client.setPassword("password");
try {
AppRoleSearchResult srchResult = client.getAllRoles(5);
LongWS[] rIds = srchResult.getRolesID();
for(int i=0, l= rIds.length; i < l; i++){
System.out.println("RoleId:"+ rIds[i].getValue());
}
} catch (RemoteException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ASGAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ASGVerificationException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ASGTechnicalException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}

Where is a mistake or a bug in my first code??

Thank you in advance, Alex
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Thu Nov 09, 2006 7:01 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

If you've got a WSDL for the WebService, I would skip the Java code entirely and just build a message flow to invoke the Service using the HTTPRequest node.

Unless you need to provide authentication for the Web Service using a mechanism that the HTTPRequest node doesn't currently support.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
accosun
PostPosted: Thu Nov 09, 2006 7:30 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

It's work fine with HTTPRequest, I've always tried this. The main goal of this configuration is to test the possibility of creating SOAP messages through an external proxy.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
accosun
PostPosted: Thu Nov 09, 2006 8:09 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

I guess, broker can't find some classes from CLASSPATH. But I've changed CLASSPATH variable in mqsiprofile.cmd already...
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Thu Nov 09, 2006 8:11 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

....

ugh.

Okay.

If you're getting a null pointer exception, then it means that the new operation is failing for some reason. It's a little hard to tell why - maybe you can look at using the Java debugger to poke into your code a bit more, or you can look at using User Trace to help a bit more too.

It could also be a classpath/class loader issue, where you haven't put the external Jar in the right place - but I'd think you would see a ClassNotFound for that.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
accosun
PostPosted: Thu Nov 09, 2006 8:35 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

The code is correct (the second one) ! It works, if i run it in command line. It doesn't work only at broker level.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Thu Nov 09, 2006 9:26 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You may have put the class in a place where it's getting loaded by the wrong classloader.

You should have the external Jar and any dependant jars that are not in the standard library into either the BAR file or the shared-classes directory in the broker workpath.

I don't recommend changing mqsiprofile.cmd unless you absolutely have to.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
accosun
PostPosted: Thu Nov 09, 2006 11:48 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

All external and dependant JARs are alredy in shared-classes directory. I'll put them into BAR and then try again.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
accosun
PostPosted: Wed Nov 22, 2006 8:10 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

Hi again!

Back to the problem... Just to refresh...

My external jar is a proxy, wich creates SOAP message, sends it to a WebService and then returns to my JavaCompute node an object with some data.

In my JCN I receive some XML data (MQ message) and forward this data as input attributes to that proxy. I should create an instance of special class ASGAdminWSClient (which is defined in an external jar).
But for unknown reason JCN cannot initializes it, I've got NullPointerException...

When I create a simple java application, which performs EXACTLY the same procedure from a command line, it WORKS fine!

To solve this problem i made the following:
1. completely reinstalled Broker and Toolkit
2. Install fix for APAR IY77292 (

IY77292
-------
Problem summary
---------------
External jar files referenced by a plugin are not found by the broker.

3. Added external JARs to JCN project
4. Put external JARs to <broker_workpath_dir>/shared-classes
5. deployed BAR with message flow to excecution group 'default'
6. restarted broker.
7. run Debug

After that i got THE SAME error.

then I went another way and:
1. Imported external JARs into message flow projet
2. added them to my BAR file
3. restarted broker.
4. run Debug

And again, i got THE SAME error.

The only way I could solve it was to directly use classloader in my JCN:

...
ClassLoader curCL = Thread.currentThread().getContextClassLoader();
ClassLoader tgtCL = this.getClass().getClassLoader();
....

but it's a wrong way.

What else can I do in this situation? Should i install Toolkit fixpack 2?

Thank you in advance, Alexander
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Wed Nov 22, 2006 8:22 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Okay, so you have isolated it to a classloader problem.

You can try putting your external jar in the broker jre/lib/ext directory.

This might be a JRE security issue.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
accosun
PostPosted: Wed Nov 22, 2006 8:36 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

Thank you for advice, Jeff, but unfortunatelly it still doesn't work... I copied JARs to jre/lib/ext , restarted broker... The same exception message appeared.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Wed Nov 22, 2006 8:49 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You may need to configure a policy file, then.

There's a default policy file supplied with broker that grants (jre/lib/security/java.policy) that grants permissions to jre/lib/ext.

You can use the IBM_JAVA_OPTIONS environment variable to add the
"-Djava.security.manager –Djava.security.policy=<broker install>/jre/lib/security/java.policy" properties to the broker startup.

But you should really look at the results of a Debug level User Trace first and see if it gives you more information.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
accosun
PostPosted: Wed Nov 22, 2006 9:32 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

I have created environment variable

set IBM_JAVA_OPTIONS = "-Djava.security.manager –Djava.security.policy=c:/IBM/MQSI/6.0/jre/lib/security/java.policy"

directly in mqsiprofile.cmd

As i understand, these lines from java.policy mean, that every jar from c:/IBM/MQSI/6.0/jre/lib/ext has all permissions

"....
// Standard extensions get all permissions by default

grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

..."

Then i have restarted broker - nothing new...
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Wed Nov 22, 2006 9:44 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Then it's probably not a JRE security issue.

Look at a User Trace, debug level, see if it gives you any more clues. Otherwise, you need to open a PMR.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
accosun
PostPosted: Fri Nov 24, 2006 8:01 am    Post subject: Reply with quote

Apprentice

Joined: 20 Dec 2001
Posts: 45
Location: Moscow

Jeff, thank you for your advices!
I got, that my problem description was not accurate, sorry for that!

Well, I've got an external jar (lets call it Ext_Jar), that is called by JCN. And this Ext_Jar is loaded by broker classloader!! But this Ext_Jar needs to load another class from one more JAR (its name is wsclient_extender.jar). I also add this wsclient_extender.jar to my JCN as an external JAR, put it to shared-classes dir, add it to BAR file etc. And broker classloader just doesn't see wsclient_extender.jar and does't load it.

That is the main problem. Is it possible to work around this problem without using classloader in JCN?

Thank you, Alexander
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JavaCompute with external jar
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.