Friday, July 22, 2016

JDeveloper 12c error javax.naming.NameNotFoundException: While trying to lookup 'jdbc.LocalSvcTblDataSource'

Today I noticed mysterious error when I run any web application in my JDeveloper 12.2.1. This is the stack trace:
[ecid: badadddc-e435-47c7-9b26-b7a8c0331704-00000048,0] [partition-name: DOMAIN] [tenant-name: GLOBAL] CCW auto-republish services error [[
com.oracle.cie.servicetable.external.ServiceTableException: javax.naming.NameNotFoundException: While trying to lookup 'jdbc.LocalSvcTblDataSource' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/LocalSvcTblDataSource'
 at com.oracle.cie.servicetable.impl.ServiceTableImpl.getOnlineLocalServiceTableConnection(ServiceTableImpl.java:99)
 at com.oracle.cie.servicetable.impl.ServiceTableImpl.getLocalConnection(ServiceTableImpl.java:223)
 at com.oracle.cie.servicetable.impl.ServiceTableImpl.query(ServiceTableImpl.java:405)
 at com.oracle.cie.servicetable.impl.ServiceTableImpl.query(ServiceTableImpl.java:379)
 at oracle.as.ccw.jmx.CCWCache.autoRePublish(CCWCache.java:320)
 at oracle.as.jmx.framework.wls.spi.WLSInternalEventsListener.processEditSessionChanges(WLSInternalEventsListener.java:376)
 at oracle.as.jmx.framework.wls.spi.WLSInternalEventsListener.handleEvent(WLSInternalEventsListener.java:198)
 at weblogic.management.eventbus.spi.InternalEventBusImpl.send(InternalEventBusImpl.java:75)
 at weblogic.management.provider.internal.RuntimeAccessDeploymentReceiverService.doCommit(RuntimeAccessDeploymentReceiverService.java:574)
 at weblogic.management.provider.internal.RuntimeAccessDeploymentReceiverService.commit(RuntimeAccessDeploymentReceiverService.java:435)
 at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195)
 at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.commit(DeploymentReceiverCallbackDeliverer.java:64)
 at weblogic.deploy.service.internal.statemachines.targetserver.AwaitingCommit.callDeploymentReceivers(AwaitingCommit.java:266)
 at weblogic.deploy.service.internal.statemachines.targetserver.AwaitingCommit.handleCommit(AwaitingCommit.java:121)
 at weblogic.deploy.service.internal.statemachines.targetserver.AwaitingCommit.receivedCommit(AwaitingCommit.java:44)
 at weblogic.deploy.service.internal.transport.CommonMessageReceiver.receiveRequestCommitMsg(CommonMessageReceiver.java:597)
 at weblogic.deploy.service.internal.transport.CommonMessageReceiver$3.run(CommonMessageReceiver.java:883)
 at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:643)
 at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
 at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
 at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
 at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
 at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:617)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:397)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
Caused by: javax.naming.NameNotFoundException: While trying to lookup 'jdbc.LocalSvcTblDataSource' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/LocalSvcTblDataSource'
 at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1224)
 at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:268)
 at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:217)
 at weblogic.jndi.internal.BasicNamingNode.lookupIgnorePartition(BasicNamingNode.java:1503)
 at weblogic.jndi.internal.PartitionHandler.lookupSharable(PartitionHandler.java:88)
 at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:584)
 at weblogic.jndi.internal.RootNamingNode.lookup(RootNamingNode.java:81)
 at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:307)
 at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:430)
 at javax.naming.InitialContext.lookup(InitialContext.java:417)
 at com.oracle.cie.servicetable.util.JdbcUtil.getOnlineLocalSvcTblConnection(JdbcUtil.java:383)
 at com.oracle.cie.servicetable.impl.ServiceTableImpl.getOnlineLocalServiceTableConnection(ServiceTableImpl.java:92)
 ... 24 more

]]

After long investigation ... Eureka ... The missing datasource isn't associated with concrete web application. This is built-in "feature":) caused by the fact that the default Derby Server supplied with JDeveloper 12c is not running.

But what is the reason the Derby is not starting?

It turned out that the cause of error is upgrade of JDK. In JDK 7U51 (and above) the default socket permissions assigned to all code including untrusted code have been changed. This was described here: http://www.oracle.com/technetwork/java/javase/7u51-relnotes-2085002.html.

But how to resolve this issue?

The simplest way is modyfying Derby start scripts. In my case I need find startNetworkServer.bat which is located in:
%WL_HOME%\common\derby\bin\startNetworkServer.bat

In this script you should modify line:
"%_JAVACMD%" %DERBY_OPTS% -classpath "%CLASSPATH%;%LOCALCLASSPATH%" org.apache.derby.drda.NetworkServerControl start %DERBY_CMD_LINE_ARGS%

replacing it by:
"%_JAVACMD%" %DERBY_OPTS% -classpath "%CLASSPATH%;%LOCALCLASSPATH%" org.apache.derby.drda.NetworkServerControl start -noSecurityManager %DERBY_CMD_LINE_ARGS%

In Linux/Unix systems you need find script startNetworkServer, and modified line should looks like:
derby_exec_command="exec \"$JAVACMD\" $DERBY_OPTS -classpath \"$LOCALCLASSPATH\" org.apache.derby.drda.NetworkServerControl start -noSecurityManager $@"

  • There is also the better solution. You can edit the "java.policy" file: 
  • Locate the directory of your JDK. 
  • Navigate to the directory: /jre/lib/security 
  • Open the file "java.policy" in an editor 
  • Add following line to the already present grants: 
    • permission java.net.SocketPermission "localhost:1527", "listen"; 
  • Save the file. 
  • Restart the integrated WebLogic server.
Ok. And here's the puzzle: Why I prefer worse (first) solution ... ?