Error "Invalid broker URL" while bridging ActiveMQ Artemis 7.4 with Weblogic 12.x - weblogic12c

I am trying to create bridge between Oracle 12.x and Redhat ActiveMQ Artemis 7.4. This is what has been done to set up the bridge:
Set artemis-jms-client-all-2.9.0.redhat-00005.jar to WL classpath
Set the following properties to WL classpath:
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=amq.xaqcf.myqueue
queue.queues/myqueue=myqueue
However, I get the following error:
java.lang.Exception: javax.resource.ResourceException: ConnectionFactory: failed to get initial context (InitialContextFactory =org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory, url = tcp://brokername:61616?type=XA_CF, user name = amq)
at weblogic.jms.adapter.JMSBaseConnection.throwResourceException(JMSBaseConnection.java:1750)
at weblogic.jms.adapter.JMSBaseConnection.startInternal(JMSBaseConnection.java:538)
at weblogic.jms.adapter.JMSBaseConnection.start(JMSBaseConnection.java:264)
at
...
-------------- Linked Exception ------------
javax.naming.NamingException: Invalid broker URL
at org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory.getInitialContext(ActiveMQInitialContextFactory.java:85)
According to ActiveMQInitialContextFactory.java, it is due to the following block:
for (Map.Entry<?, ?> entry : environment.entrySet()) {
String key = entry.getKey().toString();
if (key.startsWith(connectionFactoryPrefix)) {
String jndiName = key.substring(connectionFactoryPrefix.length());
try {
data.put(jndiName, createConnectionFactory((String) environment.get(key), jndiName));
} catch (Exception e) {
e.printStackTrace();
throw new NamingException("Invalid broker URL");
}
}
}
Here's the exception from e.printStackTrace():
Exception: javax.naming.NameNotFoundException: amq.xaqcf.myqueue
at org.apache.activemq.artemis.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:236)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
I have no issue bridging between Oracle Weblogic 12.x with ActiveMQ 6.3. A similar issue was raised here Is there a Java 1.7 compatible Artemis JMS client? but it is for Oracle SOA 10.x which uses java 1.7.
How can I make it work? Should ActiveMQInitialContextFactory.java be adapted?

Your problem is coming from the fact that you're attempting to look-up the connection factory amq.xaqcf.myqueue, but you haven't actually defined that connection factory in your JNDI properties. Instead you have this line:
connectionFactory.ConnectionFactory=amq.xaqcf.myqueue
This line actually defines a connection factory called ConnectionFactory with the URL amq.xaqcf.myqueue which is invalid. Try this instead:
connectionFactory.amq.xaqcf.myqueue=tcp://brokername:61616?type=XA_CF
The syntax for these properties is defined in the Artemis documentation.

Related

Trouble with Authenticating with remote EJB calls to Wildfly 10

I'm trying to do Remote EJB calls to my Wildfly 10/JBoss 7 EAP server, but keep getting Invalid User error messages on my Wildfly server (my EJB is called LoginManager):
23:04:02,872 ERROR [org.jboss.as.ejb3.invocation] (default task-6) WFLYEJB0034: EJB Invocation failed on component LoginManager for method public abstract java.lang.String ejbs.LoginManagerRemote.echo(java.lang.String): javax.ejb.EJBAccessException: WFLYSEC0027: Invalid User
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:69)
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:49)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:97)
I've added my user to the application-users.properties file using the add-user.sh/bat scripts.
I've tried putting in breakpoints in the Wildfly server itself in the SecurityContextInterceptor class on line 54 and see that the principal is null:
if (holder.skipAuthentication == false) {
holder.securityManager.authenticate(holder.runAs, holder.runAsPrincipal, holder.extraRoles);
I'm not entirely sure if this runAs or runAsPrincipal is the principal/credentials passed by the remote EJB invocation, but I suspect it might be responsible for my problem.
I'm calling the remote ejb as:
Properties p = new Properties();
p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(p);
LoginManagerRemote ejb = (LoginManagerRemote) context.lookup("ejb:ear-1.0/ejbs-1.0//LoginManager!ejbs.LoginManagerRemote");
return ejb.echo("test");
with my jboss-ejb-client.properties as:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.conncetion.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
remote.connection.default.username=test
remote.connection.default.password=test
Am I doing something wrong? Am I missing something obvious somewhere? What do I need to do to successfully call a remote EJB?
There's a typo in your jboss-ejb-client.properties
remote.conncetion.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
Should be remote.connection.default.connect.options etc etc

IllegalStateException while using UserTransaction (Java EE)

I am trying to make my first Java Enterprise Application and use UserTransactions.
Therefore I use JNDI Lookup with java:comp/UserTransaction to get my UserTransaction Object.
public void myMethod(MyEntity e) throws ApplicationException {
try {
this.ut = getUserTransaction();
this.ut.begin();
this.myStatefulBean.myBusinessMethod(e);
} catch ...
When I start my Transaction with .begin() and try to invoke any method in my stateful Bean (which works properly before starting a UserTransaction) I get an EJBTransactionRolledbackException which leads me to the following error:
java.lang.IllegalStateException: cannot add non-XA Resource to global JTS transaction
The Bean I am using is annotated with #DataSourceDefinition having className = "org.apache.derby.jdbc.ClientXADataSource" thus there is imo no non-XA Resource.
What am I doing wrong?
I am using openjpa 2.2.1, Java EE Version 6
Solved the problem by myself. I used in my DataSourceDefinition name = "java:global/jdbc/testDB" as name, but in my persistence.xml the DataSource name was defined as <jta-data-source>testDB</jta-data-source>
This seems to work in CMTs but not in a UserTransaction. Correcting the entry in persistence.xml to <jta-data-source>java:global/jdbc/testDB</jta-data-source> fixed the problem.

JBoss 7.1: java.lang.IllegalStateException: No 'jboss' MBeanServer found

My application is deployed on JBoss 7.1 (standalone).
I am getting an exception on the following line:
MBeanServerConnection server = MBeanServerLocator.locateJBoss();
The exception is:
JBoss: java.lang.IllegalStateException: No 'jboss' MBeanServer found!
That code above worked fine when the app was deployed on JBoss 5.
From what I was reading online, the code is supposed to work only when it's called from the same JVM in which the MBeanServer was created. Otherwise it's a remote call and I have to use JNDI. But is it not a local call (same JVM - i.e. the JBoss JVM)? How did it work on JBoss 5 then?
How do I make it work on JBoss 7.1 standalone, without changing this specific code?
Here is the solution:
https://community.jboss.org/thread/221708
Quote:
Above problem is dueto locateJboss implementation that is compatible with older version of Jboss. The MBeanServer used by JBoss 7 (by default) is the platform MBeanServer. The class name iscom.sun.jmx.mbeanserver.JmxMBeanServer and the default domain is DefaultDomain. Accordingly, you can simply use:
java.lang.management.ManagementFactory.getPlatformMBeanServer()
Alternatively:
for(MBeanServer server: javax.management.MBeanServerFactory.findMBeanServer(null)) {
if("DefaultDomain".equals(server.getDefaultDomain())) return server;
}
throw new Exception("Failed to locate MBeanServer");
On another note, jboss.system:type=ServerInfo object name doesn't work in AS 7.1 I had to use JVM specific parameters to nail down to MBean attributes. 'java.lang:type=Memory' and attribute as 'HeapMemoryUsage'.

Log4j Initialization error JBoss RestEasy

I am using JBoss 6.0. I am running a simple webserver using the jboss.resteasy library to provide simple XML responses to HTTP requests.
I have:
- A server
- A simple Java Client that creates a GET request
Now the thing is, if I use the browser to access the URL, I get the wanted XML. But if I use my Java client, which has the following code:
//Register the fake instrument
GetMethod get = new GetMethod("http:/localhost:8080/"+PROJECT_NAME+"/webserver/registerInstrument/?name=FakeClient&value=0");
HttpClient client = new HttpClient();
try {
int status = client.executeMethod(get);
} catch (HttpException e) {
System.out.println("[FakeClient] HttpException executing AddInstrument GET request: "+e);
} catch (IOException e) {
System.out.println("[FakeClient] IOException executing AddInstrument GET request: "+e);
}
Then I get the following exception:
log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.params.DefaultHttpParams).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.IllegalArgumentException: Host name may not be null
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:68)
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at client.FakeClient.<init>(FakeClient.java:30)
at client.FakeClient.main(FakeClient.java:22)
At first I thought this could be a problem with the JBoss logging, but if I access the URL through the browser, I obtain the desired XML with no problems.
Is this a problem with the Java client application?
Thank you
The 'log4j:WARN' is just a warning. It has nothing do to with the actual exception being thrown.
The exception message states that 'Host name may not be null'. This clearly indicates that there is something wrong the the hostname. And looking at you code, I can spot one error.
You need to add an extra forward slash:
GetMethod get = new GetMethod("http://localhost:8080/" ...

No Suitable Driver found for JDBC-Postgresql

I am building a project using "Maven".
In the Pom.xml i have added dependency for Postgresql and it is downloaded (as required) and is present in the Project's libs/ folder.
Now i have made a connection to it in my java file as follows :
static String userid="postgres", password = "myPassword";
static String url = "jdbc:postgresql:coredb_jfeed6";
static Connection con;
con = DriverManager.getConnection(url,userid, password);
Where "coredb_jfeed6" is my database name.
There is no compile time error. But at runtime it produces the following error :
Exception stack is:
1. No suitable driver found for jdbc:postgresql:coredb_jfeed6 (java.sql.SQLException)
java.sql.DriverManager:640 (null)
Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:postgresql:coredb_jfeed6
(org.springframework.jdbc.CannotGetJdbcConnectionException)
org.springframework.jdbc.datasource.DataSourceUtils:80 (null)
Root Exception stack trace:
java.sql.SQLException: No suitable driver found for jdbc:postgresql:coredb_jfeed6
at java.sql.DriverManager.getConnection(DriverManager.java:640)
at java.sql.DriverManager.getConnection(DriverManager.java:169)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
Could anyone please help me regarding this.?
Ok. I figured it out.
Its a BUG in Mule 3.1.2.
Its like "When an external library is to be searched, then Mule looks it in projects/lib folder. But this does not hold true for All the Database related Libraries like postgresql library" . So we need to put it in mule/user/lib folder for it to Work Correctly.