Archive for the ‘General’ Category
Dynamic serviceUrl with Spring’s HttpInvokerProxyFactoryBean
Abstract
How to set dynamically the URL used by a HttpInvokerProxyFactoryBean in a Spring-deployed WAR?
Detailed Case
I have to deploy a GWT/GXT application, calling two distant services:
a remote EJB
a service accessed through Spring Remoting
Here is the Spring configuration file I firstly used:
[xml]
<util:properties id="jndiProperties" location="classpath:jndi.properties"/>
<jee:remote-slsb id="myRemoteEJBService" jndi-name="ejb.remote.myRemoteService"
business-interface="lalou.jonathan.myRemoteEJBService"
environment-ref="jndiProperties" cache-home="false"
lookup-home-on-startup="false" refresh-home-on-connect-failure="true" />
<bean id="mySpringRemoteService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceInterface"
value="lalou.jonathan.services.mySpringRemoteService" />
<property name="serviceUrl" value="${spring.remote.service.url}"/>
</bean>
[/xml]
Unhappily, even though the remote EJB is retrieved (which proves that the jndi file is available in the classpath and rightly loaded), the Spring Remote service is not. I had to write the URL in hard in the configuration file… This is not very efficient when you work in a large team, with different production and testings environments!
This is the log when myRemoteEJBService bean is loaded:
[java]2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory – Creating shared instance of singleton bean ‘myRemoteEJBService’
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory – Creating instance of bean ‘myRemoteEJBService’
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory – Eagerly caching bean ‘myRemoteEJBService’ to allow for resolving potential circular references
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory – Returning cached instance of singleton bean ‘jndiProperties’
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory – Invoking afterPropertiesSet() on bean with name ‘myRemoteEJBService’
2010-08-17 16:05:42,937 DEBUG framework.JdkDynamicAopProxy – Creating JDK dynamic proxy: target source is EmptyTargetSource: no target class, static
2010-08-17 16:05:42,953 DEBUG support.DefaultListableBeanFactory – Finished creating instance of bean ‘myRemoteEJBService'[/java]
That is the log when mySpringRemoteService is loaded:
[java]2010-08-17 16:05:42,968 DEBUG support.DefaultListableBeanFactory – Creating shared instance of singleton bean ‘mySpringRemoteService’
2010-08-17 16:05:42,968 DEBUG support.DefaultListableBeanFactory – Creating instance of bean ‘mySpringRemoteService’
2010-08-17 16:05:42,984 DEBUG support.DefaultListableBeanFactory – Eagerly caching bean ‘mySpringRemoteService’ to allow for resolving potential circular references
2010-08-17 16:05:43,234 DEBUG support.DefaultListableBeanFactory – Invoking afterPropertiesSet() on bean with name ‘mySpringRemoteService’
2010-08-17 16:05:43,250 DEBUG framework.JdkDynamicAopProxy – Creating JDK dynamic proxy: target source is EmptyTargetSource: no target class, static
2010-08-17 16:05:43,250 DEBUG support.DefaultListableBeanFactory – Finished creating instance of bean ‘mySpringRemoteService'[/java]
You can notice that no mention to jndiProperties appears. Here is the key of the problem: jndiProperties is considered as a bean among others, which cannot be accessed easyly from the HttpInvokerProxyFactoryBean.
Fix
To fix the issue, you have to add an actual property holder in Spring XML configuration file, ie after:
[xml]<util:properties id="jndiProperties" location="classpath:jndi.properties"/>[/xml]
add an instanciation of PropertyPlaceholderConfigurer:
[xml]<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jndi.properties"/>
</bean>[/xml]
java.lang.OutOfMemoryError: PermGen space
Case:
I have to redeploy many times a day a WAR on a WebLogic 10 server, using Hotspot (Sun JVM) with Java 6. After some cycles deploy/undeploy, Hotspot crashes with the following error:
java.lang.OutOfMemoryError: PermGen space
Complete stacktrace:
[java]2010-08-17 11:26:56,718 ERROR context.ContextLoader – Context initialization failed
java.lang.IllegalStateException: Unable to load Java 1.5 dependent class [org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver]
at org.springframework.beans.factory.support.AutowireUtils.createAutowireCandidateResolver(AutowireUtils.java:125)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:103)
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:176)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:121)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1863)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3126)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1512)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:486)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:1267)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:409)
at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:43)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:569)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:150)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:116)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:323)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:844)
at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1253)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:440)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:163)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:13)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:68)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:328)
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:285)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:253)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:177)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:37)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:328)
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:285)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:253)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:177)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:37)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:242)
at org.springframework.beans.factory.support.AutowireUtils.createAutowireCandidateResolver(AutowireUtils.java:120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:103)
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:176)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:121)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
<Aug 17, 2010 11:26:56 AM CEST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: java.lang.IllegalStateException: Unable to load Java
1.5 dependent class [org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver].
java.lang.IllegalStateException: Unable to load Java 1.5 dependent class [org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver]
at org.springframework.beans.factory.support.AutowireUtils.createAutowireCandidateResolver(AutowireUtils.java:125)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:103)
at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:176)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:121)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
Truncated. see log file for complete stacktrace
Caused By: java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:328)
Truncated. see log file for complete stacktrace
>
<Aug 17, 2010 11:26:56 AM CEST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID ‘1282037204562’ for task ‘9’. Error is: ‘weblogic.application.ModuleException: ‘
weblogic.application.ModuleException:
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1514)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:486)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
Truncated. see log file for complete stacktrace
Caused By: java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:328)
Truncated. see log file for complete stacktrace
>[/java]
A short explanation
The error seems to be linked to the garbage collection. From what I could read on the web, static objects used in CGlib (and/or jars depending on the library, such as the wide spread Hibernate, Spring, etc.) are the source of the crash.
Fix
Switching HotSpot to Oracle/BEA’s JVM, aka JRockit, makes the error (almost) disappear.
Alternatively, if you can’t change the JVM, a workaround consists in upgrading the following parameter on JVM launching:
-XX:MaxPermSize=256m
weblogic-maven-plugin / java.net.MalformedURLException: no protocol: and
Case
I run mvn weblogic:deploy, with a correct configuration inside pom.xml file, in order to deploy a WAR on a WebLogic 10 server. My development machine runs under Windows XP, the distant server is under Linux. I get the following error:
java.net.MalformedURLException: no protocol: and
Complete stacktrace:
[java][INFO] Scanning for projects…
[INFO] Searching repository for plugin with prefix: ‘weblogic’.
[INFO] ————————————————————————
[INFO] Building myWar Maven Webapp
[INFO] task-segment: [weblogic:deploy]
[INFO] ————————————————————————
Downloading: http://repository.codehaus.org/weblogic/weblogic/9.0/weblogic-9.0.pom
[INFO] Unable to find resource ‘weblogic:weblogic:pom:9.0’ in repository codehaus.org (http://repository.codehaus.org)
Downloading: http://repo1.maven.org/maven2/weblogic/weblogic/9.0/weblogic-9.0.pom
[INFO] Unable to find resource ‘weblogic:weblogic:pom:9.0’ in repository central (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/weblogic/weblogic/9.0/weblogic-9.0.pom
[INFO] Unable to find resource ‘weblogic:weblogic:pom:9.0’ in repository central (http://repo1.maven.org/maven2)
Downloading: http://repository.codehaus.org/weblogic/webservices/9.0/webservices-9.0.pom
[INFO] Unable to find resource ‘weblogic:webservices:pom:9.0’ in repository codehaus.org (http://repository.codehaus.org)
Downloading: http://repo1.maven.org/maven2/weblogic/webservices/9.0/webservices-9.0.pom
[INFO] Unable to find resource ‘weblogic:webservices:pom:9.0’ in repository central (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/weblogic/webservices/9.0/webservices-9.0.pom
[INFO] Unable to find resource ‘weblogic:webservices:pom:9.0’ in repository central (http://repo1.maven.org/maven2)
[INFO] [weblogic:deploy]
[INFO] Weblogic Deployment beginning with parameters DeployMojoBase[adminServerHostName = myLocalHost, adminServerProtocol = t3, adminServerPort = 7001, userId = weblogic, password = myPassword, artifactPath = C:\…\target/myWar.war, projectPackaging = war, name = myWar, targetNames = oneTier, remote = true]
[INFO] Weblogic Deployment parameters [-adminurl, t3://myLocalHost:7001, -username, weblogic, -password, myPassword, -verbose, -debug, -name, myWar, -targets, muletier, -upload, -source, C:\…\target/myWar, -deploy]
weblogic.Deployer invoked with options: -adminurl t3://myLocalHost:7001 -username weblogic -verbose -debug -name myWar -targets muletier -upload -source C:\workarea\development\primeweb\primeweb\projects\strategic\myWar\target/myWar -deploy
[WebLogicDeploymentManagerImpl.<init>():103] : Constructing DeploymentManager for J2EE version V1_4
deployments
[WebLogicDeploymentManagerImpl.getNewConnection():146] : Connecting to admin server at myLocalHost:7001, as user weblogic
[ServerConnectionImpl.getEnvironment():288] : setting environment
[ServerConnectionImpl.getEnvironment():291] : getting context using t3://myLocalHost:7001
[ServerConnectionImpl.getMBeanServer():239] : Connecting to MBeanServer at service:jmx:t3://myLocalHost:7001/jndi/weblogic.management.mbeanservers.domainruntime
[ServerConnectionImpl.getMBeanServer():239] : Connecting to MBeanServer at service:jmx:t3://myLocalHost:7001/jndi/weblogic.management.mbeanservers.runtime
[DomainManager.resetDomain():36] : Getting new domain
[DomainManager.resetDomain():39] : Using pending domain: true
[MBeanCache.addNotificationListener():96] : Adding notification listener for weblogic.deploy.api.spi.deploy.mbeans.TargetCache@19ccba
[MBeanCache.addNotificationListener():107] : Disabling mbean caching due to: java.net.MalformedURLException: no protocol: and
[MBeanCache.addNotificationListener():96] : Adding notification listener for weblogic.deploy.api.spi.deploy.mbeans.ModuleCache@ae1cf
[MBeanCache.addNotificationListener():107] : Disabling mbean caching due to: java.net.MalformedURLException: no protocol: and
[ServerConnectionImpl.initialize():171] : Connected to WLS domain: myMainDomain
[ServerConnectionImpl.setRemote():482] : Running in remote mode
[ServerConnectionImpl.init():161] : Initializing ServerConnection : weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl@a0e990
[BasicOperation.dumpTmids():690] : Incoming tmids:
[BasicOperation.dumpTmids():692] : {Target=muletier, WebLogicTargetType=server, Name=myWar}, targeted=true
[BasicOperation.deriveAppName():139] : appname established as: myWar
<Aug 16, 2010 11:46:42 AM CEST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, myWar [archive: C:\workarea\development\primeweb\primeweb\projects\strategic\myWar\target\myWar], to muletier .>
[ServerConnectionImpl.upload():658] : Uploaded app to C:\win32app\bea\user_projects\domains\myMainDomain\.\servers\adminServer\upload\myWar
[BasicOperation.dumpTmids():690] : Incoming tmids:
[BasicOperation.dumpTmids():692] : {Target=muletier, WebLogicTargetType=server, Name=myWar}, targeted=true
[BasicOperation.loadGeneralOptions():607] : Delete Files:false
Timeout :3600000
Targets:
muletier
ModuleTargets={}
SubModuleTargets={}
}
Files:
null
Deployment Plan: null
App root: C:\win32app\bea\user_projects\domains\myMainDomain\.\servers\adminServer\upload\myWar
App config: C:\win32app\bea\user_projects\domains\myMainDomain\.\servers\adminServer\upload\myWar\plan
Deployment Options: {isRetireGracefully=true,isGracefulProductionToAdmin=false,isGracefulIgnoreSessions=false,rmiGracePeriod=-1,retireTimeoutSecs=-1,undeployAllVersions=false,archiveVersion=null,planVersion=null,isLibrary=false,libSpecVersion=null,libImplVersion=null,stageMode=null,clusterTimeout=3600000,altDD=null,altWlsDD=null,name=myWar,securityModel=null,securityValidationEnabled=false,versionIdentifier=null,isTestMode=false,forceUndeployTimeout=0,defaultSubmoduleTargets=true,timeout=0}
[BasicOperation.execute():424] : Initiating deploy operation for app, myWar, on targets:
[BasicOperation.execute():426] : muletier
<strong>java.net.MalformedURLException: no protocol: and</strong>
at java.net.URL.<init>(URL.java:567)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:751)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:147)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1667)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1323)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at java.rmi.MarshalledObject.get(MarshalledObject.java:142)
at javax.management.remote.rmi.RMIConnectionImpl$6.run(RMIConnectionImpl.java:1513)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.unwrap(RMIConnectionImpl.java:1505)
at javax.management.remote.rmi.RMIConnectionImpl.access$500(RMIConnectionImpl.java:72)
at javax.management.remote.rmi.RMIConnectionImpl$7.run(RMIConnectionImpl.java:1548)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.unwrap(RMIConnectionImpl.java:1544)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:771)
at javax.management.remote.rmi.RMIConnectionImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
[ServerConnectionImpl.close():334] : Closing DM connection
[ServerConnectionImpl.close():354] : Unregistered all listeners
[ServerConnectionImpl.closeJMX():374] : Closed JMX connection
[ServerConnectionImpl.closeJMX():386] : Closed Runtime JMX connection
[ServerConnectionImpl.closeJMX():398] : Closed Edit JMX connection[/java]
Explanation
Indeed, the " and " comes from the address of my local Maven 2 repository: C:\Documents and Settings\myLogin\.m2\repository, which is the default location. I consider this to be a bug of Mojo’s weblogic-maven-plugin plugin.
Fix
You do not have many choices :-(… You have to move your repository to a destination without blank spaces, such as C:\M2_repository.
Then, take care to edit your settings.xml, and add the following block after <settings> tag:
[xml]<localRepository>C:\M2_repository</localRepository>[/xml]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
Error:
While launching a WebLogic (10.3.3) server, I got the exception:
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
Fix:
Indeed, I had another WebLogic (9.2) instance running. Both of them were running in Debug mode, with the same debug port.
To fix the issue, check if your are not in the same situation: two applications running on the same debug port.
Another point is a little mysterious: when I run WebLogic 10 instance before the WebLogic 9, then an error occurs, too, but the message is different:
ERROR: transport error 202: bind failed: Address already in use ["transport.c",L41]
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]
JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initializedThe application has requested the JVM to exit with an fatal error from JNI. Error message:
JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)
Press any key to continue . . .
Embedded error: Could not create task or type of type: apt.
Case:
In your Maven2’s pom.xml, you call Java’s APT (Annotation Processing Tool) via maven-antrun-plugin, to generate additional sources based on annotations in your java code.
[xml]<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>…</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<apt
srcdir="src/main/java/com/lalou/jonathan/"
destdir="classes" debug="on"
compile="false" factory="com.lalou.jonathan.Factory preprocessdir="generated-sources/javacc"
classpathref="cpannot" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>[/xml]
You get the following error:
Embedded error: Could not create task or type of type: apt.
Complete stacktrace:
[java]Embedded error: Could not create task or type of type: apt.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
– You have misspelt ‘apt’.
Fix: check your spelling.
– The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
– The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the ‘ant-‘ JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
– The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
– The task is not an Ant core or optional task
and needs to be declared using <taskdef>.
– You are attempting to use a task defined using
<presetdef> or <macrodef> but have spelt wrong or not
defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath
Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.[/java]
Fix:
At least in my case, the error is not related at all to Ant. Therefore, no use searching for any ant-apt.jar and placing in in Ant’s lib folder…
Indeed, the error is known and was fixed with Maven 2.0.10 release. You simply have to upgrade your Maven2 installation, and environment variables (M2_HOME).
Transaction Management with Spring in AOP
Case
You have a couple of Hibernate DAOs, in which a huge amount of code is duplicated: begin transactions, try/catch, close transactions, etc.
You would like to factorize your code.
Fix
- Define a
SessionFactory, let’s sayhibernateSessionFactory, with your own settings.[xml]<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">(…)</bean>[/xml] - Define a
TransactionManager:[xml]<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="hibernateSessionFactory" />
</property>
</bean>[/xml] - Define transactions advices:
[xml]<tx:advice id="hibTxManager" transaction-manager="hibernateTransactionManager">
<tx:attributes>
<tx:method name="*" propagation="NEVER" read-only="true" isolation="READ_COMMITTED" rollback-for="find*" no-rollback-for="dontFind*"/>
</tx:attributes>
</tx:advice>[/xml] name="*"–> the aspect will apply to all methods. You may filter on patterns such as find*, get*, save*, etc.propagation="NEVER"–> hints the propagation level. Available options areREQUIRED, SUPPORTS, MANDATORY,REQUIRES_NEW, NOT_SUPPORTED, NEVER, NESTED.isolation="READ_COMMITTED"–>rollback-for="find*"–> rollback all transactions following the given patternno-rollback-for="dontFind*"–> exceptions for rollbacks- Define the AOP configuration:
[xml]<aop:config>
<aop:pointcut id="hibOperation"
expression="execution(* com.lalou.jonathan.dao.hibernate.Hibernate*.*(..))" />
<aop:advisor pointcut-ref="hibOperation" advice-ref="hibTxManager" />
</aop:config>[/xml]
Many thanks to Jean-Pierre ISOARD for his help on this subject.
Deploy a webservice under Mule ESB using CXF
This short tutorial is aimed at showing the main steps allowing to deploy a WebService, using CXF framework, under a Mule ESB instance.
Java code
Declare an interface:
[java]@WebService
public interface BasicExampleServices {
@WebResult(name = "myReturnedInteger")
Integer getInteger(@WebParam(name="myInteger") Integer myInteger);
}[/java]
Implement this interface:
[java]@WebService(endpointInterface = "com.lalou.jonathan.services.BasicExampleServices", serviceName = "basicExampleServices")
public class WSBasicExampleServices implements BasicExampleServices {
public Integer getInteger(Integer param) {
return 12345;
}
}[/java]
XML files
Create a Spring config file ws-basicExample.xml:
[xml]<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="basicExampleService" scope="singleton"/>
</beans>[/xml]
Create a Mule configuration file ws-basicExample-config.xml:
[xml]<?xml version="1.0" encoding="UTF-8" ?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:management="http://www.mulesource.org/schema/mule/management/2.2"
xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"
xmlns:jetty="http://www.mulesource.org/schema/mule/jetty/2.2"
xsi:schemaLocation="http://www.mulesource.org/schema/mule/management/2.2
http://www.mulesource.org/schema/mule/management/2.2/mule-management.xsd
http://www.mulesource.org/schema/mule/core/2.2
http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.mulesource.org/schema/mule/vm/2.2
http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
http://www.mulesource.org/schema/mule/cxf/2.2
http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd
http://www.mulesource.org/schema/mule/stdio/2.2
http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd">
<spring:beans>
<spring:import resource="ws-basicExample.xml"/>
</spring:beans>
<model name="wsBasicExampleModel">
<service name="wsBasicExampleService">
<inbound>
<cxf:inbound-endpoint address="http://localhost:8282/services/basicExampleServices"/>
</inbound>
<component>
<spring-object bean="basicExampleService"/>
</component>
</service>
</model>
</mule>
[/xml]
Checks
- Run the Mule, pointing your config file.
- In your favorite webbrowser, open the URL:
[xml]http://localhost:8282/services/basicExampleServices?wsdl[/xml] - You can also execute a runtime test:
[java]public class WSBasicExampleServicesRuntimeTest {
private BasicExampleServices basicExampleServices;
@Before
public void setup() {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(BasicExampleServices.class);
factory.setAddress("http://localhost:8282/services/basicExampleServices");
basicExampleServices = (BasicExampleServices) factory.create();
}@Test
public void testGetInteger() {
final Integer expectedAnswer = 12345;
final Integer actualAnswer;
final Integer param = 912354;actualAnswer = basicExampleServices.getInteger(param);
assertNotNull(actualAnswer);
assertEquals(expectedAnswer, actualAnswer);
}}[/java]
The webservice contract is expected to be displayed.
Tutorial: Tomcat / OpenJMS integration
Install and Config
- Let’s assume you would like to run OpenJMS and Tomcat on the same server, eg
myLocalServer - Download OpenJMS from this page.
- Unzip the archive, extract it to
C:\exe\openjms-0.7.7-beta-1 - Set an environment variable:
set OPENJMS_HOME=C:\exe\openjms-0.7.7-beta-1 - Take the archive
$OPENJMS_HOME/lib/openjms-tunnel-0.7.7-beta-1.war- copy it to:
$CATALINA_HOME/webapps - rename it as:
openjms-tunnel.war
- copy it to:
- Edit
OPENJMS_HOME/config/openjms.xml:- Before the ending tag
</connectors>, add the block:<Connector scheme="http"> <ConnectionFactories> <ConnectionFactory name="HTTPConnectionFactory"/> </ConnectionFactories> </Connector>
- After the ending tag
</connectors>, add the block:<HttpConfiguration port="3030" bindAll="true" webServerHost="myLocalServer" webServerPort="8080" servlet="/openjms-tunnel/tunnel"/>
- Before the ending tag
Run applications
- Launch
$OPENJMS_HOME/bin/startup.bat. The following output is expected:OpenJMS 0.7.7-beta-1 The OpenJMS Group. (C) 1999-2007. All rights reserved. http://openjms.sourceforge.net 15:15:27.531 INFO [Main Thread] - Server accepting connections on tcp://myLocalServer:3035/ 15:15:27.547 INFO [Main Thread] - JNDI service accepting connections on tcp://myLocalServer:3035/ 15:15:27.547 INFO [Main Thread] - Admin service accepting connections on tcp://myLocalServer:3035/ 15:15:27.609 INFO [Main Thread] - Server accepting connections on rmi://myLocalServer:1099/ 15:15:27.609 INFO [Main Thread] - JNDI service accepting connections on rmi://myLocalServer:1099/ 15:15:27.625 INFO [Main Thread] - Admin service accepting connections on rmi://myLocalServer:1099/ 15:15:27.625 INFO [Main Thread] - Server accepting connections on http-server://myLocalServer:3030/ 15:15:27.625 INFO [Main Thread] - JNDI service accepting connections on http-server://myLocalServer:3030/ 15:15:27.625 INFO [Main Thread] - Admin service accepting connections on http-server://myLocalServer:3030/ - Launch Tomcat. A webapp with path
/openjms-tunneland display name “OpenJMS HTTP tunnel” should appear.
Checks
-
- Open Console² or an MS-DOS prompt
- Go to
$OPENJMS/examples/basic
- Run:
build. This will compile all the examples.
Check that OpenJMS is OK:
-
- Edit
jndi.properties,- Comment the property
java.naming.provider.url
- Add the line:
java.naming.provider.url=tcp://myLocalServer:3035
- Comment the property
- Run:
run Listener queue1
- Open a second tab
- Run:
run Sender queue1 5
- Expected output in the second tab:
C:\exe\openjms-0.7.7-beta-1\examples\basic>run Sender queue1 5 Using OPENJMS_HOME: ..\.. Using JAVA_HOME: C:\exe\beaweblo922\jdk150_10 Using CLASSPATH: .\;..\..\lib\openjms-0.7.7-beta-1.jar Sent: Message 1 Sent: Message 2 Sent: Message 3 Sent: Message 4 Sent: Message 5
- Expected output in the first tab:
C:\exe\openjms-0.7.7-beta-1\examples\basic>run Listener queue1 Using OPENJMS_HOME: C:\exe\openjms-0.7.7-beta-1 Using JAVA_HOME: C:\exe\beaweblo922\jdk150_10 Using CLASSPATH: .\;C:\exe\openjms-0.7.7-beta-1\lib\openjms-0.7.7-beta-1.jar Waiting for messages... Press [return] to quit Received: Message 1 Received: Message 2 Received: Message 3 Received: Message 4 Received: Message 5
- Expected output in the second tab:
- Edit
Check that OpenJMS/Tomcat link is OK:
Manual Check
-
- Stop the
Listenerinstance launched sooner - Edit
jndi.properties,- Comment the line
java.naming.provider.url=tcp://myLocalServer:3035
- Add the line:
java.naming.provider.url=http://myLocalServer:8080
(this is Tomcat manager URL)
- Comment the line
- Run:
run Listener queue1
- Open a second tab
- Run:
run Sender queue1 5
- The expected output are the same as above.
- Stop the
GUI Check
- Stop the
Listenerinstance launched sooner - Ensure
jndi.propertiescontains the line:java.naming.provider.url=http://myLocalServer:8080
- Run:
$OPENJMS_HOME/bin/admin.bat
- A Swing application should start.
- Go to:
Actions > Connections > Online
- The queue
queue1should be followed by a ‘0’. - Run:
run Sender queue1 50
-
Action > Refresh
- The queue
queue1should be followed by a ’50’.
-
- Run:
run Listener queue1
-
Action > Refresh
- The queue
queue1should be followed by a ‘0’.
-
GWT in noserver mode with Tomcat or WebLogic
Abstract
You would like to work on the client side of your GWT application, without building and deploying the Jetty server. Or, in the same way, you need test some server features available in WebLogic but not in Jetty, such as the EJB.
GWT 2.0 documentation, at the segment How do I use my own server in hosted mode instead of GWT’s built-in Jetty instance? is not precise at all on the 3rd step: it simply states:
“change the URL at the end of the argument list to match the URL you recorded in step #1.”
Process
- Let’s assume your WAR is deployed on
http://distantMachine:8080/myApplication. The servlet container may be Tomcat or WebLogic, it does not matter - In Eclipse, go in “
Run Configuration...“. Duplicate your current and classic GWT application configuration. - Go in
Server, uncheck “Run built-in server“. - In
Argumentstab, write the following line:
[java]-noserver -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -war C:\eclipse\workspace\myApplication\src\main\webapp\lalou.jonathan.web.gwt.MyApplication -startupUrl http://distantMachine:8080/myApplication lalou.jonathan.web.gwt.MyApplication[/java] - Run
- The application is available at the following address:
[html]http://distantMachine:8080/muyApplication/?gwt.codesvr=127.0.0.1:9997[/html]
Petite enigme
Hier, on m’a presente l’enigme suivante:
Enonce
Il y a une salle, avec un interrupteur unique, qui allume une lampe unique. Cette lampe ne chauffe pas.
10 personnes sont dans la salle d’attente.
Une personne est appelee de maniere aleatoire. Elle peut allumer et eteindre la lampe, mais pas communiquer d’une quelconque maniere avec les autres membres du groupe. Ensuite elle retourne au groupe, et une autre personne est appellee.
Les personnes peuvent discuter avant l’epreuve pour mettre au point une strategie.
Question: comment faire pour qu’a un moment donne, une personne puisse affirmer “nous sommes deja tous passes au moins une fois”?
Solution
Soit n le nombre de personnes presentes initialement. Il est possible de restreindre initialement le probleme: en effet, il est equivalent que n=10 ou si n=4, voire meme n=3. En dessous de ce chiffre le probleme ne se pose evidemment plus.
Il y a deux facons d’aborder l’enigme. La premiere consiste a voir les 4 personnes comme des “pairs” (peers), chacun etant “egal” aux autres. Cette voie, que j’ai exploree, ne m’a pas permis de deboucher sur une solution.
La seconde facon consiste a considerer que parmi les 4, il y a 3 bonhommes “normaux“, egaux entre eux, et 1 “super“-bonhomme, avec des droits de “super user”.
Accordons donc les droits suivants:
- chaque bonhomme “normal” a le droit d’allumer une, et une seule, fois la lampe, a un moment bien choisi.
- le “super” bonhomme est le seul a avoir le droit d’eteindre la lampe.
Voici donc l’algorithme de resolution:
- Lorsqu’un bonhomme “normal” est appele:
- Si la lumiere est deja allumee, il ressort.
- Si la lumiere est eteinte et que le bonhomme courant n’a jamais allume la lampe, alors il l’allume.
- (De cette maniere, on s’assure que le bonhomme normal allume au plus une fois.)
- Le “super” user initialise un compteur a 0. Lorsque le super user est appele:
- Si la lumiere est deja allumee, il incremente son compteur, et il eteint la lumiere.
- Si la lumiere est eteinte, il ressort.
D’un point de vue mathematique, on se trouve face a un univers de probabilites discretes. D’apres la loi faible des grands nombres, au bout d’un temps suffisament long, le compteur atteint le nombre d’utilisateurs “normaux” (autrement dit: n-1, lui-meme sachant qu’il est deja passe). Il peut alors s’exclamer: “nous sommes tous deja passes au moins une fois!”.