How to expose activemq JMX MBeans via jboss web based jmx-console? - jboss

I have been trying to configure activemq such that the broker MBeans are available in jboss's web based jmx-console available at http://localhost:8080/jmx-console.
I have tried
<?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"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util" xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq- core.xsd">
<beans>
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
useShutdownHook="false">
<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
<!-- <managementContext createConnector="false" /> -->
<managementContext>
<MBeanServer>
<bean class="org.jboss.mx.util.MBeanServerLocator"
factory-method="locateJBoss" xmlns="" />
</MBeanServer>
</managementContext>
</managementContext>
</broker>
</beans>
When I deploy the war the piece of xml gives error
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'bean'.
Any idea how to make activemq MBeans integrate with jboss web based jmx-console?
Default settings with just createConnector=false won't work for me because jboss is configured to not use 1099 RMI port. LocateJboss factory-method call on org.jboss.mx.util.MBeanServerLocator is the only way (I know of) to get jboss MBeanServer handle.

According to the spring JMX doc, you could try something like this :
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="server">
<bean id="mBeanServerLocator" class="org.jboss.mx.util.MBeanServerLocator"
factory-method="locateJBoss" />
</property>
</bean>
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
useShutdownHook="false">
<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
<managementContext MBeanServer="exporter"/>
<!-- I am not sure what MBeanServer attribute is waiting for (a ref, an id, something else ...)-->
</managementContext>
</broker>

Related

Exception communicating with endpoint

I am implementing an application which would be exposed using RESTful web service. This application would firstly consume a RESTful web service to get the JSON file and would return this JSON file to the requestor (application which would consume my service). I am facing issues consuming the web service.
ERROR:
org.apache.camel.component.restlet.RestletOperationException: Restlet operation failed invoking https:// <--url-->
with statusCode: 1001 /n responseBody:HTTPS/1.1 - Communication Error (1001) -
The connector failed to complete the communication with the server
at org.apache.camel.component.restlet.RestletProducer.populateRestletProducerException(RestletProducer.java:233)
CODE:
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camelcontext" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration component="restlet" port="9091"/>
<rest path="/say">
<get uri="/hello" consumes="application/json" produces="application/json">
<to uri="direct:hello" />
</get>
</rest>
<route>
<from uri="direct:hello"/>
<to uri="restlet:https:// <--URL--> ?restletMethod=POST" />
</route>
</camelContext>
</beans>
Maby incoming request has additional headers, for example as in this issue Apache camel jetty RestletOperationException on invoking request 1001 when mocked restlet endpoint ("org.restlet.http.headers"). You can check and remove unnecessary headers from the request. Also, error may occur while the response by the same reason, check our service for set headers.

JPA connects to a different database instead of the one specified in my persistence.xml

Here's my persistence xml file
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="GoodreadsJpa">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entity.Book</class>
<class>entity.Review</class>
<class>entity.UserActionLog</class>
<class>entity.User</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/goodreads_clone?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC;" />
<property name="eclipselink.jdbc" value="jdbc:mysql://localhost:3306/goodreads_clone?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC;"/>
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
</properties>
</persistence-unit>
As you can see I have provided jdbc url for connecting to the database. However, when I run my application I get the following information.
14:31:57,377 INFO [org.eclipse.persistence.connection] (default task-2) Connected: jdbc:h2:mem:test
User: ROOT
Database: H2 Version: 1.3.173 (2013-07-28)
Driver: H2 JDBC Driver Version: 1.3.173 (2013-07-28)
which states that I connected to jdbc:h2:mem:test and consequently I cannot perform the desired actions.
It makes me think I am connected to a wrong database?Am I missing something? How can I actually connect to the db that I want?
I am using Wildfly 10 and EclipseLink. Not using Maven.
Assuming you're using container-managed em, you should define your data source in Wildfly configuration (standalone.xml). You should then refer to your datasource using the persistence-unit.jta-data-source (or persistence-unit.non-jta-data-source) tag in your persistence unit definition.
If you need both the MySQL and H2 data sources, you can create multiple persistence units and differentiate between them using #PersistenceContext(name = "...")
1.You need to add mysql driver to Jboss like here : Can't add mysql driver to jboss
or here
https://synaptiklabs.com/posts/adding-the-mysql-jdbc-driver-into-wildfly/
You need add mysql datasource in standalone.xml configuration file like here :
https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7/
<datasource jndi-name="java:/mydb" pool-name="my_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements />
</statement>
</datasource>

Camel + JBoss + JPA: TransactionRequiredException: Unable to register for JTA transaction despite JTA data source

I have an application based on Apache Camel that runs on JBoss AS 7.1 application server.
In one Camel route, I let Camel read XML files, unmarshal them to JPA entity objects using JAXB, and write them to a database using the Camel jpa:// component.
However, whenever an entity is sent to a JPA endpoint, Camel gives me the following TransactionRequiredException:
javax.persistence.TransactionRequiredException: joinTransaction has been called on a resource-local EntityManager which is unable to register for a JTA transaction.
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.registerIfRequired(EntityTransactionWrapper.java:91)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.joinTransaction(EntityManagerImpl.java:2092)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:360)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:327)
at com.sun.proxy.$Proxy48.joinTransaction(Unknown Source)
at org.apache.camel.component.jpa.JpaProducer$1.doInTransaction(JpaProducer.java:64)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)
at org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:61)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:152)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:304)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:147)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:424)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:424)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
at org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:735)
at org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:82)
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:303)
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
What I don't understand is that JPA insists that my EntityManager is resource-local. In my persistence.xml, I've defined the data source as JTA:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="foobar">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/myDS</jta-data-source>
<mapping-file>META-INF/eclipselink-orm.xml</mapping-file>
<!-- ... lots of entity classes omitted ... -->
<properties>
<property name="eclipselink.weaving" value="static"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
The relevant section in my applicationContext.xml is this:
<!-- snip -->
<import resource="classpath:/datasource.xml"/>
<tx:annotation-driven />
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring" id="foobar-context" useMDCLogging="true">
<!-- ... most routes omitted ... -->
<camel:route id="readXML">
<camel:from uri="file://C:/Data/xmldir"/>
<camel:to uri="direct:persistProduct"/>
</camel:route>
<camel:route id="persistProduct">
<camel:from uri="direct:persistProduct"/>
<camel:unmarshal ref="tnxJAXB"/>
<camel:to uri="jpa:com.foo.bar.Product"/>
</camel:route>
<!-- ... a lot of other unrelated stuff omitted ... -->
</camelContext>
<!-- snip -->
For testability, the data source stuff is in another file:
datasource.xml (complete):
<?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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
">
<jee:jndi-lookup id="myDS" jndi-name="java:jboss/datasources/myDS" />
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="foobar"/>
</bean>
<context:annotation-config/>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
If my research online was thorough, then all this is supposed to be correct and transaction management should work.
However, it doesn't.
What am I doing wrong?
The package versions I'm using:
Camel 2.14.3
Spring 4.1.6.RELEASE
Eclipselink 2.6.0-M3
JBoss AS 7.1.1-Final
Thanks in advance to everyone!
This exception usually occurs when you do not start a transaction. Remember transaction needs to be started at service level not at repository level. As service and repository code is not available here cannot help more.

Camel https web service consumer

I am trying to build a camel https web service consumer and I am not successful in calling this web service. This web service is currently using API-Key authentication and I have the API key. Below is my code that I have tried. Can someone give me some direction as to what I need to do to be able to do api key authentication with this remote web service?
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-http.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="https://api.url.com/api/v3.1/site/query/site/<apikeyhere>"/>
<log message="Message Recieved"/>
<to uri="file:target/messages/message"/>
</route>
</camelContext>
</beans>
All I needed here was the following code:
<to uri="https://api.url.com/api/v3.1/site/query/site/?apiKeyabcd1234"/>
And then I was able to get the data flowing.

Bayeux Server Configuration Issue

We had an issue with our CometD/Gigaspaces application creating a duplicate instances of the Bayeux Server. See my previous question posted here.
After investigating this issue with Gigaspaces, it turns out each bean defined in our Application Context File was getting created twice as
GigaSpaces has special treatment for Application Context Files called PU.XML. We've resolved this issue by renaming the PU.XML File but the
problem we have now is that we're not receiving any data on the client side and receive the following error "NetworkError: 400 Unknown Bayeux Transport - http://localhost:9292/cometd".
Previously, when the application created a duplicate instance of the Bayeux Server, we put a workaround in place to terminate the first
instance of the thread that the Bayeux Server was running on and as a result we were able to publish data on our channels using Web Sockets which we configured in the
Application Context File.
Could you have a look at our current configuration and let me know if there is a alternative solution to configure and export the Bayeux Server correctly using Spring? Is it possible the Bayeux bean is not getting exported correctly or if it is getting exported too late??
I've posted our updated Web.XML and Application Context configurations below. The CometD Version/Jars in our POM.XML are the same as my previous post. If you need further info. please let me know.
Current Web.XMl:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>CometDApplication</display-name>
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- <listener>
<listener-class>org.openspaces.pu.container.jee.context.ProcessingUnitContextLoaderListener</listener-class>
</listener>-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-gigaspaces.xml</param-value>
</context-param>
</web-app>
Current applicationContext-gigaspaces.XML:
<bean id="Bayeux" class="org.cometd.server.BayeuxServerImpl"
init-method="start" destroy-method="stop">
<property name="options">
<map>
<entry key="logLevel" value="0" />
<entry key="timeout" value="15000" />
</map>
</property>
<property name="transports">
<list>
<!-- The order of the following transports dictates the type of transport
used i.e. Web Sockets then JsonTransport (a.k.a long-polling) -->
<bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
<constructor-arg ref="Bayeux" />
</bean>
</list>
</property>
</bean>
<!-- Export the Bayeux Server to the servlet context via springs ServletContextAttributeExporter -->
<bean id="ContextExporter"
class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux">
<ref local="Bayeux" />
</entry>
</map>
</property>
</bean>
The code you posted is correct and virtually identical to the test present in CometD, see here and here.
You have something else going on, and debug logs on both client and server will help you understanding.