Java Web Application deployment on JBoss 7.1 - jboss

I intend to develop and deploy a simple web application using
EJB 3
JSP and servlet
JBoss 7
JPA
I have coded the application and created a standard ear with following structure
app.ear
|_ lib (with all required jars such as the commons logging)
|_ META-INF
|_ application.xml
|_ jboss-app.xml
|_ app_ejb.jar (contains a stateless EJB, an entity, persistence.xml etc...)
|_ app_web.war (jsps, servlet, web.xml etc..)
jboss-app.xml :- (library is the app name)
<!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
<jboss-app>
<loader-repository>library:app=ejb3</loader-repository>
</jboss-app>
application.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4">
<display-name>library</display-name>
<module>
<ejb>ejb_library.jar</ejb>
</module>
<module>
<web>
<web-uri>web_library.war</web-uri>
<context-root>web_library</context-root>
</web>
</module>
</application>
Now when I deploy this ear with the admin console of JBoss 7, the web module seems to have been deployed, even the pages are hit. However, the further part of the application where I try to inject the EJB in the servlet (as a instance varialbe using #EJB), fails.
There seems to be some problem in the way I am deploying the application.
I tried to find a tutorial where I could deploy the app in JBoss but with all that I am stuck till this.
Could anyone guide me with this? I am using JBoss for the first time and am not completely aware of JBoss specific configurations.

EJB that you are injecting, is it implementing an interface? and is that interface registered with the server? #Local or #Remote.
If not, then Try introducing a #Local interface and then your EJB implementation implementing that interface; and then, use that local interface to inject the EJB implementation.
Also, check the threads below;
JBoss 6: Injecting EJB into servlet
Inject an EJB into JAX-RS (RESTful service)
http://docs.jboss.org/ejb3/docs/tutorial/1.0.0/html/Injecting_EJB_in_Servlets.html
A silly thought, but can you re-arrange the modules declarations in application.xml; bring web modules first and ejb following it.
module -> web module
module -> ejb module
Moreover, this is also related to your situation:
http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ch01s04s02.html

Related

Deploying ear in tomee

We are deploying an ear file on Tomee server. We have placed the ear file in tomee/apps folder.
EAR file consists of 1 ejb jar. When we start tomee, deployment is successful without any errors. The ejb has a listener class. How do we tell the EAR to invoke the listener class? Here is my application and web xml but do not see log messages printed from the Listener class. So I know the listener class its not called. Can anyone help? Totally new in this area and migrating from weblogic to tomee. Thanks
myproject/src/main/application/META-INF/application xml
<module>
<ejb>abc-ejb.jar</ejb>
</module>
myproject/src/main/webapps/WEB-INF/web xml
<listener>
<listener-class>com.xyz.listener.startup.AbcListener</listener-class>
</listener>

Not able to access REST within EAR

I am using JBoss to deploy my EAR application which contains a RESTful War file.
I am using javax.was.rs.ApplicationPath, and the REST is accessible and running ok when I deploy the WAR directly on the server.
Problem is when I deploy it within the EAR file, I am not able to access it.
In the application.xml, I have the following
<module>
<web>
<web-uri>TP-Server.war</web-uri>
<context-root>/api</context-root>
</web>
</module>
In the javax.ws.rs.Application:
#ApplicationPath("/")
public class ApplicationConfig extends Application {
}
Is there any special configuration to make REST works in EAR?
Thanks
got problem solved. i think i just tried to republished the app.

How to customize JBoss AS7 404 page

I already created a custom 404 page inside my web app deployed in JBoss AS 7.1.
So if my app is at fubar dot com :8080/Myapp and I go to fubar dot com :8080/Myapp/xyzzy, I get the custom error page (defined in the web app's web.xml file).
However, when I go to fubar dot com :8080/xyzzy, JBoss displays the default 404 page which discloses that it's JBoss and which JBoss version.
I need to replace this page in order to hide this information.
Please advise.
If you want to customize the error pages for all the other contexts in JBoss 7, a part of the configuration you have in your Myapp application, you'll also have:
to disable JBoss welcome page: in the file standalone/configuration/standalone.xml (or domain/configuration/domain.xml), set the attribute enable-welcome-root as false (by default it's true)
Then you'll have to deploy a simple war file setting its context-root to '/', and define the error page for this war (using the same method you've used for Myapp). So, the war structure should be similar to (the error.war name is arbitrary):
error.war
|
|- META-INF
|- WEB-INF
| |
| |- web.xml
| |- jboss-web.xml
|
|- error
|- 404.html
where The web.xml file is:
<?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>yourcompanyname</display-name>
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
</web-app>
And in the jboss-web.xml define the context-root as '/', so it would be:
<jboss-web>
<context-root>/</context-root>
</jboss-web>
The file 404.html is your customized html error page that Jboss will show instead of the 404 default error. That's all, deploy this application in JBoss 7, and you'll have your custom 404 error page when you'll visit fubar dot com:8080/yzyqqa or whatever other root context. Remember that you'll have to keep the error configuration in your Myapp web.xml as well (and in all the other applications you may the deploy in the server).
By the way, have you considered making your app Myapp accessible directly from fubar dot com:8080? Or even better, making the jboss server only accessible from a proxy (for example Apache)?.This way you'd avoid this problem as well.
I hope it helps!
Your problem : You defined the custom error page in web.xml of Myapp. Now if you access any resource with root as Myapp and the request throws a 404 it returns the custom error page.
Now you want that if you access any other root , here xxyzzzz you want to return the custom error page.
Now logically, if you configured a file for other project you cant expect it to be same for other project
Unless
either you configure the same thing for other project , i.e. xxxyzzz as well. i.e. place the 404 config in its web.xml aswell.
or you need to do something at the server scope.
the 1st solution is fairly simple and easy in case there are less number of projects and you not expecting a URL that does not match any of the project.
if you want to go with 1st solution, you know how to do it
Regarding the 2nd approach.
I could find some posts that should be helpful to you
refer these
with jboss as7, the custom of global web.xml is gone.
I could find only one way to configure a global 404 error page. refer here. IT WORKS :D
Custom error pages in Apache for JBoss AS7
I believe you will have to create your own page. JBoss uses Tomcat for serving the web requests.
In Tomcat the way to define your own 404 response page is having the following snippet in your web.xml
(Ref - http://wiki.apache.org/tomcat/FAQ/Miscellaneous#Q6)
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
A detailed page on how to do this with struts is created by mykong # http://www.mkyong.com/struts/how-to-handle-404-error-in-struts/.
If you are using any other framework than struts you should have a equivalent.

how to set specific ejb jndi names in jboss 7.1.1

my web application contains a few 2.x stateful and stateless session ejbs. but unlike previous jboss versions (as well as other major app servers), i am unable to specify an ejb jndi name in jboss 7.1.1. i have followed their docs by eliminating jboss.xml in favor of jboss-ejb3.xml, as well as starting the app server in full profile mode.
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1"
impl-version="2.0">
<enterprise-beans>
<session>
<ejb-name>MyEJB</ejb-name>
<jndi-name>MyEJB_JNDI_NAME</jndi-name>
</session>
</enterprise-beans>
</jboss:ejb-jar>
however, the jndi-name in jboss-ejb3.xml is not taking hold, preventing me from setting my own custom ejb jndi name. does anyone know how to do this right?
<jndi-name> is no longer supported in JBoss AS 7. From this JIRA:
In AS7 we no longer support binding to custom JNDI names for EJBs. So
the beans are always bound to the spec mandated java:global, java:app
and java:module namespaces. The <jndi-name> for the session bean
element is no longer supported.

JBoss 5 AS and EJB3 bean injection from servlets?

It was my understanding that JBossAS 5.x supported EJB3 bean injection in servlets with the #EJB3 annotation. I'm using the default configuration for JBossAS 5.0.1.GA and it's not working. I've added the mappedName argument to the #EJB annotation with the session beans JNDI name, and it just doesn't do anything. No apparent errors, the bean is just never injected.
The session beans are in the ejb-jar, the servlets in a war, everything is packaged in an ear. Manual JNDI lookups work just fine. Any ideas?
This may happen if your web.xml points to an older version of the spec. Ideally, it should be something like
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
This link may help a little too.
You should also check the jar file needed for EJB3 deployment in the classpath.JAr file is jboss-ejb3-ext-api.jar.