AXIS

Hello

I use Tomcat 4.1, and axis (last version). I have 5 web apps. Each one have the same deployed service (which returns nothing and has a foo parameter). This service use a dll (the LPSolve one) which is located in the WEB-INF/lib directory of each application. Each service calls the service of the other web application.

At the first execution on webapp1, no problem. But when the webapp1 service calls the webapp2 service then the following exception is thrown:

java.lang.reflect.InvocationTargetException

at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)

at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)

at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)

at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)

Any suggestions ?

[920 byte] By [hpouyllaua] at [2007-11-26 19:05:48]
# 1
Ok my problem is a usual ClassLoader problem.I put the dll in Tomcat 's "commen/lib" directory as indicated in other forums but still I get the following error :java.lang.UnsatisfiedLinkError: Native Library already loaded in another classloader ...etc.
hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Native libraries can only be loaded once. Ensure that you only have exactly one application loading the .dll.
bckrispia at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
But I want every applications to use the library. I though putting the dll in "common/lib" would make it loaded once because the Tomcat class loader would handle it (and apps class loaders are children of it). But still, does not work.
hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Do any of your servlets call System.loadLibrary() on this DLL?
bckrispia at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
(thank you for your patience)No, my web service does not call the loadLibrary() function.
hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Hmm, interesting. Do a directory search for the DLL in question. Make sure it is only in one place under the Tomcat heirarchy.
bckrispia at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
Yes I'm sure about that ... I guess I would need to unload the library after each use in the service but it is impossible.
hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

?

That doesn't make any sense.You can't unload a native library. And even if you could, why would you want to? The general pattern is that there is some static initializer that loads the library once, and from that point on, it's available to all classes w/in the same classloader (or any of the classloader's children).

Post the complete stack trace of what happens when this error fires.

bckrispia at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

> ... This service use a dll (the LPSolve one) which is located

> in the WEB-INF/lib directory of each application.

Try to put your LPSolve.dll on a directory which is on the "PATH" of your OS (or LD LIBRARY PATH on UNIX) e.g. bin directory of JDK or winnt/system32 or any folder which is on your PATH. See this forum for a related discussion http://forum.java.sun.com/thread.jspa?threadID=563861&messageID=3123713

-BJ

Bimalesha at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
I already tried that ... didn't work
hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

I put my call to the API in a thread and I get the following error :

Exception in thread "Thread-20" java.lang.UnsatisfiedLinkError: Native Library C:\Tomcat 4.1\common\lib\lpsolve\lpsolve55j.dll already loaded in another classloader

at java.lang.ClassLoader.loadLibrary0(Unknown Source)

at java.lang.ClassLoader.loadLibrary(Unknown Source)

at java.lang.Runtime.loadLibrary0(Unknown Source)

at java.lang.System.loadLibrary(Unknown Source)

at lpsolve.LpSolve.<clinit>(LpSolve.java:274)

at model.lp.BuildProblem.solve(BuildProblem.java:55)

at model.lp.BuildProblem.run(BuildProblem.java:47)

at java.lang.Thread.run(Unknown Source)

Otherwise I got this one :

AxisFault

faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException

faultSubcode:

faultString: java.lang.reflect.InvocationTargetException

faultActor:

faultNode:

faultDetail:

{http://xml.apache.org/axis/}hostname:antigone

java.lang.reflect.InvocationTargetException

at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)

at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)

at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)

at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)

at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)

at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)

at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

at javax.xml.parsers.SAXParser.parse(Unknown Source)

at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)

at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)

at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)

at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)

at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)

at org.apache.axis.client.Call.invokeEngine(Call.java:2784)

at org.apache.axis.client.Call.invoke(Call.java:2767)

at org.apache.axis.client.Call.invoke(Call.java:2443)

at org.apache.axis.client.Call.invoke(Call.java:2366)

at org.apache.axis.client.Call.invoke(Call.java:1812)

at negotiation.SvcNegotiate2.negotiate(SvcNegotiate2.java:156)

at negotiation.SvcNegotiate.negotiate(SvcNegotiate.java:185)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)

at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)

at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)

at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)

at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)

at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)

at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453)

at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)

at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)

at java.lang.Thread.run(Unknown Source)

hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12

>lpsolve.LpSolve.<clinit>(LpSolve.java:274)

>at model.lp.BuildProblem.solve(BuildProblem.java:55)

>at model.lp.BuildProblem.run(BuildProblem.java:47)

Are these classes you wrote? This stack trace shows you the class responsible for the Exception. What's at line 274 in LpSolve?

bckrispia at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 13
yeah I know and at line 274, guess what, it's the dll loading:System.loadLibrary("lpsolve55j");And the library lpsolve55j.dll is in the common/lib directory of Tomcat
hpouyllaua at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 14

Didn't you tell me above that none of your classes called this method?

:P

Well, that's your problem. As I said before, a DLL can be loaded once and only once. What you need to do is:

1) Make *certain* that this is the only loadLibrary call for this DLL in any class.

2) Make sure that the System.loadLibrary() call takes place in a safe place - like a static initializer.

bckrispia at 2007-7-9 20:56:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 15
yeah so I have to modify the code of the API ?That can't be possible because If I call 6 times the method where I use the library there's no problem; it executes 6 times the loadLibrary if it's done in a single service, so by a unique classe loader.
hpouyllaua at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 16

> That can't be possible

*sigh* You just don't get it, do you?

> because If I call 6 times the

> method where I use the library there's no problem; it

> executes 6 times the loadLibrary if it's done in a

> single service, so by a unique classe loader.

*sigh*

You can call the native method as many times as you like.

YOU CAN ONLY LOAD THE DLL LIBRARY ONCE

Just ONCE

Not TWICE

SIX TIMES is right out!

*sigh*

bckrispia at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 17
Lolok, then I have to find a way to call the loadLibrary just once. Is that possible to give this instruction to Tomcat ?
hpouyllaua at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 18
Ok, now that *that's* out of the way...Look [url= http://wiki.apache.org/tomcat/HowTo#head-a4b7185ee95d0cf14a48f92c08d1eb66b561139d]here[/url] for an example.
bckrispia at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 19
Thank you it solved it.In fact I did all what is described in the link you gave except to put also the jar in shared/lib.So it works now :) Thanks a lot again !
hpouyllaua at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 20
Glad to hear it! Feed me dukes! :D
bckrispia at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 21
*Ahem...*
bckrispia at 2007-7-9 20:56:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...