Is embeddable container working with JBoss 7? - java-ee-6

Some time ago, I tried out the embeddable container API of EJB 3.1 with GlassFish.
Now I tried to do the same thing with JBoss 7.1, but could not make it work. I spent some time researching the problem, but only found others having this problems and no answers or examples to it.
I do know of Arquillian, which more or less eliminates the need of an embeddable container for testing EJBs, but still am interested in a working solution.
So, here's the code which works with GlassFish:
Map<String, Object> params = new HashMap<String, Object>();
//param is needed due to GlassFish bug http://java.net/jira/browse/GLASSFISH-16285
params.put(EJBContainer.APP_NAME, "MyAppName");
EJBContainer container = EJBContainer.createEJBContainer(params);
MyBean instance = (MyBean) container.getContext().lookup("java:global/MyAppName/classes/MyBean");
instance.doSomething("data");
container.close();

Related

Websphere problems when setting up Http Connection Pool for RestTemplate

I'm working with Spring 4.0.3.RELEASE version. I'm able to make restful calls successfully. However, I learnt that HTTP connections are expensive and thought of using connection pool. I read few articles like this and this. Everything is fine when I include the dependency with Maven3 and compile. The problems arise during runtime.
With this code, I get class not found exception for PoolingHttpClientConnectionManager.
public RestTemplate restTemplate(){
HttpHost host = new HttpHost("localhost", 9081);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// Increase max total connection to 200
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(50);
cm.setMaxPerRoute(new HttpRoute(host), 20);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(cm);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
httpClientBuilder.build());
return new RestTemplate(requestFactory);
}
And with this code, I get class not found exception for HttpClients.
public RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(20000);
requestFactory.setReadTimeout(20000);
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}
I'm deploying on Websphere 8.5. And I tried different versions of httpclient from 4.0.1 to 4.5.2 with different scope (provided, compile) with no luck.
Thanks in advance for any hint in the right direction.
So, it's basically a problem with Websphere 8+ versions including httpclient with their jvm library. Luckily, our Enterprise Websphere are all 7.5.x version. So, if we bundle the httpclient with the ear, it does not cause any issue in production or pre-production.
For those, who have to use Websphere 8.x versions, please use the shared isolated library approach as defined here. I used that for my local 8.5 Websphere and it works pretty neat.
you should stop the application and then go to manage module tab in websphere and
and on "Class loader order" combo box choose "parent last" item
and then start application. problem solved...

Jboss (Wildfly 9.0.1) - Remote EJB calls stops responding Intermittenly

We are upgrading JBOSS from (4.0.2) to latest Jboss (Wildfly 9.0.1) for our J2EE webApp. After upgrading we found that EJB calls are stop responding after 1 hour of load test.
Please note that the other areas of application is working fine where EJB is not used. The problem is only with remote EJB calls.
We have to restart Jboss to fix the issue.
Do we need to any configuration (threads/EJB pool) in Jboss (Wildfly 9.0.1)?
I'd just like to drop in and say that we're experiencing the same thing. What I recall reading is that this happens when the Wildfly has to wait to long to return an answer and suddenly the whole service becomes unresponsive.
We were running 8.2.0 Final and the only suggestion I could find was to upgrade. After performing an upgrade to 9.0.1 Final we're still seeing this. There was seemingly more people experiencing this but I have not been able to find any solution yet. The issues I found on the JBoss issue tracker on this have all been rejected and they're implying that it's more open for community discussion.
I have this lingering notion that toying around with timeouts might help though I haven't had time to try this yet.
P.S. I'm not privileged enough to simply comment which I would preferred.

jboss error migrating EJB 2.X ap to jboss 5

I migrating someone else's EJB 2.X app from jboss 3 to jboss 5 (and then maybe onto AS7).
When I do a test deployment of one of the EJBs I am getting this error
org.jboss.deployment.DeploymentException: Could not load class:
at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityCommandMetaData.<init>
(JDBCEntityCommandMetaData.java:76)
at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData.<init>
(JDBCEntityMetaData.java:954)...
Googling this stack trace doesn't give me any leads I can work on. As far as I can tell this means that the entity-command in conf/standardjbosscmp-jdbc.xml is wrong but I have no idea what it should be. Looking at the jboss 3 conf/standardjbosscmp-jdbc.xml file doesn't even have an entity-command listed so I assume "default" should be ok, no? I am using Oracle 11g, if that is meaningful and otherwise seem to have no db connection issues. The Oracle datasource seems to be created without problems. This is the very first error in the output. Any clues as to what i should look a to resolve this?
Are you sure you build everything against JBoss 5 libs? This could be a build problem...

Several REST and EJB problems

I'm trying to deploy a Java EE web application with RESTful web services and an EJB connexion to another Java EE application.
I'm experiencing several problems and I fail to write down every specific question, so I have no choice but tell you all in a row.
1) First, I am using Tomcat to run the app and I cannot get EJB connexion to work. No matter what, I get a JNDI error : NamingContextFactory class not found. Why ?
My JNDI connexion is as follows :
String hostname = "localhost";
String port = "1099";
String url = "jnp://" + hostname + ":" + port + "/";
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
h.put(Context.PROVIDER_URL, url);
h.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
initialContext = new InitialContext(h);
2) Therefore, as the server used is not relevant, and as the app I'm trying to connect to is using JBoss (4.4.2.GA), I tried to deploy my app under the same JBoss. I cannot get it to deploy, I have a REST problem: ClassNotFoundException: javax.ws.rs.core.ApplicationConfig at deploy time.
2.1) I am compiling with Netbeans and the ApplicationConfig.class is not part of the 1.1 version of the JAX-RS api jsr311-api-1.1.jar I'm using at compile time. The implementation of the library was changed since 0.8 version, which I was using before, but I had to upgrade the jar because it didn't include #FormParam. Until now, I had found a workaround using com.sun.jersey.api.representation.FormParam instead but Jersey is not compatible with JBoss as far as I understand.
Why is the server looking for ApplicationConfig while it's not used in the war?
2.2) I understood I had to use RESTEasy, and JBoss 4 does not include it, so have to install it manually. But the RESTEasy doc suggest that I thoroughly modify my project my adding a lot of jars, servlets etc. From my point of view, I simply need a RESTful implementation on the server libs to which my JAX-RS API, which is only an interface, will refer once the app is deployed. I may have some serious misconceptions about how Java EE libraries linking work. Please help.
So I know there are several different problems here but I couldn't manage to separate them. I have lost so much time on this that I'm worried for my project. Thanks in advance.

POC on JMS on Jboss

I am doing a POC for runnig JMS on JBoss 4.0.5 GA. can anyone privide me a link which shows examples on how to
Create a queue in Jboss
Crate a factory in Jboss.
Configuration
If the above are not applicable, the is there a default que, topic, factory in Jboss.
http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/4/html/Messaging_on_JBoss.html
http://www.outwardmotion.com/outwardmotion/jmsjboss1.php
The first thing to note is that JBoss 4.0.5 will be running JBossMQ by default (As opposed to the newer JBoss Messaging). The answers to some of your questions depend on what you're doing, i.e. MDBs/EJB3 or not?
Note, you'll have to add http:// to the beginning of these links, Stackoverflow is being lame and not letting me post links.
Take a look at this URL: www.java2s.com/Code/Java/EJB3/EJBTutorialfromJBossdemoformessagedrivenbean.htm
The Queue will be created for you automatically when JBoss loads the MDB in the example
Assuming you mean a JMS Connection Factory, you can inject factories and destinations into EJB3s using something like the following:
#Resource(mappedName = "queue/notification.EmailSender")
private javax.jms.Destination emailSenderQueue;
#Resource(mappedName = "QueueConnectionFactory")
private javax.jms.ConnectionFactory connectionFactory;
This is a good starting point: www.jboss.org/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/4/html/Messaging_on_JBoss.html
Also if you're not doing EJB3 yet in Jboss 4.0.3, see: rwatsh.blogspot.com/2006/12/ejb3-development-using-jboss-405ga.html