I have written a JAX-RS REST-API, that fetches rows from Oracle.
For this I have used JNDI since I am using Jetty. But on deploying the WAR file I am getting the following error:
Caused by:
java.lang.IllegalStateException: Nothing to bind for name jdbc/replaydev
at org.eclipse.jetty.plus.webapp.PlusDescriptorProcessor.bindEntry(PlusDescriptorProcessor.java:914)
My web.xml has the following entry:
<resource-ref>
<res-ref-name>jdbc/replaydev</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
WEB-INF/jetty-env.xml has following entries:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid='wac'/></Arg>
<Arg>jdbc/replaydev</Arg>
<Arg>
<New class="oracle.jdbc.pool.OracleDataSource">
<Set name="URL">jdbc:oracle:thin://#MY.ORACLE.SERVER:1555/JOBCTL</Set>
<Set name="User">XYZ</Set>
<Set name="Password">rockOn</Set>
<Set name="connectionCachingEnabled">true</Set>
</New>
</Arg>
</New>
</Configure>
And my Java code has the following:
Context initContext = new InitialContext();
ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/replaydev");
con = ds.getConnection();
Class.forName("oracle.jdbc.OracleDriver");
POM.xml has following dependencies added:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.11.v20150529</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.2.11.v20150529</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-plus</artifactId>
<version>9.2.11.v20150529</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jndi</artifactId>
<version>9.2.11.v20150529</version>
</dependency>
I even tried adding id tags in web.xml entry like: <resource-ref id="replaydev">....</resource-ref> for jetty-env.xml <New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource">. Its not working either.
Am I missing something??
The configuration looks fine. I guess you are using maven. Make sure you are deploying the version of jetty.xml with those modifications. e.g: mvn clean install
Thanks #voodoo14 and #joakim.
I found the soultion. I actually removed the dependencies shown above in the POM.xml
This is because I already had a standalone jetty v9 running. And I believe that the dependencies mentioned above are creating one more jetty within.
So I removed the dependencies and things worked.
Our java application presently uses SSL for communication between client and server using https. Customer requested if an upgrade can be done to TLS and if they can use both TLS and SSL at different locations. I cant understand clearly how to answer their questions or how to proceed.
jetty-ssl.xml file is as follows :
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<!-- =============================================================== -->
<!-- Configure SSL for the Jetty Server -->
<!-- this configuration file should be used in combination with -->
<!-- other configuration files. e.g. -->
<!-- java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml -->
<!-- =============================================================== -->
<Configure id="Server" class="org.mortbay.jetty.Server">
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.security.SslSocketConnector">
<Set name="Port">8443</Set>
<Set name="maxIdleTime">30000</Set>
<Set name="handshakeTimeout">2000</Set>
<Set name="keystore">/xservices-config/keystore</Set>
<Set name="password">password</Set>
<Set name="keyPassword">password</Set>
<Set name="truststore">/keystore</Set>
<Set name="trustPassword">password</Set>
<Set name="handshakeTimeout">2000</Set>
<!-- Set name="ThreadPool">
<New class="org.mortbay.thread.BoundedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">250</Set>
</New>
</Set -->
</New>
</Arg>
</Call>
</Configure>
Please let me know how to implement it.
Are you sure you need to "enable" this? I just went back at the jetty documentation and figured, as long as you don't exclude a protocol, you're allowing them all. Check your installation either with a local tool (sslscan, nmap, etc.) or a web application (e.g. from Qualys or COMODO).
If you find with the above analysis that you don't have the versions running, you could use an Apache webserver as HTTPS end-point and mod_proxy the content to jetty.
If that above is your SSL configuration for jetty, I strongly recommend you to harden it! Exclude legacy SSL protocols (e.g. SSLv2) and weak ciphers! As others have mentioned SSLv3 is actually legacy as well and not recommended anymore. In your position, I would get back to your client and check why he wants to have SSLv3 running. Unless he isn't expecting connections from dead old systems (e.g. Win XP with IE), there is not much of a reason to have SSLv3 running. However, if he does not know who is connecting to his page with what browsers, have a look at the logs. If the logs don't show an indication of the web browser used to connect to the application, I strongly recommend to enable it, run it for a period and then take a decision.
Jetty default port is 8080, but I want to change to default port to some other port (9999).
I read a few tutorials and they said almost all of configuration information is by default maintained in file jetty.xml, this file is located under $JETTY_HOME/etc/. Then, change property jetty.port to 9999. However, when I opened up that file, I couldn't find jetty.port property inside the jetty.xml. I'm currently using Jetty-9.2.1 and the port is at 8080.
I found jetty.port property under jetty-http.xml file. Even though I changed the port to 8090 in the jetty-http.xml file, jetty is still running at port 8080.
jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- =============================================================== -->
<!-- Documentation of this file format can be found at: -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default -->
<!-- configuration files. -->
<!-- -->
<!-- For a description of the configuration mechanism, see the -->
<!-- output of: -->
<!-- java -jar start.jar -? -->
<!-- =============================================================== -->
<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server" -->
<!-- Other configuration files may also configure the "Server" -->
<!-- ID, in which case they are adding configuration to the same -->
<!-- instance. If other configuration have a different ID, they -->
<!-- will create and configure another instance of Jetty. -->
<!-- Consult the javadoc of o.e.j.server.Server for all -->
<!-- configuration that may be set here. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Configure the Server Thread Pool. -->
<!-- The server holds a common thread pool which is used by -->
<!-- default as the executor used by all connectors and servlet -->
<!-- dispatches. -->
<!-- -->
<!-- Configuring a fixed thread pool is vital to controlling the -->
<!-- maximal memory footprint of the server and is a key tuning -->
<!-- parameter for tuning. In an application that rarely blocks -->
<!-- then maximal threads may be close to the number of 5*CPUs. -->
<!-- In an application that frequently blocks, then maximal -->
<!-- threads should be set as high as possible given the memory -->
<!-- available. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<!-- uncomment to change type of threadpool
<Arg name="threadpool"><New id="threadpool" class="org.eclipse.jetty.util.thread.QueuedThreadPool"/></Arg>
-->
<Get name="ThreadPool">
<Set name="minThreads" type="int"><Property name="threads.min" default="10"/></Set>
<Set name="maxThreads" type="int"><Property name="threads.max" default="200"/></Set>
<Set name="idleTimeout" type="int"><Property name="threads.timeout" default="60000"/></Set>
<Set name="detailedDump">false</Set>
</Get>
<!-- =========================================================== -->
<!-- Add shared Scheduler instance -->
<!-- =========================================================== -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
</Arg>
</Call>
<!-- =========================================================== -->
<!-- Http Configuration. -->
<!-- This is a common configuration instance used by all -->
<!-- connectors that can carry HTTP semantics (HTTP, HTTPS, SPDY)-->
<!-- It configures the non wire protocol aspects of the HTTP -->
<!-- semantic. -->
<!-- -->
<!-- This configuration is only defined here and is used by -->
<!-- reference from the jetty-http.xml, jetty-https.xml and -->
<!-- jetty-spdy.xml configuration files which instantiate the -->
<!-- connectors. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.HttpConfiguration -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize"><Property name="jetty.output.buffer.size" default="32768" /></Set>
<Set name="requestHeaderSize"><Property name="jetty.request.header.size" default="8192" /></Set>
<Set name="responseHeaderSize"><Property name="jetty.response.header.size" default="8192" /></Set>
<Set name="sendServerVersion"><Property name="jetty.send.server.version" default="true" /></Set>
<Set name="sendDateHeader"><Property name="jetty.send.date.header" default="false" /></Set>
<Set name="headerCacheSize">512</Set>
<!-- Uncomment to enable handling of X-Forwarded- style headers
<Call name="addCustomizer">
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
</Call>
-->
</New>
<!-- =========================================================== -->
<!-- Set the default handler structure for the Server -->
<!-- A handler collection is used to pass received requests to -->
<!-- both the ContextHandlerCollection, which selects the next -->
<!-- handler by context path and virtual host, and the -->
<!-- DefaultHandler, which handles any requests not handled by -->
<!-- the context handlers. -->
<!-- Other handlers may be added to the "Handlers" collection, -->
<!-- for example the jetty-requestlog.xml file adds the -->
<!-- RequestLogHandler after the default handler -->
<!-- =========================================================== -->
<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>
<!-- =========================================================== -->
<!-- extra server options -->
<!-- =========================================================== -->
<Set name="stopAtShutdown">true</Set>
<Set name="stopTimeout">5000</Set>
<Set name="dumpAfterStart"><Property name="jetty.dump.start" default="false"/></Set>
<Set name="dumpBeforeStop"><Property name="jetty.dump.stop" default="false"/></Set>
</Configure>
jetty-http.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server" -->
<!-- by adding a HTTP connector. -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add a HTTP Connector. -->
<!-- Configure an o.e.j.server.ServerConnector with a single -->
<!-- HttpConnectionFactory instance using the common httpConfig -->
<!-- instance defined in jetty.xml -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.ServerConnector and -->
<!-- o.e.j.server.HttpConnectionFactory for all configuration -->
<!-- that may be set here. -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8090" /></Set>
<Set name="idleTimeout"><Property name="http.timeout" default="30000"/></Set>
<Set name="soLingerTime"><Property name="http.soLingerTime" default="-1"/></Set>
</New>
</Arg>
</Call>
</Configure>
I was also advised to use an integration test to configure Jetty to use other port. There's a integration-tests.properties file inside the project. Maybe a solution is to set jetty.port to 9999 inside this file?
integration-tests.properties:
host = localhost
port = 9999
does it work if you set the port when you start it from the command line like this:
java -jar start.jar -Djetty.port=9999
I did this in Jetty 9.x version.
You need to go to $JETTY_HOME/start.ini file and edit this setting jetty.port.
Lets say that you want to run jetty at 9090 port:
Please change jetty.port setting in $JETTY_HOME/start.ini from
jetty.port=8080
to
jetty.port=9090
Then start jetty using java -jar start.jar option.
Then jetty will be running at 9090 port than default 8080 port.
Then do curl -i -XGET "http://localhost:9090". That should give you 200 http status.
Thats it.
Update:
On Jetty 9.x, jetty.port has been deprecated and you can use jetty.http.port instead, as shown below:
$> cd $JETTY_HOME && java -jar start.jar -Djetty.http.port=8080
On jetty 9.2.3.v20140905 it`s need to write in /etc/default/jetty
# JETTY_ARGS
# The default arguments to pass to jetty.
# For example
JETTY_ARGS="jetty.port=8080 jetty.spdy.port=8443 jetty.secure.port=443"
but this change only http port. To change https port in jetty 9.2 create ini file $JETTY_HOME/start.d/https.ini
# Initialize module https
#
--module=https
## HTTPS Configuration
# HTTP port to listen on
https.port=8443
# HTTPS idle timeout in milliseconds
https.timeout=30000
# HTTPS Socket.soLingerTime in seconds. (-1 to disable)
# https.soLingerTime=-1
jetty 9.3 in /etc/default/jetty
# JETTY_ARGS
# The default arguments to pass to jetty.
# For example
JETTY_ARGS="jetty.http.port=8080 jetty.ssl.port=443"
or command line parameters -Djetty.http.port=8080 -Djetty.ssl.port=443
I changed the port successfully, you can try to edit jetty.port in the file located at $Jetty_home/start.d/http.ini.
You need to change the http port in the start.ini file because it will over-right jetty-http.xml config.Or just comment the line in start.ini and keep your config from jetty-http.xml.
In [jetty home]/start.ini
## HTTP port to listen on
#jetty.port=8080
Just for completeness on jetty 7 you can use this:
java -jar start.jar --module=http jetty.port=9080
If you are using eclipse you need to set the run configurations. When you install jetty in eclipse, the default port for jetty is 8080.
So you need to change it into an XML file. If the problem remains, you need to change it in eclipse run configurations.
I hope it works, as it worked for me.
For IntelliJ, this can be done similar to Magnus Lassi's command-line answer.
Run --> Edit Configurations --> Add "-Djetty.port=XXXX", e.g.:
jetty:run-war -Djetty.port=9999
For SSL port you can pass the param:
-Dssl.port=8445
It worked for me.
For a spring boot application, inside your application.properties file
add
server.port = preferred port number eg. 8082
IMAGE OF PORT CONFIGURATION
I changed the jetty.http.port property in jetty/start.ini and it worked for me!
For changing SSL port, you need to change jetty.ssl.port property in below directory:
📁$JETTY_HOME/etc
📄 jetty-ssl.xml
<Configure id="Server" class="org.eclipse.jetty.server.Server">
...
<Call name="addConnector">
<Arg>
<New id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
...
<Set name="port"><Property name="jetty.ssl.port" deprecated="ssl.port" default="8443" /></Set>
...
</New>
</Arg>
</Call>
...
</Configure>
On Jetty's main project page compatibility with JASPI (JASPIC/JSR 196) is mentioned.
However, the distribution of Jetty 8 does not seem to contain any classes related to JASPI. There's a jetty-security-8.1.8.v20121106.jar jar in [jetty home]/lib, but this one does not contain any of the JASPIC/JASPI types.
The documentation about JASPIC/JASPI on the Jetty wiki is only a placeholder and does not contain any information.
After some Googling I found JavaDocs on the Eclipse site and discovered there should be a jetty-jaspi-8.1.8.v20121106.jar somewhere. Those JavaDocs are included in the distribution as well. Finally, a jetty-jaspi repo appears at Github.
Obviously there is some amount of support available, but why are those classes seemingly not present in the Jetty distribution and where is the documentation on how to configure this? What am I missing?
This project (https://github.com/guofengzh/jaspi-on-jetty) is a working example of the JASPI API in jetty that uses geronimo-jaspi which in turn calls back to the jetty-jaspi modules for the authentication. Geronimo seems to be providing the configuration mechanism and jetty the authentication modules themselves in this example.
It seems as though you can select a form, digest or basic authentication methods. A quick test of the form based login has shown it appears to function.
The Jaspi authentication factory is setup in jetty-web.xml like so:
<Set name="securityHandler">
<New class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.plus.jaas.JAASLoginService">
<Set name="name">JAASRealm</Set>
<Set name="loginModuleName">jaas</Set>
</New>
</Set>
<Set name="authenticatorFactory">
<New class="org.eclipse.jetty.security.jaspi.JaspiAuthenticatorFactory" />
</Set>
</New>
</Set>
And the jaspi configuration file is referenced via a system property in the pom.xml file:
<systemProperty>
<name>org.apache.geronimo.jaspic.configurationFile</name>
<value>./conf/jaspi/form-test-jaspi-2.xml</value>
</systemProperty>
Additionally, the jaspi library you mentioned is added as a dependency in the pom, along with the geronimo jaspi implementation:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaspi</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.components</groupId>
<artifactId>geronimo-jaspi</artifactId>
<version>2.0.0</version>
</dependency>
I have also been unable to find documenation on the topic. It seems as though the jetty-jaspi module is not one of the standard start options, but could be added to the ${jetty.home/lib/ext} directory (see Jetty classloading).
I have used Jetty in the past but I have little experience with jWebSocket. I would like to add to my current program, which uses the Jetty libraries, and make it also support WebSocket connections though port 80. I have read it can be done but find little to no source or examples to read about it. Any help is appreciated.
I am currently working on the same thing, and so far I have found their task for this on Google Code:
http://code.google.com/p/jwebsocket/issues/detail?id=76
This was posted back in April of 2011:
"There's a separate project jWebSocketJetty available now in the Downloads / Nightly Build Section of jWebSocket.org now."
If you pull up the web.xml from that project, it looks like they've gotten their jwebsocket servlet working with jetty. I'll be looking into this more tomorrow.
You have to modify two configuration files to run jWebSocket on jetty using port 80.
1:- Modify your jWebSocket.xml and add jetty engine entry at top of engine section of xml.
<engines>
<engine>
<name>org.jwebsocket.jetty.JettyEngine</name>
.
.
</engine>
</engines>
You can delete all other engine entries.
2:- Modify jetty.xml. This file can be located at jWebSocketJetty\src\main\resources folder.
Modify first connector entry and set jetty.port property to 80.
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host">
<Property name="jetty.host" />
</Set>
<!-- Jetty default -->
<!--
<Set name="port">
<Property name="jetty.port" default="80"/>
</Set>
-->
<!-- jWebSocket default, can be changed to 80 -->
<!-- but consider to update jWebSocket.js accordingly! -->
<Set name="port">
<Property name="jetty.port" default="80"/>
</Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">443</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
<Set name="responseBufferSize">65536</Set>
</New>
</Arg>
</Call>
I don't know, because I haven't used it, but would their JettyServlet would work?