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>
Related
It would be great if someone was able to help me with the following.
We currently use Jetty to expose our REST interface (Which is setup with Spring) and I want to be able to set the prefix of the threads that are used to process these calls. I believe I have found the change to cxf that will enable this behaviour:
https://issues.apache.org/jira/browse/CXF-5919
It seems to change the initial "qtp" value to whatever you want. (The version we have does include these changes) The problem is that I cannot actually work out how to set it, initially I tried the following:
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Set name="threadPool">
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">1000</Set>
<Set name="threadNamePrefix">myname</Set>
</New>
</Set>
</Configure>
http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax#Creating_a_NewObject_and_Setting_It_on_the_Server
But that does not work as it's not the QueuedThreadPool that has the threadNamePrefix value.
I would be great if someone was able to give me some pointers as to how I can update my jetty.xml so that I can set this value.
Thank you
Rob
Looking at Jetty source code I see that name attribute is the one you are after. Your example should look like this:
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Set name="threadPool">
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">1000</Set>
<Set name="name">myname</Set>
</New>
</Set>
</Configure>
This is the result (from VisualVM) on my setup:
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
I've a web app that needs to use ElasticSearch but my host does not permit to use Java apps.
It is possible to put the ElasticSearch server on other machine(Remote) so that the webapp makes the queries to a remote server? If yes, ElasticSearch have some way to secure the data in the ElasticSearch server? How can I protect other users to make queries to this remote ElasticSearch server?
Best Regards,
Yes. If you don't have the option to move your application to another server that permits Java, you can access the remote server using JSON calls or a client if available for your platform (http://www.elasticsearch.org/guide/en/elasticsearch/client/community/current/clients.html).
To make things secure, you can install the jetty plugin (https://github.com/sonian/elasticsearch-jetty), configure SSL, authentication and maybe add a IP restriction like creating a jetty-iprestriction.xml with the content bellow and adding a reference to it in elasticsearch.yml.
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="ESServer" class="org.eclipse.jetty.server.Server">
<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 class="org.eclipse.jetty.server.handler.IPAccessHandler">
<Call name="addWhite">
<!-- allowed server ip -->
<Arg>xxx.xxx.xxx.xxx</Arg>
</Call>
<Set name="handler">
<New class="com.sonian.elasticsearch.http.jetty.handler.JettyHttpServerTransportHandler"
id="HttpServerAdapterHandler">
<Set name="transport"><Ref id="ESServerTransport"/></Set>
</New>
</Set>
</New>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
<Item>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
</Configure>
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>
My goal is simple. Configure the maven-jetty-plugin with a JNDI for javamail.
But after hours of googling and reading i cannot figure out exactly what to do....
Can someone please help me with a simple step-by-step instruction.
I just read the documentation at http://docs.codehaus.org/display/JETTY/JNDI, but there is absolutly no information about what file i should be editing...
For example. Where am i supposed to put this???
<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="mail" class="org.mortbay.jetty.plus.naming.Resource">
<Arg><Ref id="wac"/></Arg>
<Arg>mail/Session</Arg>
<Arg>
<New class="org.mortbay.naming.factories.MailSessionReference">
<Set name="user">fred</Set>
<Set name="password">OBF:1xmk1w261z0f1w1c1xmq</Set>
<Set name="properties">
<New class="java.util.Properties">
<Put name="mail.smtp.host">XXX</Put>
<Put name="mail.from">me#me</Put>
<Put name="mail.debug">true</Put>
</New>
</Set>
</New>
</Arg>
And lastly. Since this is the maven-jetty-plugin, i do not have access to modify any core files, so should there be some kind of xml file i should create and set up to override jetty original configuration?
Add the following configuration to the maven-jetty-plugin:
<jettyEnvXml>src/jetty-env.xml</jettyEnvXml>
Then, you can place that file in that location.
Here are concrete examples:
pom.xml (line 536)
jetty-env.xml