JBoss as an http server? - jboss

I'm trying to write a webapp where the server side provides only json/REST services, and the gui is written in html5, backbone, marionette, etc. using async XHR. The html, js, css, etc. is static and cachable (when deployed to production).
I need to deploy this to JBoss EAP6 (broadly equivalent to AS7 for this problem). During development I'd like to be able to edit my javascript and html templates and have the results instantly visible in the browser. In production I need my static content (the front end) to be exploded and not deployed in any type of Java EE structure (so, no war or ear (or sar)).
So, basically, I need to deploy wars to jboss, as usual, and I also need jboss to act as an http server for the static part of the app.
I have played with the idea of copying my content into the welcome-content directory in the root of EAP6. While this serves the content with no problem I can't work with this structure for development because I can't live with the time overhead of copying my changes across to a different directory. I have also tried a symlink from welcome-content to my static content in the dev environment, but this doesn't work in this version of jboss.
Edit: I have answers that are telling me how to work around the problem, but I'm not really stuck for a workaround -- that's easy. I'm really looking specifically for how to configure jboss to serve static content.
TIA.

You could just deploy the static html/css/js like you normally would, and use a tool to inject changes into the DOM for you in real time. I'm doing this with GruntJS now using grunt-contrib-watch and it works pretty well.

Update for JBoss EAP 7.x
Just to complement the answer by Zach Lysobey, JBoss EAP 7.x has Undertow was underlining https/2 server. It has therefore it's own properties and has as basic properties below:
<subsystem xmlns="urn:jboss:domain:undertow:1.0">
<buffer-caches>
<buffer-cache name="default" buffer-size="1024" buffers-per-region="1024" max-regions="10"/>
</buffer-caches>
<server name="default-server">
<http-listener name="default" socket-binding="http" />
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content" />
</host>
</server>
<servlet-container name="default" default-buffer-cache="default" stack-trace-on-error="local-only" >
<jsp-config/>
<persistent-sessions/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
</handlers>
</subsystem>
Reference: Undertow.io
Cli commands
You can therefore change the properties using the CLI command and subsystem=undertow:
/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=url-charset,value="utf-8")
Static content in Undertow
This other question describes a similar situation and the official documentation describes a file handler for serving static files.
Cli command to create a file handler:
/subsystem=undertow/configuration=handler/file=new-file-handler:add(path="${jboss.home.dir}/welcome-content")

Update
TL;DR
I presume that the original issue is long resolved now after more than 5 years since it was asked. If someone really insists on using JBoss as static file web server, then the solution mentioned in the question is THE solution - using welcome-content directory. With EAP6 you must have an active paid subscription from RedHat to use it in production, and their knowledge base does provide the same answer.
As its not 2013 anymore, copying a bunch of static files really should not be an issue, and most IDEs can handle that quite well(only copying the files that changed etc).
For everyone else coming here from google, it is IMHO more beneficial to point to the right tools for the job and separate backend and frontend deployment(btw Nginx was available long before 2013, and Apache has been here, well, since forever :) ).
Although it is possible to host your static web assets via JBoss, it is a rather inefficient use of java web server. As your Frontend is completely separated from you java backend, why not deploy it to dedicated web server - Nginx or Apache for example, which is going to be vastly more efficient and suitable for serving static content.(Or a dedicated Wildfly w/ Undertow if you must)
You do not specify, if you only have a single JBoss instance or a more complex deployment but one common scenario for a usecase like yours goes like this:
[Nginx server:80] <--> [JBoss server:8080]
- location / { |- your-backend.war
root /path/to/frontend (web context /myapp/api)
}
- location /api {
proxy_pass http://backend
}
Head over to Nginx documentation for more info.
Advantages of using dedicated web server:
You can use it as load balancer at the same time, just add more Jboss instances, update the upstream config and you have scalable backend, yey
Deployment of your Frontend is simply a copy of static files to the corresponding folder - no need for restart, you can configure the paths to suit your folder structure.
Nginx(or well configured Apache) can handle extreme load with ease, it uses event mechanism instead of threads, + you can fiddle with caching strategies etc
You alleviate your java web server from the overhead of serving static web assets, and you can tune it for what it does best- server your java web service
You can deploy multiple web frontends or multiple projects, with different hostname, so you can host dev and test versions of your app on a same physical server and bind them to for exampe https://dev.myapp.com and https://test.myapp.com
You can use Web server for SSl offloading - again, alleviating your JBoss app server from the burden of SSL handling.

Related

How to deploy non-ear website in jboss

I have a website comprising of a server and client. The server is an EAR, and I'm using JBoss to deploy it. The frontend is a series of html/js/css files that call into the backend via ajax.
I can deploy the frontend to an apache (2.2) server, and it works fine, however, I have a requirement that they both be on the same port (with different contexts). How do I deploy my static files to jboss in their own context? It also needs to be able to use mod_rewrite (or something similar).
Thanks
You could use Apache as the front end web server for the Jboss app server behind it. You can deploy all your content to Jboss and configure Apache to manage it.
Or you can use Apache to serve the static content and still use it as the front end for Jboss, configuring Apache to map your Jboss port to Apache. You can configure it to use different contexts if you need to.
Take a look here

Difference between jboss 6 and jboss 7 standalone server?

I was using Jboss 6 . I am wondering to see jboss 7 which does not have many folders that jboss 6 had. It will be helpful if someone explains the difference between the jboss 7 stand alone server and the previous versions.
AS7 is different in a lot of respects to its predecessors AS6,5. So it wont be possible to list down all the differences here.
to list supported technology related differences, refer to below table.
Some Major Differences: (Thanks for #Jyore for additions)
Modular (on-demand) class-loading
Addition of domain managed nodes (multiple JVM management)
All configuration is done in Standalone.xml for standalone mode and domain.xml for domain mode.
About the new DIRECTORY Structure
configuration : Configuration files for the standalone server that runs off of this installation. All configuration information for the running server is located here and is the single place for configuration modifications for the standalone server.
data :Persistent information written by the server to survive a restart of the server
deployments: End user deployment content can be placed in this directory for automatic detection and deployment of that content into the server's runtime.
NOTE: The server's management API is recommended for installing deployment content. File system based deployment scanning capabilities remain for developer convenience.
lib/ext : Location for installed library jars referenced by applications using the Extension-List mechanism
log : standalone server log files
tmp : location for temporary files written by the server
Apart from that I really dont want to duplicate information on web
There is a migration guide from AS5,AS6 to AS7. This can help you understand what are the config changes that are generally required to switch to AS7. it also points out what has significantly changed, highly recommend going through it.
Also You can read Getting Started with AS7, to know AS7 better

Deploying .ear file (contains rest services)

I have a few questions about deploying my .ear file (was provided to me, the file itself should not be the problem). I set up jBoss application server jboss-6.0.0.Final and was able to run a simple hello world app to ensure the server was functioning properly.
I was told to place the .ear file in /server/default/deploy so I did. When I ran jboss (through /bin/run.bat) I got no errors related to deploying the ear file.
Question
Is this all the software I need (jBoss)? Do I also need something like Apache or tomcat?
The .ear file contains RESTful service calls that should return xml. Will these be deployed (accessible through a jQuery ajax call after the server (jboss/bin/run.bat) is executed?
Currently when I try to make the calls, the resources do not seem to exist.
Thanks in advance for taking the time to help.
JBoss AS ships with an embedded Tomcat as a servlet container so you really don't need that anymore. Apache Web Server is NOT required for your .EAR to be deployed properly.
To answer your questions
No other software is needed to deploy the EAR. You simply copy your EAR file to deploy directory (which you have rightfully done so).
If your EAR contains RESTFul services, they will be deployed and you can access them using any client including jQuery or even a simple browsers. The trick is to know the access URL to the RESTFul services.
If you have difficulty identifying the URL for accessing your RESTFul services please refer [1] for more information.
Hope this helps.
Good luck!
[1] https://docs.jboss.org/author/display/AS7/JAX-RS+Reference+Guide
I can answer the first question. You need apache if you want to serve static content or you need to isolate the traffic (say keep apache in the dmz and then use apache to proxy traffic to the internal jboss servers). tomcat is bundled along with jboss, so you do not need it.

GWT server part?

I'm thinking about an application where in some cases both client and server would run on customer's computer. Concerning the client's resource usage I've found this question, concerning the general disadvantages of GWT I've found this, but I can't find anything about the overhead of the server part. I need no application server there, anything capable of running the server part of GWT would do.
What is needed to run the server part of GWT and how many resources it consumes?
If you use a ServiceImpl w/ your GWT app, you need to deploy it into a servlet container, like Tomcat or Jetty (or many others). Otherwise, it can be deployed on any web server, as it will only consist of javascript, HTML, and CSS.

Stop browser scripts caching in GWT App

I have a GWT app deployed onto our client's machines. As an ongoing
development alongside, we have to release new improved versions of the
application fron time to time. Everytime we release a new version we
often run into the problem where the client's browser has cached the
old scripts scriptsand for a while it behaves strangly as the data it
is trying to work with is not quite compatible with it. What is the
best way to overcome this problem. Currently I have to tell the users
to clear their browser's cache for a new release but it would be nice
they don't have to do this.
Possible solution depends on the way you are hosting your application. If you are hosting directly from servlet container, then you can use servlet filter like the one described here:
http://seewah.blogspot.com/2009/02/gwt-tips-2-nocachejs-getting-cached-in.html
Here are appropriate filters from tadedon library:
http://code.google.com/p/tadedon/source/browse/tadedon-servlet/src/main/java/com/xemantic/tadedon/servlet/CacheDisablingFilter.java
http://code.google.com/p/tadedon/source/browse/tadedon-servlet/src/main/java/com/xemantic/tadedon/servlet/CacheForcingFilter.java
And here is guice ServletModule which enables them for the whole guice web application:
http://code.google.com/p/tadedon/source/browse/tadedon-gwt/src/main/java/com/xemantic/tadedon/gwt/http/GwtHttpCachingModule.java
If you are using some reverse proxy in front of tomcat it would be even simpler. In case of apache (e.g. mod_proxy, mod_jk), and assuming that all the application resources (html, graphics, java scripts, css, etc.) are put on apache, just set these options in apache configuration:
<Files *.nocache.*>
ExpiresDefault "access"
</Files>
<Files *.cache.*>
ExpiresDefault "now plus 1 year"
</Files>
It is described here:
http://code.google.com/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html
in "Perfect Caching" section. Such deployment scenario assumes that only rpc requests should go through reverse proxy to tomcat. If for some reasons all the application context is proxied to tomcat you can still use apache's LocationMatch directive instead of Files directive.
By default, the bulk of your app should be cached by the browser until a new version of it is generated by your build process.
It might help to understand the GWT bootstrapping model to understand how this works.
The first script your client requests, your-app-name.nocache.js, is not cached, and it does nothing except check the browser's user agent and capabilities, and make a second request for the relevant app JS.
At this point, the script it requests should be cached by the browser if it's been requested before. This is a {indistinguisable-numbers-and-letters}.cache.html file.
When you redeploy your app, the nocache.js file will be executed and ask for a different cache.html file from the server, which will not already be present in the cache, but which will get cached by the browser once it is downloaded.
Are you doing anything unusual with deferred binding, or with caching headers on your server? This might potentially be causing your nocache.js file to get cached after all, which would make it request old cache.htmls from the browser cache.