I am writing an application that invokes an Oracle web service. The web service client code was provided me.
This application uses a custom subclass of URLClassLoader to load jars at run-time. Running the unit tests from my local machine works fine, however when I deploy the application on the server and run it, I get the following error. Other classes/jars are loading fine through the custom ClassLoader.
Not sure why this is happening? Maybe FactoryFinder is using a separate ClassLoader instance? Any help is appreciated. Thanks!
javax.xml.rpc.ServiceException: Provider oracle.j2ee.ws.client.ServiceFactoryImpl not found
at javax.xml.rpc.FactoryFinder.newInstance(FactoryFinder.java:44)
at javax.xml.rpc.FactoryFinder.find(FactoryFinder.java:137)
at javax.xml.rpc.ServiceFactory.newInstance(ServiceFactory.java:69)
at com.mycomp.myapp.oracle.client.TSClient.<init>(TSClient.java:34)
at com.mycomp.myapp.oracle.LaborHours.update(LaborHours.java:92)
at com.mycomp.myapp.oracle.OracleConnection.updateMetrics(OracleConnection.java:73)
at com.mycomp.myapp.Project.crawl(Project.java:150)
at com.mycomp.myapp.Main.main(Main.java:302)
This is the conclusion I came up with.
ServiceFactory uses it's own class loading mechanism (which apparently is a different instance than my custom class loader).
I had to use this hack http://forums.sun.com/thread.jspa?threadID=300557 to add the jars to the system class loader's class path.
Related
I have some personal project where I am trying to share some class instance between webapp and a normal app. My project structure is something like below:
+ NormalApp
+ WebApp
I am starting the application from the NormalApp and I included WebApp using EmbeddedTomcat. Now I have a class named Notifier in WebApp. I want to use the instance of Notifier in NormalApp without losing it's state.
Could someone tell me how can I achieve this scenario?
I have some plan in mind like setting the Tomcat class loader to use Systems class loader. I tried it but couldn't able to achieve it. Is my understanding of this wrong?
Have you tried making your normal app like web components ? so your application will be available when tomcat start. And you can use System properties to pass parameters to the tomcat.
Another option is using Spring boot. Here is a tutorial
https://spring.io/guides/gs/spring-boot/
http://spring.io/guides/tutorials/bookmarks/
I'm currently creating my own JDBCRealm and more specifically, I'm overriding the Authenticate method. The override was no problem, and I got it to work using SHA authentication.
The problems starting arising when I needed to access a different column that isn't covered by Tomcat's own methods, like getPassword(username) and getPrincipal(username).
I have a Hibernate method that retrieves a user based on their username and it looks like:
UsersDTO user = UsersDAO.getUser(username);
The problem is, that because the code is part of the Tomcat library and not the application, calling the method doesn't work. It throws no exceptions and nothing gets logged to catalina.out, it just presents me with a 500 HTTP error.
I have tried numerous things, but I'm at a loss at the moment. Can anyone shed a light on my problem?
You cannot call classes loaded by the app classloader from classes loaded by the server classloader.
You should deploy your jars in a way that all the invocations are done between classes loaded by the same classloader, or from classes loaded by a lower level classloader to classes loaded by a higher level classloader.
Take a look at this. It's related to Weblogic, but the same concepts apply to Tomcat.
http://docs.oracle.com/cd/E24329_01/web.1211/e24368/classloading.htm
Tomcat is implemented with Apache Commons Logging library. So with proper implementation of that logging library in your code, tomcat should be able to log your error properly.
see reference here
I have embedded Jetty container inside my main server and I also use Jersey 2.5 for handling REST resources.
everything seems to work well and now I would like to pass my server's context class into each of my REST resources.
I'm having hard time understanding how to do that...
If someone can provide full code example - it could be awesome!
Many thanks
What exactly do you mean when you say you have a Jetty container inside your "main server"? Are you programmatically executing Jetty within the application? Also, when you say "context" are you referring to the ServletContext?
In tomcat web container spring listens to session and executes a destroy-method on a "session-scoped" bean, that invokes a web-service.
sometimes this strange exception is raised:
interface com.sun.xml.ws.developer.WSBindingProvider is not visible from class loader
What can this mean?
This has to be a jar conflict issue. Check the below link if it helps:
generated-client-error
Regarding the issue "interface com.sun.xml.ws.developer.WSBindingProvider is not visible from class loader", the same issue has been envounterd when developping 3rd party h2h connection under the GlassFish Server v2.1 . But after moving the 3rd party related jar from ".../lib/ext” into the “.../lib” level this issue possible to be rectified.
We have a number of web service client applications which interface between our main customer facing application and backend web services. These web service application generate their own JAXWS stub code to directly interface with the web services and implementation code to provide a clean interface between the JAXWS code and any application that wishes to use it. We've had some small problems with these over the last few weeks but most of them have been resolved.
When it was time to integrate these into the customer facing application we encountered numerous problems, mainly focused around JDK1.5 and 1.6 incompatibility. These have been resolved now, however we have hit another problem which we have no resolution for. The web service clients use AOP to set common things like header credentials, exception handling and throttling:
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* MyService.*(..))" />
<aop:aspect id="throttling" ref="throttlingAdvisor">
<aop:around pointcut-ref="pointcut" method="doThrottle" />
</aop:aspect>
<aop:aspect id="errorHandling" ref="errorHandlingAdvisor">
<aop:around pointcut-ref="pointcut" method="handleExceptions" />
Each aspect refers to a POJO bean, these beans include the method stated in the configuration with the method parameter type of org.aspectj.lang.ProceedingJoinPoint, this is used to extract the arguments of the method I'm intercepting.
We have one of these for each of the web service clients (in an applicationContext-webservicename.xml). This xml file is included in the packaged JAR which is included in the customer facing application and imported into the main applicationContext.xml loaded by the web.xml of the customer facing application.
We have a number of unit tests for these web clients, they all pass proving there's nothing wrong with them individually. When all the services are included in the customer facing applications we get a java.lang.NoClassDefFoundError: ProceedingJoinPoint exception when it starts up (we're using tomcat 5.5 with JDK1.5.0_17).
I looked up the JavaDoc for java.lang.NoClassDefFoundError just in case it had a special meaning, looks like the JVM thinks the class does not exist. I then looked for the jar which contains the classes it's claiming it cannot find (aspectjrt-1.5.4.jar and aspectjweaver-1.5.4.jar), there is a duplication of these classes so I tried removing each jar in turn to see what would happen, exactly the same error.
Am I missing a required dependency? Is there a common cause to this problem (I've searched for this yesterday not finding much)? Any help would be most appreciated.
After all this time we managed to find the solution to this problem, we use Bamboo to build our projects when a SVN commit is detected. Although the bamboo environment was set up to match our development machines when it built a dependent project it produced this weird problem.
We're still not sure why it did this, however in the meantime we're manually building and deploying this particular project.
My advice to anyone experiencing a similar problem, just isolate yourself from internal maven repos and rebuild all your projects locally.
Thanks for everyone's help.
Could be a class loader issue. Where are the AspectJ JARs? If you have them in your WEB-INF/lib now, perhaps you could try copying them to the Tomcat common/lib and see if that helps.
It could be that the app server class loader needs them on startup, but the application class loader hasn't gotten them from WEB-INF because it's lower in the class loader hierarchy.
Only add aspectjrt.jar to the server/lib folder, NOT the aspectjweaver.jar. Duplicate classes can also lead to confusion. The runtime jar (the "rt" stands for runtime) is supposed for the runtime. The weaver jar is used for compile/weave time. Are you using LTW or CTW?