I am using jdk1.6. I have loaded a jar at runtime successfully. Codes are as follow:
vm = VirtualMachine.attach(vid);
vm.loadAgent(agentPath);
Now I wannt to unload this agent at runtime. There is no API DOC to do that. Can anyone give me some advices? Thanks.
EDIT
More Codes
GlobalVariables.vm = VirtualMachine.attach(vid);
// Check to see if transformer agent is installed
if(!GlobalVariables.vm.getSystemProperties().contains("demo.agent.installed")) {
System.out.println("Load agent");
GlobalVariables.vm.loadAgent(agentPath);
}
GlobalVariables.connectorAddress = GlobalVariables.vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress", null);
if(null == GlobalVariables.connectorAddress) {
// It's not, so install the management agent
String javaHome = GlobalVariables.vm.getSystemProperties().getProperty("java.home");
File managementAgentJarFile = new File(javaHome + File.separator + "lib" + File.separator + "management-agent.jar");
GlobalVariables.vm.loadAgent(managementAgentJarFile.getAbsolutePath());
System.out.println("Load Management agent");
GlobalVariables.connectorAddress = GlobalVariables.vm.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress", null);
// Now it's installed
}
// Now connect and transform the classnames provided in the remaining args.
//JMXConnector connector = null;
try {
// This is the ObjectName of the MBean registered when loaded.jar was installed.
//ObjectName on = new ObjectName("transformer:service=DemoTransformer");
GlobalVariables.on = new ObjectName("transformer:service=DemoTransformer");
// Here we're connecting to the target JVM through the management agent
GlobalVariables.connector = JMXConnectorFactory.connect(new JMXServiceURL(GlobalVariables.connectorAddress));
GlobalVariables.server = GlobalVariables.connector.getMBeanServerConnection();
System.out.println("MBean Server connection...");
// Call transformClass on the transformer MBean
GlobalVariables.server.invoke(GlobalVariables.on, "transformClass", new Object[]{className, args}, new String[]{String.class.getName(), String.class.getName()});
} catch (Exception ex) {
ex.printStackTrace(System.err);
} finally {
if(GlobalVariables.connector!=null) try { GlobalVariables.connector.close(); } catch (Exception e) {}
GlobalVariables.vm.detach();
System.out.println("Has disconnected");
}
What did I do then
I run the above code again to load those two agents again. But I got errors.
Errors
error in current vm
com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:103)
at com.sun.tools.attach.VirtualMachine.loadAgent(VirtualMachine.java:508)
at faultinjectionaction.AttachClass.attachAgent(AttachClass.java:111)
at org.apache.jsp.fjstep3_jsp._jspService(fjstep3_jsp.java:350)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
error in target vm
Exception in thread "Attach Listener" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:348)
Caused by: javax.management.InstanceAlreadyExistsException: transformer:service= DemoTransformer
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:482)
at faultinjectionagent.AgentMain.agentmain(AgentMain.java:28)
... 6 more
Aim
To do the same job with no errors. I think I need to unload the agents when I finished my job every time. But I failed to unload those agents.
EDIT GlobleVariables
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import com.sun.tools.attach.VirtualMachine;
public class GlobalVariables{
public static MBeanServerConnection server;
public static ObjectName on;
public static JMXConnector connector = null;
public static String connectorAddress = null;
public static VirtualMachine vm;
}
What do you mean by unload the agent? You cannot unload the classes as it implicitly says in the documentation:
the specified JAR file is added to the system class path (of the
target virtual machine)
The only way arround this might be some custom class loader magic, but I would not recommend that.
Update: After looking at your extended question, I think your problem is actually something else. At some point you are invoking
JMXConnectorFactory.connect(new JMXServiceURL(GlobalVariables.connectorAddress))
in order to create a JMXConnector. I guess that within your GlobalVariables.server.invoke call, you are registering a MBean by new ObjectName("transformer:service=DemoTransformer"). This name must be unique and when you are running the code a second time, this name is already taken as suggested by javax.management.InstanceAlreadyExistsException: transformer:service= DemoTransformer. What you needed to do is:
Either choose another name when registering the MBean a second time.
Call MBeanServerConnection.close(new ObjectName("transformer:service=DemoTransformer")) before detaching from the remote JVM in order to make the name available again.
You might have assumed that by detaching, all state on the remote machine was reset. This is however not true. You added an MBean with a name and than you tried to do this again. This error can be understood as if you added a two values with the same key to a map. Other than with the map, you will however not override values but cause the exception you observe above.
By the way: You should call JMXConnector.close explicitly when the connection to the remote server is not longer required.
PS: You might find this article interesting.
Update 2: After discussion in the chat and after getting the MBean naming conflict out of the way, I think this is what caused the problem:
When a Java Agent is loaded a second time, the classes that come with the agent (represented in managementAgentJarFile) are already loaded in the target JVM. This means, that no class initializers will be run again and state changes that are represented by static variables will still be represented. Additionally, it is not possible to load classes with the same name but changed implementation. This will cause LinkageErrors and the agent loading will fail. The solution is to avoid static state such that an agent cannot inflict with itself and to create separate name spaces for different agents. Otherwise, agent classes can be unloaded by using custom class loaders. More information on this matter can be found on many places and here:
Can I pre-empt the class path?
http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html
Related
I am trying to get a simple Arango app started with Spring Data. My Arango db is running in Docker on localhost and default port.
The project is built as a Spring Boot Groovy-enabled project using Intellij.
I've pushed the demo app to github here and it's about as simple as can get.
I did this trying to follow the online documentation, but structurally I put the model class in the model folder and the repository interface into a repository folder.
When I try and run this I get this error. But so far as I can see I had done what was expected extending from AbstractRepository<Organisation.class>. it says ambiguous dependency for parameter of type ArangoOperations, but I don't do this directly in the repository.
What have I done wrong?
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'organisationRepository': Unsatisfied dependency expressed through constructor parameter 1: Ambiguous argument values for parameter of type [com.arangodb.springframework.core.ArangoOperations] - did you specify the correct bean references as arguments?
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:756) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:991) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:865) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:574) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:518) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:481) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:602) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:594) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1226) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:865) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:853) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:840) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:791) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication$run.call(Unknown Source) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) [groovy-2.5.7.jar:2.5.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) [groovy-2.5.7.jar:2.5.7]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135) [groovy-2.5.7.jar:2.5.7]
at com.softwood.arango.ArangoApplication.main(ArangoApplication.groovy:14) [main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.7.RELEASE.jar:2.1.7.RELEASE]
so in the end noted that the example i was copying didnt reflect latest versions of libraries etc, so i took the latest docker image 3.4, and updated the gradle app build to latest libraries in the dependencies
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.codehaus.groovy:groovy'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile 'com.arangodb:arangodb-spring-data:3.1.0'
compile 'com.arangodb:arangodb-java-driver:5.0.7'
}
and retried. things started to look better, however they have changed the spring data repository interface defn now where you need two types - the entity class and the type id of the #id field - else the code wont compile
public interface OrganisationRepository extends ArangoRepository<Organisation, String> {}
this allowed the save operation to work -
however the findOne operation takes an Example.of and returns an optional. so in latest code you essentially have to test for completed result before you do a Optional.get() to get the value
so my simple CrudRunner run operation now looks like this, which compiles and runs and returns the previous saved object
#Override
public void run(final String... args) throws Exception {
// first drop the database so that we can run this multiple times with the same dataset
operations.dropDatabase()
// save a single entity in the database
// there is no need of creating the collection first. This happen automatically
final Organisation vf = new Organisation(name:"Vodafone", inaugurated: 2000, webAddress:"vodafone.com")
repository.save(vf)
CollectionOperations coll= operations.collection(Organisation)
CollectionPropertiesEntity props = coll.getProperties()
println props.name
// the generated id from the database is set in the original entity
println(String.format("vf organisation saved in the database with id: '%s'", vf.id))
// create an example from saved object and use to query the db - findOne returns Optional<T>
Optional<Organisation> res = repository.findOne(Example.of(vf))
assert res.isPresent()
final Organisation foundOrg = res.get()
repository.findOne()
println(String.format("Found %s", foundOrg.name))
}
so now we have a basic working version of spring data with arango. enough to get you over the initial 'humps' in the road i can explore a bit further
hope this might help any one else who wants to get started and gets frustrated when your PoC fails to work.
note. in the browser client on the docker server you need to select the database that you create (here 'arango-demo' db) as be default your logged into _system db and not your app db. once you select the right db, you can see the autocreated collection and your record in that collection.
My tomcat based REST API application is not able to process request due to above mentioned error. I have tried following things so far :
checking if all the jar files are available or not
Checking permissions on all files present in tomcat/webapp/ directory
firewall rules
Hbase is availabe or not
but then also getting following exception. I am using CDH 5.3.1 which contains HBase 0.98.6. Does anyone know how to resolve this issue?
2015-03-03 05:09:02 privateLog [ERROR] java.lang.reflect.InvocationTargetException org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:413)
org.apache.hadoop.hbase.client.HConnectionManager.createConnection(HConnectionManager.java:306)
com.amazon.dao.MyDAO.<clinit>(SensorDataDAO.java:78)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
java.util.concurrent.FutureTask.run(FutureTask.java:166)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)
com.amazon.dao.MyDAO <clinit>
Code which tries to establish connection is as follows:
public class MyDAO {
protected static HConnection connection;
static {
Configuration conf = HBaseConfiguration.create();
conf.addResource("hbase-site.xml");
connection = HConnectionManager.createConnection(conf);
// connection object is still null at this point
try {
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Can you try setting this into your conf?
config.set("hbase.zookeeper.quorum", "zookeeper-ip:port");
If this works then we can check if the hbase-site.xml you are setting into conf has the correct details or not.
I solved my problem. I found 2 reasons for this error. In case someone faces same error then this answer might help them :)
Some jar files were missing from class path hence InvocationTargetException came. Since we are using Ant based build system and not Maven based, some jar files were missing. Basically we need to put almost all jar files present in /etc/hadoop, /etc/hadoop-hdfs, /etc/hbase and /etc/zookeeper directories.
Please take a note that we are using Cloudera Hadoop distribution, if
you are using some different distribution then these paths may vary.
Second major problem was that we did not included hdfs-site.xml file while creating configuration object. Since we are using name node HA feature, this file is a must. IF this file is not present then hbase cannot connect to proper name node service.
Now connection related code looks like this :
public class MyDAO {
protected static HConnection connection;
static {
Configuration conf = HBaseConfiguration.create();
conf.addResource("hbase-site.xml");
conf.addResource("hdfs-site.xml");
conf.addResource("core-site.xml");
connection = HConnectionManager.createConnection(conf);
try {
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I created a java application and initialize a java.util.Logger with that application and run that application as -javaagent with jboss AS 7 server and i got IllegalStateException (i am using eclipse IDE).Here follows my logger initialization code
static public void setup() throws IOException {
// Get the global logger to configure it
Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
logger.setLevel(Level.INFO);
fileTxt = new FileHandler("C:/Users/abc/Desktop/ATAGENT/Logging.txt");
fileHTML = new FileHandler("C:/Users/abc/Desktop/ATAGENT/Logging.html");
// create txt Formatter
formatterTxt = new SimpleFormatter();
fileTxt.setFormatter(formatterTxt);
logger.addHandler(fileTxt);
// create HTML Formatter
formatterHTML = new BMITHtmlFormatter();
fileHTML.setFormatter(formatterHTML);
logger.addHandler(fileHTML);
}
When i create -javaagent jar appended with above lines of code and run with jboss as7 server i got following exception
WARNING: Failed to load the specified log manager class org.jboss.logmanager.LogManager
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.jboss.as.server.Main.main(Main.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.modules.Module.run(Module.java:260)
at org.jboss.modules.Main.main(Main.java:291)
Caused by: java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
at org.jboss.logmanager.Logger.getLogger(Logger.java:60)
at org.jboss.logmanager.log4j.BridgeRepositorySelector.(BridgeRepositorySelector.java:42)
... 7 more
And i serched in fourms and i got a solution which is Open the launch configuration for the server definition.
and add -logmodule org.jboss.logmanager to the program arguments before org.jboss.as.standalone.
But it results the same exception with some additional warning. Here follows the exception
WARNING: -logmodule is deprecated. Please use the system property 'java.util.logging.manager' or the 'java.util.logging.LogManager' service loader.
WARNING: Failed to load the specified log manager class org.jboss.logmanager.LogManager
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.jboss.as.server.Main.main(Main.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.modules.Module.run(Module.java:260)
at org.jboss.modules.Main.main(Main.java:291)
Caused by: java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
at org.jboss.logmanager.Logger.getLogger(Logger.java:60)
at org.jboss.logmanager.log4j.BridgeRepositorySelector.(BridgeRepositorySelector.java:42)
... 7 more
I had the same problem with JBOSS EAP 6, it took me 2 days for find a solution !.
The cause is that your agent need to create a Logger at statup, he need to be able to access the logmanager classes before JBOSS Modules has been initialized. You need to add JBoss LogManager to the boot classloader. Then, there will be a conflict between LogManager available via ModuleClassLoader and classes loaded via system classloader.
The solution is to make Java Agent and JBoss Modules use the same classloader to load the LogManager classes.
For EAP 6, In your standalone.conf (or domain) (It must be close for your version)
add
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:$JBOSS_HOME/modules/org/jboss/logmanager/main/jboss-logmanager-1.3.1.jar"
and for make Java Agent and JBoss Modules use the same classloader
modify this piece of code in adding org.jboss.logmanager like this :
if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then
JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.jboss.logmanager"
fi
Hope this will help.
I found the solution after searching for couple of days in the below link.
https://github.com/jbossas/jboss-as-maven-plugin/issues/40#issuecomment-14943429
I have to tweak a little bit to get is work in Windows 7.
Open Eclipse.
Add Jboss 7.1 Runtime 1 server.
Select the Server and press F3.
Click on Open Launch Config.
Goto VM arguments.
Add the below two entries.
"-Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager"
"-Djava.util.logging.manager=org.jboss.logmanager.LogManager"
Now select the Classpath TAB
Select User Entries
Click Add External Jars
Select the three jar files
a) jboss-logmanager-1.2.0.GA.jar
b) jboss-logmanager-log4j-1.0.0.GA.jar
c) log4j-1.2.16.jar
Paths
C:/jboss-as-7.1.1.Final/modules/org/jboss/logmanager/main/jboss-logmanager-1.2.0.GA.jar"
C:/jboss-as-7.1.1.Final/modules/org/jboss/logmanager/log4j/main/jboss-logmanager-log4j-1.0.0.GA.jar"
C:/jboss-as-7.1.1.Final/modules/org/apache/log4j/main/log4j-1.2.16.jar"
This will start the standalone jboss without any issues.
In EAP 6.4, the correct logmanager's path should be
$JBOSS_HOME/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-1.5.4.Final-redhat-1.jar
I have an application deployed on Glassfish v3.0.1 which reads events from a table in my database. Once ready it marks them as processed. I am getting a strange error I can't explain when trying to call the method which does the update.
#Override
#TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void markEventAsProcessed(Long eventId) {
try {
AtlasEventQueueUpdateAsProcessedQuery setEventAsProcessed = new AtlasEventQueueUpdateAsProcessedQuery(entityManager, eventId);
int updateCount = setEventAsProcessed.execute();
logger.debug("Mark Event [" + eventId + "] processed");
return updateCount;
} catch (QueryException ex) {
logger.error("Event [" + eventId + "has not been marked as processed", ex);
}
}
When this is called in my application I am getting the following exception (Full trace at the bottom of the post):
Caused by: javax.ejb.AccessLocalException: Client not authorized for this invocation.
Does anyone know what might cause this error I have loked on the Web but didn't find anything useful.
2010-08-27 09:44:37,380 ERROR [Ejb-Timer-Thread-1 :EventProvider ] Unhandled exception in event processing - javax.ejb.EJBAccessException
javax.ejb.EJBAccessException
at com.sun.ejb.containers.BaseContainer.mapLocal3xException(BaseContainer.java:2262)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2053)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
at $Proxy190.markEventAsProcessed(Unknown Source)
at com.company.atlas.eventprocessor.provider.EventProvider.processNewEvents(EventProvider.java:170)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5292)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:157)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundTimeout(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5264)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3965)
at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1667)
at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:98)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2485)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.ejb.AccessLocalException: Client not authorized for this invocation.
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1850)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:188)
... 34 more
I've deleted the directory domains/domainx/generated/policy/<appname>/
and completly redeployed (not just restarted) the app.. its working now as expected.
The GlassFish documentation has an entry for this error:
javax.ejb.AccessLocalException: Client Not Authorized Error
Description
Role-mapping information is available
in Sun-specific XML (for example,
sun-ejb-jar.xml), and authentication
is okay, but the following error
message is displayed:
[...INFO|sun-appserver-pe8.0|javax.enterprise.system.container.ejb|...|
javax.ejb.AccessLocalException: Client not authorized for this invocation.
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:...
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(...)
Solution
Check whether the EJB module (.jar)
or web module (.war) is packaged in
an application (.ear) and does not
have role-mapping information in
application level, Sun-specific,
sun-application.xml. For any
application (.ear), security
role-mapping information must be
specified in sun-application.xml. It
is acceptable to have both
module-level XML and application-level
XML.
I don't know if it makes sense in your context.
If it doesn't, maybe have a look at the following thread Persisting Entity: javax.ejb.AccessLocalException: Client not authorized for this invocation. One of the poster suggested to set the logging level of the SECURITY Logger to FINE [so that] the Glassfish Policy subsystem will log a detailed message describing the nature of the failed permission check. This might help. And I can't tell you if you're facing the same problem but the OP solved his issue by cleaning the generated policy files:
This exception can also occur, if you try to copy and paste EJB session beans with new methods, as patch files for fixing bugs or incorporating new features. Restarting the server or disabling & enabling the enterprise app will not help, as the EJB Session beans or entities have to be repackaged and redeployed, so that the App server registers the new methods and checks and grants/excludes the access privileges to the new/altered methods in EJB session beans.
I had the same problem here when injecting a Stateless SessionBean (TransactionAttribute.REQUIRES_NEW) into an other Stateless SessionBean. For me restarting the server solved it for me...
Just wanted to let you know ;-)
I had the same issue. I'm not using any kind of access control on the service but on one instance of glassfish everything worked fine, on another, I got this error but only on some methods. I added #PermitAll and redeployed the service and everything started working.
On Glassfish 3.1.2 at least, sometimes a previous iteration of a bean that has changed will choke Glassfish at deployment. The app will run until it gets to whatever bit of code that should be called but can't be because the previously deployed class is still there. I think Glassfish might keep track of each and prevent the new code from calling the old code, but I haven't really been that keen to worry about it as the solution is simple enough:
Stop the server, go to the domain directory and delete all the files and sub-directories in the application directory. Then do the same in the generated and osgi-cache directories. Restart the server and rebuild/redeploy.
I had this same Error but mine was caused from this:
<c:set var="speciesList" value="#{timberSaleController.distinctSaleSpecies}" />
the function:
public List<Species> getDistinctSaleSpecies()
{
return ejbFacade.getDistinctSpeciesForAllSales();
}
when i changed the set tag to this it worked:
<c:set var="speciesList" value="#{timberSaleController.getDistinctSaleSpecies()}" />
First of all, I'd like to underline that I've already read other posts in StackOverflow (example) with similar questions, but unfortunately I didn't manage to solve this problem with the answers I saw on those posts. I have no intention to repost a question that has already been answered, so if that's the case, I apologize and I'd be thankful to whom points out where the solution is posted.
Here is my question:
I'm trying to deploy an EJB in WebLogic 10.3.2. The purpose is to use a specific WorkManager to execute work produced in the scope of this component.
With this in mind, I've set up a WorkManager (named ResponseTimeReqClass-0) on my WebLogic configuration, using the web-based interface (Environment > Work Managers > New). Here is a screenshot:
Here is my session bean definition and descriptors:
OrquestratorRemote.java
package orquestrator;
import javax.ejb.Remote;
#Remote
public interface OrquestratorRemote {
public void initOrquestrator();
}
OrquestratorBean.java
package orquestrator;
import javax.ejb.Stateless;
import com.siemens.ecustoms.orchestration.eCustomsOrchestrator;
#Stateless(name = "OrquestratorBean", mappedName = "OrquestratorBean")
public class OrquestratorBean implements OrquestratorRemote {
public void initOrquestrator(){
eCustomsOrchestrator orquestrator = new eCustomsOrchestrator();
orquestrator.run();
}
}
META-INF\ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?>
<ejb-jar xmlns='http://java.sun.com/xml/ns/javaee'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
metadata-complete='true'>
<enterprise-beans>
<session>
<ejb-name>OrquestradorEJB</ejb-name>
<mapped-name>OrquestratorBean</mapped-name>
<business-remote>orquestrator.OrquestratorRemote</business-remote>
<ejb-class>orquestrator.OrquestratorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor></assembly-descriptor>
</ejb-jar>
META-INF\weblogic-ejb-jar.xml
(I've placed work manager configuration in this file, as I've seen on a tutorial on the internet)
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<ejb-name>OrquestratorBean</ejb-name>
<jndi-name>OrquestratorBean</jndi-name>
<dispatch-policy>ResponseTimeReqClass-0</dispatch-policy>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
I've compiled this into a JAR and deployed it on WebLogic, as a library shared by administrative server and all cluster nodes on my solution (it's in "Active" state).
As I've seen in several tutorials and examples, I'm using this code on my application, in order to call the bean:
InitialContext ic = null;
try {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(env);
}
catch(Exception e) {
System.out.println("\n\t Didn't get InitialContext: "+e);
}
//
try {
Object obj = ic.lookup("OrquestratorBean");
OrquestratorRemote remote =(OrquestratorRemote)obj;
System.out.println("\n\n\t++ Remote => "+ remote.getClass());
System.out.println("\n\n\t++ initOrquestrator()");
remote.initOrquestrator();
}
catch(Exception e) {
System.out.println("\n\n\t WorkManager Exception => "+ e);
e.printStackTrace();
}
Unfortunately, this don't work. It throws an exception on runtime, as follows:
WorkManager Exception =>
javax.naming.NameNotFoundException:
Unable to resolve 'OrquestratorBean'.
Resolved '' [Root exception is
javax.naming.NameNotFoundException:
Unable to resolve 'OrquestratorBean'.
Resolved '']; remaining name
'OrquestratorBean'
After seeing this, I've even tried changing this line
Object obj = ic.lookup("OrquestratorBean");
to this:
Object obj = ic.lookup("OrquestratorBean#orquestrator.OrquestratorBean");
but the result was the same runtime exception.
Can anyone please help me detecting what am I doing wrong here? I'm having a bad time debugging this, as I don't know how to check out what may be causing this issue...
Thanks in advance for your patience and help.
Your EJB gets bound under the following JNDI name (when deployed as EJB module):
Object obj = ic.lookup("OrquestratorBean#orquestrator.OrquestratorRemote");
Note that I deployed your code (without the weblogic-ejb-jar.xml) as an EJB module, not as a shared library.
seems like your mapped-name in ejb-jar.xml "Orquestrator" may be overriding the mappedName=OrquestratorBean setting of the Bean.
Have you tried ic.lookup for "Orquestrator" ?