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

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

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>

Change Jetty configuration from code to XML

I have embedded Jetty into my application. My requirements was simple: use HTTP/2, disable some crypto protocols and ciphers, and use my own handler to some requests. I did it from my code. It works very well. But now I have client who want to use more HTTP features available in Jetty like Basic Authentication, or redirection. I don't want to add more and more HTTP configuration to my application, so I returned to idea of Jetty XML config file.
For debug/monitoring purposes I use Server.dump() and I can see enabled/disabled ciphers, or my handler. Is it possible to create XML config file based on working Jetty or based on Jetty Server.dump()?
You don't need to change your current code (much) to start using XML to allow modifications of your server.
Consider the XmlEnhancedServer example:
Available at https://github.com/jetty-project/embedded-jetty-cookbook
package org.eclipse.jetty.cookbook;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
/**
* This is a Server setup in a default way, but is can be enhanced by providing
* (0 to n) Jetty XML file arguments on the command line.
* <p>
* Run without a command line argument and pay attention to the contextPath for the
* default Context. (It should be {#code "/"})
* <br/>
* Now run with {#code src/test/resources/xml-enhanced/adjust-default-contextpath.xml} and see
* that the context path is now {#code "/foobar"}
* </p>
* <p>
* Run with {#code src/test/resources/xml-enhanced/configure-http.xml} and you will be
* adjusting the {#link HttpConfiguration} parameters in use.
* </p>
* <p>
* Run with {#code src/test/resources/xml-enhanced/add-rewrites.xml} and you will be
* adjusting adding rewrite rules to the existing handler tree.
* <br/>
* Request {#code http://localhost:8080/bar/blah} and you will receive a 302 redirect
* to {#code http://localhost:8080/foo}
* </p>
* <p>
* Run with {#code src/test/resources/xml-enhanced/add-https.xml} and you will be
* adding an HTTPS connector with configuration.
* </p>
*/
public class XmlEnhancedServer
{
public static void main(String[] args) throws Exception
{
Server server = new Server();
HttpConfiguration httpConfig = new HttpConfiguration();
ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
httpConnector.setPort(8080);
server.addConnector(httpConnector);
// Figure out what path to serve content from
ClassLoader cl = DefaultServletFileServer.class.getClassLoader();
// We look for a file, as ClassLoader.getResource() is not
// designed to look for directories (we resolve the directory later)
URL f = cl.getResource("static-root/hello.html");
if (f == null)
{
throw new RuntimeException("Unable to find resource directory");
}
// Resolve file to directory
URI webRootUri = f.toURI().resolve("./").normalize();
System.err.println("WebRoot is " + webRootUri);
HandlerList handlers = new HandlerList();
ContextHandlerCollection contexts = new ContextHandlerCollection();
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setBaseResource(Resource.newResource(webRootUri));
contexts.addHandler(context);
ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
holderPwd.setInitParameter("dirAllowed", "true");
context.addServlet(holderPwd, "/");
handlers.addHandler(contexts);
DefaultHandler defaultHandler = new DefaultHandler();
handlers.addHandler(defaultHandler); // always last in handler list
server.setHandler(handlers);
// apply extra XML (provided on command line)
if (args.length > 0)
{
// Map some well known objects via an id that can be referenced in the XMLs
Map<String, Object> idMap = new HashMap<>();
idMap.put("Server", server);
idMap.put("httpConfig", httpConfig);
idMap.put("httpConnector", httpConnector);
idMap.put("Handlers", handlers);
idMap.put("Contexts", contexts);
idMap.put("Context", context);
idMap.put("DefaultHandler", defaultHandler);
// Map some well known properties
Map<String,String> globalProps = new HashMap<>();
URI resourcesUriBase = webRootUri.resolve("..");
System.err.println("ResourcesUriBase is " + resourcesUriBase);
globalProps.put("resources.location", resourcesUriBase.toASCIIString());
List<Object> configuredObjects = new ArrayList<>();
XmlConfiguration lastConfig = null;
for (String xml : args)
{
URL url = new File(xml).toURI().toURL();
System.err.println("Applying XML: " + url);
XmlConfiguration configuration = new XmlConfiguration(url);
if (lastConfig != null)
configuration.getIdMap().putAll(lastConfig.getIdMap());
configuration.getProperties().putAll(globalProps);
configuration.getIdMap().putAll(idMap);
idMap.putAll(configuration.getIdMap());
configuredObjects.add(configuration.configure());
lastConfig = configuration;
}
// Dump what was configured
for(Object configuredObject: configuredObjects)
{
System.err.printf("Configured (%s)%n", configuredObject.getClass().getName());
}
// Dump the resulting idMap
idMap.forEach((id, obj) -> System.err.printf("IdMap[%s]: (%s)%n", id, obj.getClass().getName()));
}
server.setDumpAfterStart(true);
server.start();
server.join();
}
}
This will take an existing Embedded Jetty Server, tag specific components inside and ID Map, along with a few properties, and a user provided list of XML files to configure this server.
Here's a few of the XML that can be used in this kind of setup.
adjust-default-contextpath.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Context" class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="contextPath">/foobar</Set>
</Configure>
configure-http.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort">8443</Set>
<Set name="outputBufferSize">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="sendServerVersion">true</Set>
</Configure>
add-rewrites.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="insertHandler">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
<Set name="rewriteRequestURI">true</Set>
<Set name="rewritePathInfo">false</Set>
<Set name="originalPathAttribute">requestedPath</Set>
<Set name="dispatcherTypes">
<Array type="javax.servlet.DispatcherType">
<Item>
<Call class="javax.servlet.DispatcherType" name="valueOf">
<Arg>REQUEST</Arg>
</Call>
</Item>
<Item>
<Call class="javax.servlet.DispatcherType" name="valueOf">
<Arg>ASYNC</Arg>
</Call>
</Item>
</Array>
</Set>
<Get name="ruleContainer">
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
<Set name="pattern">/bar/*</Set>
<Set name="location">/foo</Set>
</New>
</Arg>
</Call>
</Get>
</New>
</Arg>
</Call>
</Configure>
add-https.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStorePath"><Property name="resources.location"/>/ssl/keystore</Set>
<Set name="KeyStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
<Set name="KeyStoreType">JKS</Set>
<Set name="KeyManagerPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
<Set name="TrustStorePath"><Property name="resources.location"/>/ssl/keystore</Set>
<Set name="RenegotiationAllowed">false</Set>
</New>
<New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Arg><Ref refid="httpConfig"/></Arg>
<Call name="addCustomizer">
<Arg>
<New class="org.eclipse.jetty.server.SecureRequestCustomizer">
<Arg name="sniHostCheck" type="boolean">true</Arg>
<Arg name="stsMaxAgeSeconds" type="int">-1</Arg>
<Arg name="stsIncludeSubdomains" type="boolean">false</Arg>
</New>
</Arg>
</Call>
</New>
<Call name="addConnector">
<Arg>
<New id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="acceptors" type="int">-1</Arg>
<Arg name="selectors" type="int">-1</Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<!-- uncomment to support proxy protocol
<Item>
<New class="org.eclipse.jetty.server.ProxyConnectionFactory"/>
</Item>-->
</Array>
</Arg>
<Set name="port">8443</Set>
<Set name="idleTimeout">30000</Set>
<Set name="soLingerTime">-1</Set>
<Set name="acceptorPriorityDelta">0</Set>
<Set name="acceptQueueSize">0</Set>
<Get name="SelectorManager">
<Set name="connectTimeout">15000</Set>
</Get>
<Call name="addIfAbsentConnectionFactory">
<Arg>
<New class="org.eclipse.jetty.server.SslConnectionFactory">
<Arg name="next">http/1.1</Arg>
<Arg name="sslContextFactory"><Ref refid="sslContextFactory"/></Arg>
</New>
</Arg>
</Call>
<Call name="addConnectionFactory">
<Arg>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="sslHttpConfig" /></Arg>
<Arg name="compliance">
<Call class="org.eclipse.jetty.http.HttpCompliance" name="valueOf">
<Arg>RFC7230</Arg>
</Call>
</Arg>
</New>
</Arg>
</Call>
</New>
</Arg>
</Call>
</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

Jetty error - java.lang.IllegalStateException: No object for id=Contexts

I want to run two webapps(different ports) on two parallel jetty instances.
I'm using jetty7.1.6 and following the instructions here.
My jetty-cp.xml(customized jetty.xml) contains this section:
<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>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
Now when I run one jetty instance from command line(java -Djetty.home=/opt/jetty -jar /opt/jetty/start.jar etc/jetty-cp.xml), I get the following error :
2014-01-02 18:03:47.649:WARN::Config error at <Call name="addBean"><Arg>| <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager"><Set name="contexts">| <Ref id="Contexts"/>| </Set><Call name="setContextAttribute"><Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg><Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg></Call><Call name="addAppProvider"><Arg>| <New class="org.eclipse.jetty.deploy.providers.ContextProvider"><Set name="monitoredDir"><Property name="jetty.home" default="."/>/contexts</Set><Set name="scanInterval">5</Set></New>| </Arg></Call><Call name="addAppProvider"><Arg>| <New class="org.eclipse.jetty.deploy.providers.WebAppProvider"><Set name="monitoredDir"><Property name="jetty.home" default="."/>/webapps</Set><Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set><Set name="scanInterval">5</Set><Set name="contextXmlDir"><Property name="jetty.home" default="."/>/contexts</Set></New>| </Arg></Call></New>| </Arg></Call> java.lang.IllegalStateException: No object for id=Contexts
2014-01-02 18:03:47.650:WARN::EXCEPTION
java.lang.IllegalStateException: No object for id=Contexts
at org.eclipse.jetty.xml.XmlConfiguration.refObj(XmlConfiguration.java:676)
at org.eclipse.jetty.xml.XmlConfiguration.itemValue(XmlConfiguration.java:941)
This section of config is present in /opt/jetty/etc/jetty-deploy.xml file.
What am I doing wrong? I already specified the object with id=Context in jetty-cp.xml file which I specified in command line. Why is the section in jetty-deploy.xml unable to find it?
start.ini had jetty-deploy.xml uncommented which caused *<Ref id="Contexts"/>* to be parsed before its definition in jetty-cp.xml.
Basically, files mentioned in start.ini get loaded even before the jetty-cp.xml I mentioned on command line. This needs to be kept in mind.

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