Jboss AS 7.2 - Serve static content - jboss

Can I create a static directory in JBoss AS 7.2, like WildFly?
I know the WildFly server can be configured to serve static content by undertow subsystem. For instance:
<server name="default-server">
<http-listener name="default" socket-binding="http"/>
<host name="default-host" alias="localhost">
<location name="/mycontent" handler="content"/>
</host>
</server>
<handlers>
<file name="content" path="${jboss.home.dir}/content" directory-listing="true"/>
</handlers>
According to my requirement, user will upload the static content in the static directory.

I have found the solution.
JBoss AS 7.2 does not support to serve static content's directory as WildFly. I know, not everybody has luxury to use WildFly.
I created a war directory with extension (mycontent.war) instead of war file and created dodeployed.war file also. Inside the mycontent.war directory, I created WEB-INF directory and web.xml file. The web.xml file contains only display name tag. That is it. You can upload the static content in the directory and the contents can be served also.

Related

Can we change Jboss default deploy folder path?

Let's assume I've war file in one location in file system and I have Jboss server installed at different location in file system.Now my question is there any way Jboss can access my war file directly.
In short I don't want to move my war file in deploy folder instead I want location of war file to be treated as deploy folder.
Is it possible??If yes then how?
Add path of custom deployment directory in standalone-*xml like :
<paths>
<path name="custom.dir" path="/PATH_TO/jboss/applications"/>
</paths>
and then in deployment-scanner subsystem mention it like :
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
<deployment-scanner path="customDeployDir" relative-to="custom.dir" > scan-interval="5000"/>
</subsystem>

Serve static content(Single page application) using Wildfly

I need to serve static content outside of WAR using the Wildfly application server.
I setup
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
<handlers>
<file name="welcome-content" path="c:/Users/admin/web" directory-listing="true"/>
</handlers>
Everything worked okay but I faced with the routing problem.
The application has a html5 history support.
When I go to the Url: localhost:8080 everything is okay, my app redirects to /home
But when I refresh the page it returns 404 error.
Is there a possibility to define location name as wildcard e.g. /*
or how can i solve the problem with single page application?

Deployment of webapp in wildfly using Context Descriptors

I searched using "How to set Context Path in Wildfly", but got no success. Can anyone help me on how to do it..?
I've used the following code to set the Context Path in tomcat where I can access my application directly using localhost:8080/myApp
myApp.xml contains as follows and placed at $CATALINA_BASE\conf\[enginename]\[hostname]\myApp.xml
<Context path="myApp" docBase="G:\workspace\j2ee\myProject\myWebApp\WebContent" />
similar or equivalent type of configuration want to use in Wildfly server.
In your standalone.xml configuration you want to add a deployment like this:
<deployments>
<deployment name="myProject" runtime-name="myProject.war">
<fs-archive path="G:/workspace/j2ee/myProject/myWebApp/WebContent"/>
</deployment>
</deployments>
Then within WebContent/WEB-INF create a file called jboss-web.xml with a configuration similar to:
<?xml version="1.0"?>
<jboss-web>
<context-root>/my-context-path</context-root>
</jboss-web>
If this doesn't work you may need to rename WebContent directory to WebContent.war, even if it is exploded it may want .war in the name.

Decreasing log level in Eclipse WTP with Tomcat 7

I am running Tomcat 7 from within Eclipse WTP (Juno) and I cannot seem to tune down the logging level. It logs everything from debug which is too verbose to be of any use (I want it log from INFO). The logging.properties file is as follows:
handlers = java.util.logging.ConsoleHandler
.handlers = java.util.logging.ConsoleHandler
.level=INFO
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
Adding both of these per the FAQ that Tom Chatt cites:
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file="${workspace_loc}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf/logging.properties"
to the arguments to the server's launch configuration will get you what you want.
${workspace_loc} is literal; Eclipse will substitute it with your workspace directory.
tmp0 may be tmp1 or such instead; use the same path that's in the server's configuration.
Assumes that you've placed the logging.properties file there, of course.
That way you'll see the file in the Project Explorer window under Servers.
You should start by copying the one from the Tomcat conf directory.
This all assumes that you're intent on using JULI.
Works for me with Tomcat 8.0 and Eclipse Mars.
No idea why it didn't work for Tom.
I did see ClassNotFounds, for the obvious reason, when I used the wrong class name from someone's post.
I'd advise against the approach of Tom Chatt, since that will affect all of the other uses of that JVM.
I had this same issue, wanting to configure the logging levels of Tomcat 7 in Eclipse WTP. I tried putting a logging.properties in the /src directory of my web app. No effect. I tried modifying the logging.properties file in the /conf directory of my Tomcat installation, but no effect there either. I discovered Eclipse WTP's "shadow" Tomcat area, under my workspace directory, in .metadata/.plugins/org.eclipse.wst.server.core/tmp0, and put a logging.properties file in the /conf directory under there. No effect.
I discovered a number of articles (e.g., this FAQ at eclipse.org) noting that while Tomcat in "real life" automatically runs with a logging manager called "JULI", for some reason the Tomcat running inside Eclipse WTP does not run with JULI. I tried adding
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
to the VM args in my Tomcat run config, but that just got me ClassNotFound errors. (And yes, I did have tomcat-juli.jar in my classpath, so no idea why it wasn't finding it.)
Finally, it occurred to me to try modifying the logging.properties instance in my jdk jre/lib. Jackpot! It turns out that's the one that does have an effect on the logging done by Tomcat-in-Eclipse. So, the moral of this long tale is that if all you want to do is just simply configure the logging while you're running in Eclipse, with a simple little statement like:
myapp.mypackage.level=FINE
Then $JAVAHOME/lib/logging.properties is the place to put it.
To solve this I followed the tomcat log4j guide at http://tomcat.apache.org/tomcat-7.0-doc/logging.html. This will make tomcat use log4j.
Next set up a log4j config in $CATALINA_HOME/lib.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="null" class="org.apache.log4j.varia.NullAppender" />
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
</layout>
</appender>
<category name="org.package.domain">
<priority value="INFO" />
<appender-ref ref="console" />
</category>
</log4j:configuration>

Context pointing to external directory in Jetty 9

I want to deploy a .war file to Jetty by setting up a context that points to my external .war (outside webapps folder). I know how to do this in Tomcat, but I can't figure out how to do this for Jetty 9.
In Tomcat I placed an .xml file to configure my context in $CATALINA_HOME/conf/Catalina/localhost :
<?xml version='1.0' encoding='utf-8'?>
<!-- Context fragment for deploying ServletExample.war -->
<Context path="/CurrencyServlet" docBase="/Users/macbook/Desktop/School/Java/Temp/CurrencyServlet.war" debug="0" privileged="true"/>
Can anyone provide a simple example for Jetty 9?
Have a look at the provided $jetty_home/webapps/test.xml file. In jetty9 you can configure your webapps, etc. by placing a ContextProvider config file in $jetty_home/webapps.
Have a look at the docs: http://www.eclipse.org/jetty/documentation/current/configuring-contexts.html
This is how you configure the path to your webapp:
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set>