JMX Integration with Apache CXF - java

I need CXF server monitoring with JMX and followed CXF Documentation. I use tomcat and following is the content of my cxf.xml file located at /home/kalpa/applications/apache-tomcat-7.0.54/webapps/java_first_jaxws/WEB-INF/classes
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
<property name="bus" ref="cxf" />
<property name="enabled" value="true" />
<property name="JMXServiceURL " value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" />
</bean>
</beans>
But I cannot monitor the data with jconsole. There is no local entry for the connection.
What could be the issue here?

I don't know if your question is still an ongoing problem but this is my configuration :
<cxf:bus bus="cxf">
<cxf:properties>
<entry key="bus.jmx.enabled" value="true"/>
<entry key="bus.jmx.JMXServiceURL" value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi"/>
</cxf:properties>
</cxf:bus>
Instead of yours :
<bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
<property name="bus" ref="cxf" />
<property name="enabled" value="true" />
<property name="JMXServiceURL " value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" />
</bean>
I'm working with CXF 3.0.2, and a jconsole in JRE 1.6.0_27 ...
This is working fine :
jconsole connection string

Related

Java - Quartz Job working on Debug Tomcat, but not on separate Tomcat

I configured a Quartz job, which fires in the eclipse's Debug Tomcat that comes with Spring. But if I deploy my application to my separate Tomcat installation, the job doesn't fire.
Here's my quartz-config.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="de.java.scheduling" />
<bean name="issueSyncJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="de.java.scheduling.IssueSyncJob" />
<property name="durability" value="true" />
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="issueSyncJobDetail" />
<property name="cronExpression" value="0/10 * * ? * MON-FRI" />
</bean>
<!-- Scheduler factory bean to glue together jobDetails and triggers to Configure Quartz Scheduler -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="issueSyncJobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
Any idea what might be the cause for the job not triggering once deployed on my Tomcat?

Spring integration - less boilerplate?

I have started using Spring-integration for listening on JMS-queues, and it's working satisfactory, but I have somewhat of an issue with the amount of xml-configuration required in order to set up a listener. Most of this is boilerplate, what changes is really just the jms-instance and the name of the queue to listen to, and the class and method to invoke upon receiving a message. Here is an example:
<?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:int="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<bean id="jms.queue.myQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="${myApplication.jms.queue.myQueue}" />
</bean>
<bean id="jms.container.myJMSListender"
class="org.springframework.jms.listener.DefaultMessageListenerContainer"
destroy-method="destroy">
<property name="connectionFactory"
ref="jmsConnectionFactory" /> <!-- Defined elsewhere -->
<property name="destination"
ref="jms.queue.myQueue" />
<property name="sessionTransacted"
value="true" />
</bean>
<int:publish-subscribe-channel id="channel.myQueue" />
<jms:message-driven-channel-adapter id="channelAdapter.myQueue"
container="jms.container.myQueue"
channel="channel.myQueue"
acknowledge="transacted"/>
<int:service-activator id="serviceActivator.myQueue"
input-channel="channgel.myQueue"
ref="myQueueJMSListener"
method="handleMessage" />
</beans>
As you can see, a lot of config for something fairly simple, and with quite a lot of JMS-listeners this becomes tedious, both to read and write.
Is there a way to configure listening to a queue with Spring-integration that requires less boilerplate? I've looked into creating my own XML-tag, but I'm kinda hoping that there is a simpler solution.
You only need an external container if you need to configure properties that are not exposed on the namespace.
<jms:message-driven-channel-adapter id="channelAdapter.myQueue"
destination="jms.queue.myQueue"
connection-factory="jmsConnectionFactory"
channel="channel.myQueue"
acknowledge="transacted"/>
Found that Spring integration has annotation support.
Requires some setup, but this can be used for multiple listeners:
<amq:connectionFactory id="jmsConnectionFactory" brokerURL="${jms.host}">
<amq:redeliveryPolicy>
<amq:redeliveryPolicy maximumRedeliveries="0" />
</amq:redeliveryPolicy>
</amq:connectionFactory>
<bean id="cachingJmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
</bean>
<jms:annotation-driven />
<bean id="jmsListenerContainerFactory" class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
<property name="connectionFactory" ref="cachingJmsConnectionFactory" />
</bean>
Then, listening to a certain queue is as simple as:
#JmsListener(destination = "${myQueueName}")
public void listen(#Payload final String payload) {

NameNotFound on remote jmx call with rmi

I'm trying to remotely call jmx bean exposed by spring using this guide
but when I launch my client code, it fails to load application context with such error
Caused by: java.io.IOException: Failed to retrieve RMIServer stub:
javax.naming.NameNotFoundException: jmxrmi at
javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:357)
at
javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267)
at
org.springframework.jmx.support.MBeanServerConnectionFactoryBean.connect(MBeanServerConnectionFactoryBean.java:126)
at
org.springframework.jmx.support.MBeanServerConnectionFactoryBean.afterPropertiesSet(MBeanServerConnectionFactoryBean.java:114)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 38 more Caused by: javax.naming.NameNotFoundException: jmxrmi
Here is my server spring context
<?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:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=testBean" value-ref="testBean" />
</map>
</property>
<property name="assembler">
<bean
class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="managedInterfaces">
<value>jmx.IJmxTestBean</value>
</property>
</bean>
</property>
<property name="server" ref="mbeanServer" />
</bean>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="1199" />
</bean>
<bean id="testBean" class="jmx.JmxTestBean">
<property name="name" value="TEST" />
<property name="age" value="100" />
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="registry">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1199/jmxrmi" />
</bean>
and this is my client spring context
<?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:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="clientConnector"
class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1199/jmxrmi" />
</bean>
<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="objectName" value="bean:name=testBean" />
<property name="proxyInterface" value="jmx.IJmxTestBean" />
<property name="server" ref="clientConnector" />
</bean>
Any ideas?
Ok, this is not the issue with spring jmx, but with the jboss eap that I'm deploying the apps. This code runs perfectly fine when I launch the spring contexts as standalone clients or on jetty. Since I run this on JBoss EAP 6.2 then jmx by rmi is not supported I need to find another way.

JBoss 7 Override JNDI Datasource

I have a Spring Web Application with Maven 3 and Datasources/Beans configured for local development on a h2 Database. For Testing there exists a JBoss AS 7.1 Server.
Is it possible to override a Bean / DataSource in a special JBoss XML-File, so that for local (IDE) matters a DriverManagerDataSource is used (see first code posting), and a JndiObjectFactoryBean (second one), if my Application is deployed on a JBoss?
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
<!-- And so on -->">
<!--GENERAL-->
<context:annotation-config/>
<context:component-scan base-package="com.mysuperapp"/>
<!--DATASOURCES-->
<bean id="activitiDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:file:h2\activiti;MVCC=TRUE"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="hibernateDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:file:h2\hibernate;AUTO_SERVER=TRUE"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<!--TXMANAGEMENT-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="mysuperappPersistenceUnit"/>
<property name="dataSource" ref="hibernateDataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="packagesToScan" value="com.mysuperapp.model"/>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<entry key="hibernate.hbm2ddl.auto" value="update"/>
</map>
</property>
</bean>
<!-- And so on -->
custom applicationContext.xml datasources for JBoss
<bean id="activitiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/activitiDataSource"/>
</bean>
<bean id="hibernateDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/hibernateDataSource"/>
</bean>
Any help is greatly appreciated.
Your application creates the database connection on its own as i can see on your config.
Instead of doing this you could just define the datasource on the app-server and obtain it by a jndi lookup. So you can configure the database connection for each system separately.
<!-- DataSource-LookUp -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton">
<property name="jndiName" value="java:jboss/datasources/MyDataSourceDS" />
<property name="resourceRef" value="true" />
</bean>
Your JBoss has a file <jboss_home>/standalone/configuration/standalone.xml which is used if you don't provide a different one.
For testing purposes you could try and make a copy of that file in the same directory, e.g. naming it test.xml and add your datasource definition there. Then use it by starting JBoss with standalone.bat --server-config=test or standalone.bat -c test.
I managed to do this with a SVN patch, which is added prior to the automatic deployment. It changes the DataSource definitions.
Pay attention when creating the patch with windows and applying under linux with /usr/bin/patch (CR+LF problem, apply dos2unix filename to both patch and files to be patched).

Get BeanCreationException when try to add Jackson Library

I have a simple Hello World example that passes a Map to Camel and displays the values to the console via Log4J. I want to expand this example to render this map in JSON by adding the Jackson library to my Camel applicationContext.xml
First I tried adding the following XML tags to my applicationContext.xml (as specified at
http://camel.apache.org/json.html under "Using JSON in Spring DSL")
<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>
But when I add this to my applicationContext.xml, and run my Java code I get the following XmlBeanDefinitionStoreException message:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'dataFormats'. One of '{"http://camel.apache.org/schema/
spring":route}' is expected.
Moving these tags inside or outside of my camelContext yields the same error (just a longer list of URLs when inside the camelContext).
Is there something else I need to specify in my ApplicationContext.xml?
Here is my current applicationContext.xml:
UPDATED: The following xml now works. Had to move the location of the dataFormats XML tags.
<?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:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<context:component-scan base-package="sample" />
<context:annotation-config />
<camel:camelContext id="HelloWorldContext">
<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>
<camel:route>
<camel:from
uri="timer://hello.world.request.timer?fixedRate=true&period=10000" />
<camel:to uri="log:hello.world.request?level=INFO?showAll=true" />
<camel:bean ref="helloWorld" />
<camel:to uri="log:hello.world.response?level=INFO?showAll=true" />
</camel:route>
</camel:camelContext>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="transacted" value="false" />
<property name="concurrentConsumers" value="1" />
</bean>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost" />
<property name="redeliveryPolicy" ref="redeliveryPolicy" />
<property name="prefetchPolicy" ref="prefetchPolicy" />
</bean>
<bean id="prefetchPolicy" class="org.apache.activemq.ActiveMQPrefetchPolicy">
<property name="queuePrefetch" value="5" />
</bean>
<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="1" />
<property name="backOffMultiplier" value="2" />
<property name="initialRedeliveryDelay" value="2000" />
<property name="useExponentialBackOff" value="true" />
</bean>
</beans>
The dateFormats and json elements are part of the camel namespace. You need to specify that
<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>

Categories