I have configured SSL for Solr using following tutorial (https://lucene.apache.org/solr/guide/6_6/enabling-ssl.html) and it is accepting HTTPS connections. I want to open a separate port for HTTP now so that Solr can receive HTTP and HTTPS requests at the same time.
AFAIS Solr does not support both HTTP and HTTPS at the same time. You can only use one of them at a time.
Reference:
Check comment by Shalin in below post
here
Check last comment by Shawn in below post
here
In Jetty.XML,
Uncomment the connector for HTTPS
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
<Arg>
<New class="org.eclipse.jetty.http.ssl.SslContextFactory">
<Set name="keyStore"><SystemProperty name="jetty.home" default="."/>/etc/solrtest.keystore</Set>
<Set name="keyStorePassword">secret</Set>
<Set name="needClientAuth"><SystemProperty name="jetty.ssl.clientAuth" default="false"/></Set>
</New>
</Arg>
<Set name="port"><SystemProperty name="jetty.ssl.port" default="8983"/></Set>
<Set name="maxIdleTime">30000</Set>
</New>
</Arg>
</Call>
Related
I'm trying to configure the connection pool 2 web applications using .xml context descriptor for 2 separate context paths and databases, but with the same logical code.
The problem is that when using JNDI to lookup the datasource, the resources are overridden when jetty loads the context, and the apps end up using the same database. Here is my configuration and code:
Configuration for MyApp1.xml:
<New id="myDataBase" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/myDataBase</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://host:3306/mydb</Set>
<Set name="User">...</Set>
<Set name="Password">...</Set>
</New>
</Arg>
</New>
Configuration for MyApp2.xml
<New id="myDataBase" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/myDataBase</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://host:3306/mydb-test2</Set>
<Set name="User">...</Set>
<Set name="Password">...</Set>
</New>
</Arg>
</New>
Code used by the apps:
public class MyDb {
...
static {
try {
datasource = (DataSource) new InitialContext().lookup("jdbc/myDataBase");
} catch (NamingException e) {
// ...
}
...
}
So, jetty loads context for MyApp1.xml, then MyApp2.xml. When I try to access the apps, they both use the same database: mydb-test2.
How can I properly resolve this problem?
EDIT:
I have tried adding the argument in the configuration but it is not working; it is strange that now the contexts both use the first configured database: mydb
This is the xml for each app:
<Configure id='wac1' class="org.eclipse.jetty.webapp.WebAppContext">
...
<New id="myDataBase" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid='wac1'/></Arg>
<Arg>jdbc/myDataBase</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://host:3306/mydb</Set>
<Set name="User">...</Set>
<Set name="Password">...</Set>
</New>
</Arg>
</New>
...
<Configure id='wac2' class="org.eclipse.jetty.webapp.WebAppContext">
...
<New id="myDataBase" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid='wac2'/></Arg>
<Arg>jdbc/myDataBase</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://host:3306/mydb-test2</Set>
<Set name="User">...</Set>
<Set name="Password">...</Set>
</New>
</Arg>
</New>
...
What am I missing? Do I have to change the code (way in which I make the lookup)?
I've tried
datasource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/myDataBase");
but I get a javax.naming.NameNotFoundException - probably because I dont use env variables, but I don't think I need that, just per context scope lookup)
EDIT 2:
Ok, so I was actually missing a web.xml config which solved the issue (see http://www.eclipse.org/jetty/documentation/current/jndi-configuration.html#configuring-datasources)
<resource-ref>
<res-ref-name>jdbc/HugaDataBase</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
You need to set the scope for the JNDI entries. Instead of the empty first argument, you should have something like this:<Arg><Ref refid='myapp'/></Arg>
I need to use https for jetty maven plugin.
I googled following answer
https://stackoverflow.com/a/3795116/2674303
But looks like this answer is not suitable for jetty-maven-plugin of 9 version.
idea complains about syntax
How to fix my problem?
Ok, since jetty-9.0 it is no longer possible to configure a https connector directly in the pom.xml: you need to use jetty xml config files to do it.
I am new to exchange ,so excuse my code copy/paste.
jetty.xml
<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">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">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>
Look here, for whole bunch of xml's and if it is helpful please check my answer as correct
I'm making a small servlet app in Java, with Maven, in Netbeans. I'm using SQLite database, and newest Jetty server. I have problem with creating connection pool for use in servlets. What works(in servlet):
Class.forName("org.sqlite.JDBC");
String url = "jdbc:sqlite:c:\\db\\base";
Connection con = DriverManager.getConnection(url);
And this works without specific settings in jetty.xml/web.xml/pom.xml
I have libraries to use SQLite and connection pools (org.xerial.sqlite-jdbc, commons-pool, commons-dbcp).
What doesn't work:
web.xml:
<resource-ref>
<description>DB Connection Pool</description>
<res-ref-name>jdbc/DSTestPool</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jetty.xml
<New id="DSTestPool" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/DSTestPool</Arg>
<Arg>
<New class="org.sqlite.SQLiteConnectionPoolDataSource">
<Set name="driverClassName">org.sqlite.JDBC</Set>
<Set name="url">jdbc:sqlite:c:\\db\\base</Set>
</New>
</Arg>
</New>
pom.xml - dependencies.
This configuration, even without changes in code (change to using pool) creates error in jetty console:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
....
Caused by:
java.lang.IllegalStateException: Nothing to bind for name jdbc/DSTestPool at org.eclipse.jetty.plus.webapp.PlusDescriptorProcessor.bindEntry(PlusDescriptorProcessor.java:895)
...
Opening app in Jetty: Error 503
I think there is something wrong with my declaration of jdbc/DSTestPool in jetty.xml, I've tried different parameters, but result was the same.
There is one parameter missing in your jetty.xml, you can declare any of the following types:
org.eclipse.jetty.plus.jndi.EnvEntry: for env-entry type of entries
org.eclipse.jetty.plus.jndi.Resource: for all other type of resources
org.eclipse.jetty.plus.jndi.Transaction: for a JTA manager
org.eclipse.jetty.plus.jndi.Link: for link between a web.xml resource name and a naming entry
And each of these types follow the same pattern:
<New class="org.eclipse.jetty.plus.jndi.xxxx">
<Arg><!-- scope --></Arg>
<Arg><!-- name --></Arg>
<Arg><!-- value --></Arg>
</New>
Your jetty.xml file have the name and value but the scope is missing.
Try with the following for JVM instance scope (the name is unique across the JVM instance)
<New id="DSTestPool" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg><!-- empty arg -->
<Arg>jdbc/DSTestPool</Arg>
<Arg>
<New class="org.sqlite.SQLiteConnectionPoolDataSource">
<Set name="driverClassName">org.sqlite.JDBC</Set>
<Set name="url">jdbc:sqlite:c:\\db\\base</Set>
</New>
</Arg>
</New>
Or something like the following for a web app context scope (the name is unique to the WebAppContext instance)
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="DSTestPool" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid='wac'/></Arg><!-- reference to WebAppContext -->
<Arg>jdbc/DSTestPool</Arg>
<Arg>
<New class="org.sqlite.SQLiteConnectionPoolDataSource">
<Set name="driverClassName">org.sqlite.JDBC</Set>
<Set name="url">jdbc:sqlite:c:\\db\\base</Set>
</New>
</Arg>
</New>
</Configure>
See the documentation here for details.
An approach could be to use HikariCp (or any other pooler..).
In jetty-env.xml:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/ds</Arg>
<Arg>
<New class="com.zaxxer.hikari.HikariDataSource">
<Arg>
<New class="com.zaxxer.hikari.HikariConfig">
<Set name="dataSourceClassName">org.sqlite.SQLiteDataSource</Set>
<Call name="addDataSourceProperty">
<Arg>url</Arg>
<Arg>jdbc:sqlite:path/to/test.db</Arg>
</Call>
</New>
</Arg>
</New>
</Arg>
In web.xml:
<resource-ref id="ds">
<res-ref-name>jdbc/ds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
then you get datasource:
(DataSource)new InitialContext().lookup("java:/comp/env/jdbc/ds");
...
I am trying to run jetty in ssl mode with client authentication.
I pass keystore.But instead of passing truststore, i import my certificate into java/jre/lib/security/cacerts. please find the jetty.xml configuration
<Call class="java.lang.System" name="setProperty">
<Arg>javax.net.ssl.keyStore</Arg>
<Arg><SystemProperty name="jetty.home" default="." />/../workspace/conf/xyz.ks</Arg>
</Call>
<Call class="java.lang.System" name="setProperty">
<Arg>javax.net.ssl.keyStorePassword</Arg>
<Arg>abc</Arg>
</Call>
<Call class="java.lang.System" name="setProperty">
<Arg>javax.net.ssl.keyStoreType</Arg>
<Arg>JKS</Arg>
</Call>
Socketconnector
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.security.SslSocketConnector">
<Set name="Port"><SystemProperty name="port"/></Set>
<Set name="maxIdleTime">600000</Set>
<Set name="keystore"><SystemProperty name="javax.net.ssl.keyStore"/></Set>
<Set name="keyPassword"><SystemProperty name="javax.net.ssl.keyStorePassword"/></Set>
<!--Set name="truststore"><SystemProperty name="javax.net.ssl.trustStore"/></Set>
<Set name="trustPassword"><SystemProperty name="javax.net.ssl.trustStorePassword"/></Set-->
<Set name="needClientAuth">true</Set>
</New>
</Arg>
</Call>
Now when i hit the url https://localhost:1234/xyz?wsdl i get bad_certificate exception which is caused due to null cert chain.
i) can java cacerts be used to configure jetty?
ii) is it because of the webservice call because in the logs it is shown as the server is started.
I am using jetty 6 and cxf 2.6 webservice.
thanks,
Keerthi.
You should try hitting your URL from a browser, after adding your client certificate to your browser certificate store. By the way you will know if your error is due to server or client side misconfiguration.
In order to have custom session storage I have implemented a custom sessionManager (by extending NoSqlSessionManager) and sessionIdManager. My code (along with jars it requires) went into ${jetty.home}/lib/ext (version 8.1.4 BTW). With start.ini i included another config file with following content:
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Set name="sessionIdManager">
<New id="customIdMgr" class="com.me.customSessionIdManager">
<Arg>...</Arg>
</New>
</Set>
</Configure>
Jetty starts and sessionIdManager appears to be working. At least scavenge() method is being called. So far so good. Next step is to associate my custom sessionManager with the WebAppContext of my choice. I did it within the overlay template (overlay.xml) with following content:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="server">
<Get id="customIdMgr" name="sessionIdManager"/>
</Get>
<Set name="sessionHandler">
<New class="org.eclipse.jetty.server.session.SessionHandler">
<Arg>
<New class="com.me.customSessionManager">
<Set name="sessionIdManager"><Ref id="customIdMgr"/></Set>
</New>
</Arg>
</New>
</Set>
</Configure>
However when starting Jetty I get this:
WARN:oejx.XmlConfiguration:Config error at <Get id="customIdMgr" name="sessionIdManager"/> java.lang.NullPointerException
...which implies that the object that was registered in the main jetty configuration is now gone when overlays are processed.
Any idea what I'm doing wrong here?
After quite a lot of debugging it turns out, the root of the problem is <Get name="server"> returns null. Most probably reference to Server class is injected into WebAppContext much later in the deployment process. So instead of getting Server i referenced it with <Ref id="Server"> and that did the trick.