JBoss as an http server?
Asked Answered
M

3

9

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.

Maidie answered 11/9, 2013 at 20:31 Comment(6)
The problem is primarily a production problem, not a development problem.Maidie
Than why not put all the static content in a separate war? For that matter, why have JBoss serve the static content at all? Most production environments I've encountered have a webserver (apache, nginx) in front of their appserver anyway. That webserver can be used to serve the (static) webcontentBluegreen
I am currently working with the content in an exploded war so that I can continue development. However, jboss can do the static content thing -- it already does that with its welcome-content directory, and it is specifically how to configure jboss to do this that I'm looking for.Maidie
I guess you'll keep on getting workaround suggestions since I (dare I say we?) don't understand why you have this strange requirementBluegreen
this is how you do it with Wildfly, but it might just be that you can't do it in AS7.Tortuga
It's a little late now, but if you're open to something completely different, drop JBoss and try dropwizard.io -- perfect for mixing RESTful services with static content.Pekoe
T
0

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.

Transmit answered 26/2, 2014 at 21:36 Comment(0)
C
0

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")
Cran answered 31/8, 2019 at 4:30 Comment(0)
V
-1

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.
Val answered 1/4, 2018 at 7:15 Comment(2)
I did not mean to ruffle your feathers:) I have updated the answer.Val
Ok, I've deleted my original comment because it was inappropriate, sorry. However, I still stress that you're answering the wrong question (with the majority of your answer). Everything after the link to jboss is opinion rather than fact and is of limited applicability. Stack overflow actively tries to discourage both. This question does not require an in-depth tutorial on nginx.Maidie

© 2022 - 2024 — McMap. All rights reserved.