Jetty OJDBC java.net.ConnectException: Connection timed out: connect - oracle

Could you help me, please. I have war file from Welogic. And I need to start it at jetty. My jetty-env.xml:
<New id="dataSource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/rtnDS</Arg>
<Arg>
<New class="oracle.jdbc.pool.OracleDataSource">
<!-- <Set name="DriverType">thin</Set>-->
<Set name="URL">jdbc:oracle:thin:#10.20.10.221:1521:rtn.rtn.taganka</Set>
<Set name="User">RTN_PROD17_F5</Set>
<Set name="Password">*******</Set>
<Set name="connectionCachingEnabled">true</Set>
<Set name="connectionCacheProperties">
<New class="java.util.Properties">
<Call name="setProperty">
<Arg>MinLimit</Arg>
<Arg>5</Arg>
</Call>
</New>
</Set>
</New>
</Arg>
</New>
But i have an error when jetty is starting
[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext#5399f6c5{/,file:///C:/Users/Viachaslau/IdeaProjects/JobsLocal/src/main/webapp/,UNAVAILABLE}{file:///C:/Users/Viachaslau/IdeaProjects/JobsLocal/src/main/webapp/}
java.net.ConnectException: Connection timed out: connect

Related

Can we run initial sql in oracle jdbc connection on jetty?

I have a local jetty java project. I would like to run some sql when the server creates any connections. The connections are configured in a jetty-env.xml file. Im hoping there is some oracle jdbc property like "run-sql-on-connect" where I can trigger the sql. Essentially I want to alter the session whenever a connection is established. Is there anything in OracleDataSource.connectionProperties like this?
<New id="OracleDS_local" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/local</Arg>
<Arg>
<New class="oracle.jdbc.pool.OracleDataSource">
<Set name="URL">jdbc:oracle:thin:*******</Set>
<Set name="user">*****</Set>
<Set name="password">****</Set>
<Set name="connectionProperties ">
<Set name="run-sql-on-connect" >alter session sql here</Set>
</Set>
</New>
</Arg>
</New>
A possible workaround/solution (depending on the requirements) would be to use a custom context handler and a related event to perform a separate connection and execute the query you want.
I know it's not an optimal solution but it might do the trick.
Reference:
https://www.eclipse.org/jetty/javadoc/jetty-11/org/eclipse/jetty/webapp/WebAppContext.html
<Configure id='oracledbdemo' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="OracleDS_local" class="org.mortbay.jetty.plus.naming.Resource">
...
</Configure>
REPLACE WITH
<Configure id='oracledbdemo' class="<YOUR_CUSTOM_WebAppContext_HERE">
</Configure>

Unable to open httpConnection in Jetty9 while migrating from jetty6

I am migrating my current spring based java project from jetty6 to jetty9. I am also migrating from JDK6 to JDK9 at the same time. I do understand that quite a lot has changed with jetty.
I tried to follow the docs from jetty link but after successfully building my project I am getting error while trying to open active http/https connections.
I have done the configuration in XML as I am reading a lot of values from properties file and doing all this programmatically won't be very clean approach.
Below is my configuration:-
<Configure id="server" class="org.eclipse.jetty.server.Server">
<New id="httpConfig"
class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort"><Ref id="opPort" /></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>
<Call name="addCustomizer">
<Arg>
<New class="org.eclipse.jetty.server.SecureRequestCustomizer" />
</Arg>
</Call>
</New>
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server">
<Ref refid="server" />
</Arg>
<!-- <Arg name="acceptors">2</Arg> -->
<!-- <Arg name="selectors">-1</Arg> -->
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.SslConnectionFactory">
<Arg name="next">http/1.1</Arg>
<Arg name="sslContextFactory">
<Ref refid="sslContextFactory" />
</Arg>
</New>
</Item>
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config">
<Ref refid="httpConfig" />
</Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="host">localhost</Set>
<Set name="port">
<Ref id="opPort" />
</Set>
<Set name="idleTimeout">2000000</Set>
<Set name="acceptQueueSize">64</Set>
</New>
</Arg>
</Call>
<New id="sslContextFactory"
class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="keyStorePath">./configuration/dev/keystore</Set>
<Set name="keyStorePassword">OBF:1zlu1uum1toq1w8v1to41uvk1zlo</Set>
<Set name="keyManagerPassword">OBF:1zlu1uum1toq1w8v1to41uvk1zlo</Set>
<Set name="trustStorePath">./configuration/dev/keystore</Set>
<Set name="trustStorePassword">OBF:1zlu1uum1toq1w8v1to41uvk1zlo</Set>
<!-- <Set name="endpointIdentificationAlgorithm"></Set> -->
<Set name="ExcludeCipherSuites">
<Array type="String">
<Item>SSL_RSA_WITH_DES_CBC_SHA</Item>
<Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item>
<Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item>
<Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item>
<Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
<Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
<Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item>
</Array>
</Set>
</New>
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<!--your web app WAR goes here -->
<Item>
<New id="WmSecurityWebApp" class="org.eclipse.jetty.webapp.WebAppContext">
<Arg>./target/gls-op.war</Arg>
<Arg>/gls-op/us/7049</Arg>
<Set name="logUrlOnStart" type="boolean">true</Set>
<Set name="parentLoaderPriority">true</Set>
</New>
</Item>
</Array>
</Set>
</New>
</Set>
While the project is building successfully but when I hit any Rest API, it throws error:-
16:26:16.470 [qtp985922955-32] DEBUG o.e.j.util.thread.QueuedThreadPool - ran EatWhatYouKill#29855e88/org.eclipse.jetty.io.ManagedSelector$SelectorProducer#dcd6f19/PRODUCING/1/1
16:26:16.470 [qtp985922955-18] DEBUG o.e.jetty.server.HttpConnection -
javax.net.ssl.SSLHandshakeException: Unrecognized SSL message, plaintext connection?
at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.fill(SslConnection.java:804) ~[jetty-io-9.4.6.v20170531.jar:9.4.6.v20170531]
I have updated the keystore using jdk8 and also the OBF form using jetty utility version being used on my machine.
Even after changing many things around, it is not working out for me.
I removed SSL and tested only using HTTP connection settings. It worked fine. I am not using SSL for now and it seems to be good for now. Meanwhile I will keep checking out for options to use both settings together in a single file.

Jetty 9 XML Connector Configuration error

I am attempting to run jetty 9.3.8. I had to change over my Jetty 8 configuration, which was working, but I am now receiving a Config error which prints out the whole XML connector configuration line.
Here is what Jetty doesn't like - jetty.xml
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelecChannelConnector">
<Set name="host">
<Property name="jetty.host" default="localhost"/>
</Set>
<Set name="port">
<Property name="jetty.port" default="7080"/>
</Set>
<Set name="maxIdleTime">60000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="confidentialPort">7443</Set>
</New>
</Arg>
</Call>
Any ideas are great.
You have a typo in SelecChannelConnector => SelectChannelConnector.
Anyway, for Jetty 9 you should prefer the use of org.eclipse.jetty.server.ServerConnector as quoted in Jetty's own documentation:
Prior to Jetty 9, the type of the connector specified both the protocol and the implementation used; for example, selector-based non blocking I/O vs blocking I/O, or SSL connector vs non-SSL connector. Jetty 9 has a single selector-based non-blocking I/O connector, and a collection of ConnectionFactories now configure the protocol on the connector.
Configuring Jetty Connectors

Can I use property placeholders in Jetty-env.xml?

I am working on a project that uses jetty-env.xml to define some resources in the test environment. It requires that I hijack it and put in my username and password for the resources. Is there a way to define my credentials in an external way and use a property placeholder instead? Like in the Spring applicationConfig.xml I can use ${username} as defined in my system properties.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="wac" class="org.mortbay.jetty.webapp.WebAppContext">
<New id="validation_mail" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>mail/exampleMail</Arg>
<Arg>
<New class="org.mortbay.naming.factories.MailSessionReference">
<Set name="user"></Set>
<Set name="password"></Set>
<Set name="properties">
<New class="java.util.Properties">
<Put name="mail.smtp.host">mail.example.edu</Put>
</New>
</Set>
</New>
</Arg>
</New>
<New id="datasource" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/DataSource</Arg>
<Arg>
<New class="com.sybase.jdbc3.jdbc.SybDataSource">
<Set name="databaseName">example</Set>
<Set name="serverName">testip.example.edu:2025</Set>
<Set name="portNumber">2025</Set>
<Set name="user">username</Set> <!-- put username here -->
<Set name="password">password</Set> <!-- put password here -->
</New>
</Arg>
</New>
I new to these tools so I might be closer to an answer than I think. Any help would be appreciated.
Enviroment:
Spring Tool Suite 3.4.0 RELEASE
Maven 3
Jetty Plugin 6.1
Spring 3
If you're using the jetty maven plugin, then you can define your properties in a properties file.
Configure the jetty plugin like this:
<configuration>
<systemPropertiesFile>${project.basedir}/src/test/conf/jetty-env.properties</systemPropertiesFile>
</configuration>
And then your jetty-env.xml can be like this:
<New id="dsDatasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/dsProtWb</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">net.sourceforge.jtds.jdbc.Driver</Set>
<Set name='url'>jdbc:jtds:sqlserver://ROPFDN812Q:4900/dlmp_proteomics_wb_dev;instance=FDNDEV18;domain=mfad</Set>
<Set name="username"><SystemProperty name="LANID" /></Set>
<Set name="password"><SystemProperty name="LANPW" /></Set>
</New>
</Arg>
</New>
You can define environment variables and use the Env tag as a placeholder.
<New id="dsDatasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/dsProtWb</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">net.sourceforge.jtds.jdbc.Driver</Set>
<Set name='url'>jdbc:jtds:sqlserver://ROPFDN812Q:4900/dlmp_proteomics_wb_dev;instance=FDNDEV18;domain=mfad</Set>
<Set name="username"><Env name="LANID"/></Set>
<Set name="password"><Env name="LANPW"/></Set>
</New>
</Arg>
</New>

How to Configure P6Spy with OracleConnectionPoolDataSource in specific

We are using Oracle connection Pooling mechanism in our project as our application uses some oracle specific features.
The configuration of our datasource in jetty.xml is as follows:
<Call name="addService">
<Arg>
<New class="org.mortbay.jetty.plus.DefaultDataSourceService">
<Set name="Name">DataSourceService</Set>
<Call name="addDataSource">
<Arg>app_ds</Arg><!--java:comp/env-->
<Arg>
<New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
<Set name="description">xxxx</Set>
<Set name="user">xxx</Set>
<Set name="password">xxxx</Set>
<Set name="loginTimeout">xxx</Set>
<Set name="URL">jdbc:oracle:thin:#localhost:1521:xxx</Set>
</New>
</Arg>
</Call>
<Call name="start"/>
</New>
Now How do we integrate this datasource with P6Spy, so that P6Spy can print out all the SQL statements on to the console...?
I have previously used P6spy with other datasources like spring's DriverManagerDataSource, other datasources like as
(In Tomcat)
Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#xxx"
username="xxx" password="xxx" maxActive="65" maxIdle="10"
maxWait="-1" removeAbandoned="true"/>
..etc.
All these datasources take driverClassName as argument where we can provide the "com.p6spyengine.spy.P6SpyDriver" in the place of "oracle.jdbc.driver.OracleDriver" and provide the real driver name in spy.properties. The all worked fine.
But with oracle.jdbc.pool.OracleConnectionPoolDataSource, there is no such property called driverClassName to provide a proxy driver to.
In this case how can i integrate P6Spy with it?
Please help...
Thanks in Advance,
Krishna V
From my experience with Glassfish, I would suggest to:
keep your existing oracle (real) datasource definition
create new one (P6Spy one) used as proxy to real one,
defined like this:
<Call name="addService">
<Arg>
<New class="org.mortbay.jetty.plus.DefaultDataSourceService">
<Set name="Name">DataSourceService</Set>
<Call name="addDataSource">
<Arg>p6spy_ds</Arg><!--java:comp/env -->
<Arg>
<New class="com.p6spy.engine.spy.P6DataSource">
<!-- properties would be irrelevant here -->
<Set name="description">xxxx</Set>
<Set name="user">xxx</Set>
<Set name="password">xxxx</Set>
<Set name="loginTimeout">xxx</Set>
<Set name="URL">jdbc:oracle:thin:#localhost:1521:xxx</Set>
</New>
</Arg>
</Call>
<Call name="start" />
</New>
and make sure to refer the real one from the spy.properties file,
using:
realdatasource=jdbc/app_ds # assuming that app_ds is your real datasource
the last thing is to refer the proxy_ds in all your application logic to make sure to use it (If referring would cost you too much, you can always call the proxy datasource the same as the original one and rename the original one + refer the new name in spy.properties config file)
With Jetty, adding P6Spy is actually a little easier. P6Spy has a P6DataSource that accepts another data source via constructor parameter. This is by far the easiest way to setup P6Spy.
<Call name="addService">
<Arg>
<New class="org.mortbay.jetty.plus.DefaultDataSourceService">
<Set name="Name">DataSourceService</Set>
<Call name="addDataSource">
<Arg>app_ds</Arg><!--java:comp/env-->
<Arg>
<New class="com.p6spy.engine.spy.P6DataSource">
<Arg>
<New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
<Set name="description">xxxx</Set>
<Set name="user">xxx</Set>
<Set name="password">xxxx</Set>
<Set name="loginTimeout">xxx</Set>
<Set name="URL">jdbc:oracle:thin:#localhost:1521:xxx</Set>
</New>
</Arg>
</New>
</Arg>
</Call>
<Call name="start"/>
</New>

Resources