Enabling JBoss AS 7 Directory Listings - jboss7.x

I have the following directory structure deployed to JBoss AS 7.1.1.Final (under standalone/deployments):
doc.war
-> module1
-> index.html
-> module2
-> index.html
As you can see, there's no index.html under doc.war. When I browse to localhost:8080/doc/module1/, the correct index.html is displayed, but when I browse to localhost:8080/doc/, JBoss shows an error message (404 - The requested resource is not available).
I think this is related to the fact that directory listings are turned off by default in JBoss AS 7. How can I enable directory listings, either globally or more specifically for this one application?
Edit
Based on Mukul Goel's answer, I ran the CLI command to add the static-resources feature, restarted the server and retried the request, but it didn't work.
Here's the relevant snippet from the standalone.xml file. Please note that I have the native connector enabled.
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="true">
<configuration>
<static-resources listings="true"/>
</configuration>
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https"/>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
</virtual-server>
</subsystem>
Here's the error message that JBoss is showing:
Update
So the conclusion to this seems to be that there is an issue with the official JBoss 7.1.1.Final (http://www.jboss.org/jbossas/downloads) download. I didn't manage to get Directory Listings working with this version. Trying a later version (from the JBoss CI server at https://ci.jboss.org/jenkins/job/JBoss-AS-7.x-latest/), I was able to see the directory listings after applying the config change that Mukul Goel had suggested below.
A potential source of this issue could be the version of JBossWeb that is used in JBoss. The official 7.1.1.Final bundles JBossWeb 7.0.13. Mukul (see below) was able to get it working running a version of JBoss that bundles JBossWeb 7.0.16.
I'm accepting Mukul Goel's answer as solving this issue, but be aware that it will probably not work with the official 7.1.1.Final download.

Yes you are right, directory listings are by default disabled (a security measure)
To enable directory listing in JBOSS
Try running the following CLI command to enable diectory listing:
In Domain Mode
/profile=full/subsystem=web/configuration=static-resources/:write-attribute(name=listings,value=true)
.
In Standalone Mode
/subsystem=web/configuration=static-resources/:write-attribute(name=listings,value=true)
It will generate following kind of configuration :
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
<configuration>
<static-resources listings="true"/>
</configuration>
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
</virtual-server>
</subsystem>
UPDATE:
Tried it myself as the user is facing problems
RAN CLI command for the standaloneMode
This was generated, note that the native is disabled also there is no HTTPS connector generated for me (Don`t know why it is showing enabled for you? are you using openSSL somewhere? )
I created a sample webprojet(a client side project) with two htmls ,published it to jboss and hit url
http://localhost:8080/sample/
and this is the screenshot of directory listing
The command worked it for me, So that does turns on Directory listing on JBOSS AS7.1.1 Final(I am also using the same version)
So the question comes down to rest of your server configuration, your application structure, technologies you are using, springs etc and also if you are using some ssl library.
UPDATE 2
Suggested a fresh download and reconfigure environment and see
nwinkler was still facing issues even with a fresh distribution (JbossWeb 7.0.13) So suggested to take nightly builds from
ci.jboss.org/jenkins/job/JBoss-AS-7.x-latest
Just go to the link and download whats under last successful artifact
And the problem was resolved. Looks like some bug with jbossWeb 7.0.13
Do go through the comments, the discussion might be helpful

Related

Rewriting paths with undertow-handlers.conf doesn't work as expected

Background
JBoss 7.1.5 EAP back-end with an Angular 7 UI.
I need to make JBoss aware of the UI's routes, but rewrite them all to the UI's index page for routing by Angular.
The project is structured thus:
webapp/
WEB-INF/
undertow-handlers.conf
web.xml
...etc
login/
background.jpg
login.jsp
index.jsp
assets/*
...html
...js
...css
index.jsp simply response.sendRedirect("index.html")s, where index.html is part of the assets produced by the Angular CLI. JavaScript and HTML is served from webapp/, images from webapp/assets/.
Configuration
From standalone-full.xml
<subsystem xmlns="urn:jboss:domain:undertow:4.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="http" socket-binding="http" redirect-socket="https"/>
<host name="default-host" alias="localhost,workstation">
<location name="/" handler="welcome-content"/>
<filter-ref name="request-dumper"/>
</host>
</server>
<servlet-container name="default">
<jsp-config x-powered-by="false"/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<filter name="request-dumper" module="io.undertow.core" class-name="io.undertow.server.handlers.RequestDumpingHandler"/>
</filters>
</subsystem>
and
<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host">
<alias name="localhost"/>
<alias name="workstation"/>
</virtual-server>
</subsystem>
With the above configuration, I see the expected server log:
[org.wildfly.extension.undertow] (ServerService Thread Pool -- 84) WFLYUT0021: Registered web context: '/' for server 'default-server'
And I can access the site's login page, and the URI / serves the main angular index page and assets as expected.
Problem
What I need is for paths in this context (like /base or /shop/60) to be handled by Angular, so redirected to index.
As a simple test based on this answer, I have tried this single rule in WEB-INF/undertow-handlers.conf:
exists(%{RELATIVE_PATH}) -> done
path-prefix('/') -> rewrite('/');
but it seems to do nothing at all as I get a 404.
I've tried -> rewrite('/index.html') and -> rewrite('/index.jsp') to no avail.
The file is clearly being read, though, because if I put garbage into the file it throws an exception in the server log.
UT000045: Error parsing predicated handler string Invalid expression:
# path('/base') -> rewrite('/')
What have I missed?
I'm quite a neophyte to JBoss and the whole Undertow ecosystem; please let me know what other details I should add to this question.
Curiosity
With request dumper activated, I see a single initial request to / made by JBoss (User-Agent=Java/1.8.0_181) immediately after booting, but when I navigate to / from a browser, I don't see that request in the dump. But I do see the failed request for /base. Why is that?
I'm serving an Angular 8 SPA from /gui (like you my API is in another servlet). All I had to do with Undertow 2.0.15 (EAP 7.2) was add a WEB-INF/undertow-handlers.conf with:
path-prefix['gui'] and not file(%U) -> rewrite('/gui/index.html')
I would guess that if your SPA is served at / you could just:
not file(%U) -> rewrite('/index.html')
I had two problems:
I was missing rules, and I has misunderstood the function of path-prefix (which matches on complete and non-terminal path segments, rather than acting like a regex ^(group)).
My final, working undertow-handlers.conf looks like this:
regex('/login(.*)') -> done;
path-prefix('/assets') -> done;
regex('(.*).js') -> done;
regex('(.*).map') -> done;
regex('(.*).svg') -> done;
regex('(.*).png') -> done;
regex('(.*).eot') -> done;
regex('(.*).woff2') -> done;
regex('(.*).html') -> done;
path('/') -> rewrite('/index.html');
path('/base') -> rewrite('index.html');
path-prefix('/shop') -> rewrite('index.html');
...and all my other angular routes
Note that /base is a terminal path segment, and matches with path, whereas /shop/60 takes an additional path parameter, so requires path-prefex.
For whatever reason, the solution proposed in the linked question above, simply capturing it all with path-prefix('/') didn't work in my case.
Possibly-heplful side-note: we have a REST server that serves from /RestService/ in another servlet context, so no rules were needed to allow that to continue to work.
Additionally, I was using webpack's development proxy server through ng hmr, and needed to add byPassProxy rules equivalent to the undertow rules, as well.
I'm happy for improvements on this: please don't hesitate to comment or add another answer.

Wildfly Server local server debug panel shows error "http connector is not enabled for server profile"

I setup a local JBoss/Wildfly server launch configuraiton in Intellij Idea. When I attempt to start the server, the configuration panel pops up and shows following error.
Error: HTTP connector is not enabled for server profile
I could not find anything in the Idea help what this means and how to fix it. The server is a keycloak distro but is just plain wildfly 10 with an extra subsystem.
Has anyone seen this before and knows how to fix the error?
I can't reproduce this with fresh installation of keycloak 3.2.1 from here
IDEA looks for the 2 following xpath's searching for a HTTP connector settings:
"/ns:server/ns:profile/*[local-name()='subsystem']/*[local-name()='server']/*[local-name()='http-listener'][#*[local-name()='socket-binding' and .='http']]",
"/ns:server/ns:profile/*[local-name()='subsystem']/*[local-name()='connector'][#*[local-name()='socket-binding' and .='http']]"};
For me playing with the fresh keycloak distribution the first xpath hits at the following markup:
<subsystem xmlns="urn:jboss:domain:undertow:3.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
Please check your configuration around this place.
If this does not help, please attach your standalone.xml or at least the relevant part of it.
In my case changing of 'JRE' from 'Default' to explicit one (Even though it was the same as it was in parentheses in the default version) solved the problem.

Disable X-Powered-By in JBOSS AS 7.1.1 Final

I want to remove Server Apache-Coyote/1.1 and X-Powered-By JSP/2.2 from response header in Jboss AS 7.1.1 final. I tried a lot but could not found any thing.
What i tried is
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
<configuration>
<static-resources listings="true"/>
<jsp-configuration development="true" x-powered-by="false" display-source-fragment="false"/>
</configuration>
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="false">
<alias name="localhost"/>
<alias name="example.com"/>
</virtual-server>
</subsystem>
but this is not working, Still same response headers are comming.
Please help me.
To modify Server header you can use the system property:
org.apache.coyote.http11.Http11Protocol.SERVER
Eg:
<system-properties>
<property name="org.apache.coyote.http11.Http11Protocol.SERVER" value="myserver"/>
</system-properties>
About X-Powered-By header there is a known issue in 7.1.1 that jsp-configuration element is not properly processed by the server and as such none of the settings configured are applied. See jsp configuration is ignored
It was fixed in version 7.1.2, you can download and compile this version, or even better upgrade to WildFly 8.x

Multiple Tomcat instances, starting one kills the other

I have 2 different java applications running in two Tomcat instances (Ubuntu OS, Tomcat 7.0.57). For my Tomcat configuration, I follow instructions provided by this video, but as far as I saw, it is a very standard way to do it.
Running each application separately is working fine, but as soon as I try to run both at same time, the first started one becomes unavailable (HTTP 503 error). Tomcat instance logs do not provide any information about any kind of shutdown, keeping the last "INFO: Server startup in xxx ms". It seems the first tomcat process is simply killed. If I re-start that first application, then the same scenario applies to the second app.
All troubleshooting information I could find talk about port issues. I double checked my port numbers, they are different:
app-1: conf/server.xml:
<Server port="8105" shutdown="SHUTDOWN">
<Connector port="8180" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8143" />
<Connector port="8109" protocol="AJP/1.3" redirectPort="8143" />
...
</Server>
app-2: conf/server.xml:
<Server port="8205" shutdown="SHUTDOWN">
<Connector port="8280" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8243" />
<Connector port="8209" protocol="AJP/1.3" redirectPort="8243" />
...
</Server>
app1.sh
export CATALINA_HOME=/home/tomcat/apache-tomcat-7
export CATALINA_BASE=/home/tomcat/app-1
cd $CATALINA_HOME/bin
./startup.sh
app2.sh
export CATALINA_HOME=/home/tomcat/apache-tomcat-7
export CATALINA_BASE=/home/tomcat/app-2
cd $CATALINA_HOME/bin
./startup.sh
Any idea on what can happen, or how I can get any logs to dig this?
My server was hosted on a EC2 t1.micro instance, with 600MB memory.
I finally decide to update it to an instance with more memory and the problem disappear.

How to Change SSL Version for HTTPS Connections in JBoss EAP 6.1

I have a simple HTTPS connector configured on my JBoss EAP 6.1 server for SSL connections to a bunch of RESTful web services I am working on. I am not sure if JBoss EAP 6.1 comes with TLS 1.2 (or SSL 3.2, since I believe TLS is really just later versions of SSL), but I want to use that version of TLS or later.
What is the default SSL version of JBoss EAP 6.1 , if my standalone.xml file tags that handle this connector look like this? :
<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true">
<ssl name="https" key-alias="localhost" password="something" certificate-key-file="${jboss.server.config.dir}/localhost.jks"/>
</connector>
There is no SSL version information given in the standalone.xml entry above, as you can see, so I've no idea.
I have read on the JBoss community web site that you can add something like sslProtocol="TLS" in the tag, and protocol="TLSv2" in the tag, but is that really all there is to it?
i.e.
<connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" secure="true" sslProtocol="TLS">
<ssl name="https" key-alias="localhost" password="something" certificate-key-file="${jboss.server.config.dir}/localhost.jks" protocol="TLSv2" />
</connector>
Will the above work, and if so, how can I tell?
According to redhat documentation for EAP 6.1
protocol
The version of the SSL protocol to use. Supported values include SLv2, SSLv3, >TLSv1, SSLv2+SSLv3, and ALL. The default is ALL
Adding sslProtocol="TLS" and protocol="TLSv2" should work fine. Not to sound condescending, but the easiest way to see if it works is by testing it.
If this question did get moved to another SE site could you please provide the link?