EXIT_ON_INIT_FAILURE in Jetty-9.3.12 standalone server - java

Is there any equivalent of EXIT_ON_INIT_FAILURE from Tomcat in Jetty? I have war which throws IllegalArgumentException during start up (in Spring Bean initialization), but Jetty only prints WARN from DeploymentManager (Unable to reach node goal: started) and started normally (of course with no context). I have tried options:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">{context_path}</Set>
<Set name="throwUnavailableOnStartupException">true</Set>
<Set name="war">{war_path}</Set>
<Set name="maxFormContentSize">10485760</Set>
</Configure>
but with no results.
Logs from Jetty:
2017-03-16 21:45:05.798:WARN:oejd.DeploymentManager:main: Unable to reach node goal: started
java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'intranetClient' defined in class path resource
{...stacktrace...}
2017-03-16 21:45:05.836:INFO:oejs.AbstractConnector:main: Started httpConnector#48140564{HTTP/1.1,[http/1.1]}{0.0.0.0:5070}
2017-03-16 21:45:05.840:INFO:oejs.AbstractConnector:main: Started httpMngConnector#4439f31e{HTTP/1.1,[http/1.1]}{0.0.0.0:5075}
2017-03-16 21:45:05.841:INFO:oejs.Server:main: Started #40994ms
Thanks in advance for any advice how it should be configured.

Your DTD is outdated.
Use:
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
Get rid of the block ...
<Set name="servletHandler">
<New class="org.eclipse.jetty.servlet.ServletHandler">
<Set name="startWithUnavailable">false</Set>
</New>
</Set>
The rest is all that's needed in your ${jetty.base}/webapps/${context}.xml file to trigger the failure.

Related

Deploy Static content in jetty

I am trying deploy the app static in jetty, but using xml config file, because i am using virtual hosts.
I create this file xml for deploy:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mail</Set>
<!--<Call name="setInitParameter">
<Arg>org.eclipse.jetty.servlet.Default.useFileMappedBuffer</Arg>
<Arg>false</Arg>
</Call> -->
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="resourceBase">/ccmail</Set>
<Set name="directoriesListed">true</Set>
</New>
</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>apps.cairunet.ad.br</Item>
</Array>
</Set>
</Configure>
The name for my folder app is ccmail. Is located in webapps/ccmail
I already try pass to path for:
<Set name="resourceBase">/ccmail</Set>
<Set name="resourceBase">ccmail</Set>
<Set name="resourceBase">./ccmail</Set>
<Set name="resourceBase">webapps/ccmail</Set>
<Set name="resourceBase">/webapps/ccmail</Set>
Anyone this paths not works for me.
Jetty launch this error:
2019-02-25 09:36:46.422:WARN:oejs.ServletContextHandler:main:
ServletContextHandler.setHandler should not be called dire ctly. Use
insertHandler or setSessionHandler etc. 2019-02-25
09:36:46.484:WARN:oejw.WebInfConfiguration:main: Can't generate
resourceBase as part of webapp tmp dir name:
java.lang.IllegalStateException: No resourceBase or war set for
context 2019-02-25 09:36:46.500:WARN:oejw.WebAppContext:main: Failed
startup of context o.e.j.w.WebAppContext#7d0587f1{/mail,nul
l,UNAVAILABLE,apps.cairunet.ad.br} java.lang.IllegalStateException: No
resourceBase or war set for context
at org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:577)
at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:152)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:506)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:544)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:46)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:192)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:505)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:151)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:453)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:579)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:240)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
at org.eclipse.jetty.server.Server.start(Server.java:415)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:382)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1572)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1512)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1511)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:220)
at org.eclipse.jetty.start.Main.start(Main.java:490)
at org.eclipse.jetty.start.Main.main(Main.java:77) 2019-02-25 09:36:46.578:INFO:oejs.AbstractConnector:main: Started
ServerConnector#27808f31{HTTP/1.1,[http/1.1]}{0.0.0.0: 8080}
2019-02-25 09:36:46.594:INFO:oejs.Server:main: Started #2970ms
Note: be careful with your DOCTYPE, what you have declared is from Jetty 7.x thru Jetty 8.x, and is not correct for Jetty 9.x
Don't mix ResourceHandler and WebAppContext / ServletContextHandler.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mail</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>apps.cairunet.ad.br</Item>
</Array>
</Set>
</Configure>
The most basic support is to not reference /ccmail in your <Configure>.
The fact that it exists as ${jetty.base}/webapps/ccmail/ is enough, that will deploy /ccmail as a static resource base for you.
BUT if you want to combine static resources with virtual hosts, then you can either use a WebAppContext with an alternate base, or a new ResourceHandler.
Example of alternate bases:
Serving static files from alternate path in embedded Jetty
Example of ResourceHandler usage:
https://www.eclipse.org/jetty/documentation/current/static-content-deployment.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/ccmail</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="resourceBase">/fully/qualified/path/to/my/jetty.base/webapps/ccmail</Set>
<Set name="directoriesListed">true</Set>
</New>
</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>apps.cairunet.ad.br</Item>
</Array>
</Set>
</Configure>

How to set Jetty Request Log to default Timezone using XML

I am not able to make Jetty Request-log log requests with the local time-zone time using the following code,
<Set name="LogTimeZone" type="java.lang.String">
<Get class="java.util.TimeZone" name="default">
<Get name="ID"/>
</Get>
</Set>
it defaults to GMT. The setLogTimeZone() (http://download.eclipse.org/jetty/9.3.9.v20160517/apidocs/org/eclipse/jetty/server/AbstractNCSARequestLog.html#setLogTimeZone-java.lang.String-) accepts a string argument and therefore should ideally work. But, it doesn't! Although, when providing the required String directly it works just fine,
<Set name="LogTimeZone">Europe/London</Set>
the jetty log(std error) seems to be working fine. Is this a known bug?
Jetty Version used : 9.1.1
Take the result of getID() out of the TimeZone.getDefault() into an xml id attribute, then reference it later in the <Set> call using a <Ref> element.
Example of how this works in Jetty XML:
foo.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="foo" class="java.lang.Object">
<Get class="java.util.TimeZone" name="default">
<Get id="defaultTimeZone" name="ID"/>
</Get>
<Get id="sysout" class="java.lang.System" name="out">
<Call name="println">
<Arg>
<Ref refid="defaultTimeZone"/>
</Arg>
</Call>
</Get>
</Configure>
Testing it on the command line ...
$ cd /path/to/jetty-dist-9.3.9.v20160517/
$ java -cp lib/jetty-util-9.3.9.v20160517.jar:lib/jetty-xml-9.3.9.v20160517.jar \
org.eclipse.jetty.xml.XmlConfiguration foo.xml
2016-07-13 17:16:25.447:INFO::main: Logging initialized #121ms
America/Phoenix

How to change timezone for Jetty request log *filenames*?

I have configured request logs as seen below - in jetty.xml. However, the LogTimeZone which is set to GMT-5 below will only change the timezone of the log entries in request.yyyy_mm_dd.log but the filename of request.yyyy_mm_dd.log doesn't reflect "GMT-5". As an example, with the below setting when I started Jetty (01/28/2014), it generated log files with file names - request.2014_56_28.log. Not sure where "56" came from for the file name "request.2014_56_28.log" Any suggestion would be of big help!!
<Ref id="Handlers">
<Call name="addHandler">
<Arg>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler">
<Set name="requestLog">
<New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
<Set name="filename">
logs/request.yyyy_mm_dd.log
</Set>
<Set name="filenameDateFormat">yyyy_mm_dd</Set>
<Set name="retainDays">365</Set>
<Set name="append">true</Set>
<Set name="extended">false</Set>
<Set name="logCookies">false</Set>
<Set name="LogTimeZone">GMT-5</Set>
</New>
</Set>
</New>
</Arg>
</Call>
</Ref>
What you need is a TimeZone string that will identified by your system. Which means:
TimeZone identifier does not use GMT offset notation
TimeZone identifier is not 3-letters (see javadoc section about "Three-letter time zone IDs")
TimeZone identifier is long form.
References
Getting jetty to log with the correct timezone
java.util.TimeZone

Jetty 7 - Disable directory list at root folder /

I have a lot of production servers running RMI application in each one, and more 4 Java webapps, eg:
Server A:
RMI app by JNLP file;
webapp_1 (connected by RMI with local RMI app);
webapp_2 (connected by RMI with local RMI app);
webapp_3 (connected by RMI with local RMI app);
webapp_4 (connected by RMI with local RMI app);
Server B:
...the same..OK
All users access this servers directly on 8080 port (direct to Jetty) in a default context, eg 'main-area', where it can access by some html links all apps (RMI app, webapp_1, webapp_2, etc.).
When some user access the '/' page, eg:
www.foo.com:8080/
main-area/
webapp_1/
webapp_2/
webapp_3/
...
Jetty returns a list with all applications (just like directory list of Apache).
Is there some way to block it, or redirect to 'main-area' context ?
The list of webapp contexts that do not match "/" is presented to you as part of the responsibility of org.eclipse.jetty.server.handler.DefaultHandler
The DefaultHandler is enabled by default, to remain in conformance to the Servlet Spec.
Disabling DefaultHandler:
If you just want a simple 404, with no information presented by the DefaultHandler, then just comment it out in the ${jetty.home}/etc/jetty.xml
<!-- =========================================================== -->
<!-- Set handler Collection Structure -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<!-- Disable the DefaultHandler to avoid listing of non-matching contexts
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
-->
</Array>
</Set>
</New>
</Set>
Presenting Static Content for "/" (ROOT) Context:
If you want the root context "/" (ROOT) to present something else, then create a ${jetty.home}/webapps/ROOT directory and put an index.html file in it.
[jetty-distribution-7.6.13.v20130916]$ cat webapps/ROOT/index.html
<h1>This is ROOT</h1>
This will deploy a static content webapp where you can put any content you want to in there, images, css, etc.
Automatically Redirecting "/" (ROOT) to another path:
Note: this will not work at the same time as the above ${jetty.home}/webapps/ROOT option, his this option, or that option, but not both.
If you want Jetty to redirect "/" automatically to another URL then use the rewrite handler.
Make sure you have the rewrite OPTION enabled, and include a set of rewrite rules xml
[jetty-distribution-7.6.13.v20130916]$ grep rewrite start.ini
OPTIONS=Server,jsp,jmx,resources,websocket,ext,rewrite
etc/jetty-rewrite.xml
Next, you'll want to define your rewrite rules ...
Contents of ${jetty.home}/etc/jetty-rewrite.xml to redirect accesses from "/" to "/test/"
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Get id="oldhandler" name="handler"/>
<Set name="handler">
<New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
<Set name="handler"><Ref id="oldhandler"/></Set>
<Set name="rewriteRequestURI">true</Set>
<Set name="rewritePathInfo">false</Set>
<Set name="originalPathAttribute">requestedPath</Set>
<!-- redirect from the welcome page to a specific page -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RedirectRegexRule">
<Set name="regex">^/$</Set>
<Set name="replacement">/test/</Set>
</New>
</Arg>
</Call>
</New>
</Set>
</Configure>
Create an index.html file for that location.
This will be served so the list does not need to be generated.
You can then put a simple redirect in there, along with a normal link if the browser does not respect redirects.
Thanks to Thorbjørn Ravn Andersen by solution:
I created a basic Dynamic Web Application with a single index.jsp with JSP HTML/JS redirect inside:
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=bar/index.jsp">
<script type="text/javascript">
window.location.href = "bar/index.jsp"
</script>
<title>Page Redirection</title>
</head>
<body>
If you are not redirected automatically, follow the <a href='bar/index.jsp'>main area</a>
</body>
</html>
I deployed as 'ROOT.war' and I configured a 'root.xml' in '...jetty/contexts/' with:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/ROOT.war</Set>
</Configure>

Mule/Jetty Setup

I have a working Mule application that I want to setup Jetty on to respond to http requests. The following config:
<jetty:endpoint address="http://localhost:8080"
name="jettyEndpoint"
host="localhost"
port="8080" path="/"
synchronous="true" />
<service name="jettyUMO">
<inbound>
<jetty:inbound-endpoint ref="jettyEndpoint" />
</inbound>
<test:component appendString="Received" />
</service>
...works when I start the application, and point browser of choice to http://localhost:8080 - all that gets displayed is "Received", per the test:component.
What I want to do is update this so that instead of seeing "Received", I want to go to where I defined an index.html file. My assumption is that I have to change the test:component out for an outbound endpoint - is this correct? Where would I specify the path (relative or absolute)?
I had to add a jetty:connector instance:
<jetty:connector name="httpConnector"
configFile="conf/jettyConfig.xml"
useContinuations="true" />
Here's the contents of the jettyConfig.xml because the simple example has errors:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.mortbay.jetty.Server">
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="port">8080</Set>
</New>
</Arg>
</Call>
<Set name="handler">
<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.mortbay.jetty.Handler">
<Item>
<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.WebAppDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="webAppDir">path/webapps</Set>
</New>
</Arg>
</Call>
</Configure>
This did not work for me.
> [04-22 17:25:22] WARN log [main]:
> failed SelectChannelConnector#0.0.0.0:8080
> java.net.BindException: Address already in use
> at sun.nio.ch.Net.bind(Native Method)
I think, what happens is that one instance is being created on port defined in jettyConfig and then another through Mule. Changing the port in jettyConfig yields two identically behaving instances on two different ports.
The simplest solution is to remove the addConnector Call from jettyConfig.xml and let Mule assign the port.
It is also not needed to specify host and port on the endpoint. This suffices:
<jetty:endpoint address="http://localhost:8080" name="serverEndpoint" path="services/Foo" synchronous="false" />

Categories

Resources