How to setup https/ssl on Tomcat 6?

Generate a keystore using this command:

c:\work\keytool -genkey -alias myalias -keyalg RSA -keystore mykeystore

 

Your Tomcat server.xml should have an entry like below:

<Connector port=”8443″ protocol=”org.apache.coyote.http11.Http11Protocol”  SSLEnabled=”true”
maxThreads=”150″ scheme=”https” secure=”true”
clientAuth=”false” sslProtocol=”TLS” keystoreFile=”C:\work\mykeystore”
keystoreType=”JKS” keystorePass=”123456″ />

This may also be needed (note the SSLEngine=off ):

<Listener className=”org.apache.catalina.core.AprLifecycleListener” SSLEngine=”off” />

 

Note, your site now will work on both http and https – assuming you have not removed the http connector from server.xml

If you want to force some URLs to work only in https then add the following in web.xml:

 

<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>

<user-data-constraint>
<!– All access to this area will be SSL protected –>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

 

Now, all the URLs that are like: /secure/whatever – can be accessed only over https. If you attempt to access them over http, it will redirect to https automatically.

Note: We have generated and used a dummy certificate above, altho it works – when u open url using https://.. in your browser – you will see a warning and a red mark. To use a real ssl certificate (you will have to buy) - the steps will be slightly different.

How to share folders between Windows Host, and Linux Guest OS on VMWare (Workstation)?

 

First Way

  1. On Windows Host, Right Click > Properties > Share (with Everyone)
  2. On Linux Host: Applications > File Browser > File > Connect to Server > Service Type: Windows Share , Server:  Give-Desktop-IP > Connect.
  3. On being prompted enter windows username/group/password – Thats it, your shared folder will show up

 

Second Way

  • You could always run a Web-Server on your Windows Host, and access it from Linux Host (either browser or wget). Not exactly file sharing, but files can be downloaded from Windows Host to Linux this way (just in case nothing else is working for you!)

 

Third Way

  • With VMWare Tools – it should be possible too… have not got it to work yet.

Error Message: No suitable driver found for jdbc:mysql:.. in a maven jpa/hibernate/mysql project

Problem Statement

In your maven project, with appropriate dependencies for Hibernate/MySQL, you get the following error – when jpa-hibernate code is invoked:

WARN : org.hibernate.connection.DriverManagerConnectionProvider – no JDBC Driver class was specified by property hibernate.connection.driver_class
WARN : org.hibernate.cfg.SettingsFactory – Could not obtain connection to query metadata
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/somedb

Solution

The solution is in the warning itself. Note the line that says:  no JDBC Driver class was specified by property hibernate.connection.driver_class

In your persistence.xml file add the following line:
<property name=”hibernate.connection.driver_class” value=”com.mysql.jdbc.Driver” />

That’s It!

How to resolve: Maven Error: [ERROR] No plugin found for prefix ‘archetype’ in the current project…

Problem Statement

You get this error while doing  maven build:

[ERROR] No plugin found for prefix ‘archetype’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the
repositories [local (C:\Documents and Settings\<user>\.m2\repository), central (http://repo1.maven.org/maven2)%5D

Solution

Very likely, your proxy settings are the problem. If you are behind a firewall setup your proxy correctly.
Proxy settings are in settings.xml config file of maven. This file usually exists in two places:

  • <MAVEN_HOME>\conf
  • c:\documents and settings\<user>\.m2

Thats it!

Simple image (widget for) zoom, rotate?

Ref: https://github.com/can3p/iviewer

Here is an example (only zoom, fit etc.. for rotate see iviewer website):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>jquery.iviewer test</title>
<script type=”text/javascript” src=”imgtest/jquery.js” ></script>
<script type=”text/javascript” src=”imgtest/jqueryui.js” ></script>
<script type=”text/javascript” src=”imgtest/jquery.ui.core.js” ></script>
<script type=”text/javascript” src=”imgtest/jquery.mousewheel.min.js” ></script>
<script type=”text/javascript” src=”imgtest/jquery.iviewer.js” ></script>
<script type=”text/javascript”>
var $ = jQuery;
$(document).ready(function(){
var iv1 = $(“#viewer”).iviewer({
src: “test_image.jpg”,
update_on_resize: false,
zoom_animation: false,
mousewheel: false,
onMouseMove: function(ev, coords) { },
onStartDrag: function(ev, coords) { return false; }, //this image will not be dragged
onDrag: function(ev, coords) { }
});

$(“#in”).click(function(){ iv1.iviewer(‘zoom_by’, 1); });
$(“#out”).click(function(){ iv1.iviewer(‘zoom_by’, -1); });
$(“#fit”).click(function(){ iv1.iviewer(‘fit’); });
$(“#orig”).click(function(){ iv1.iviewer(‘set_zoom’, 100); });
$(“#update”).click(function(){ iv1.iviewer(‘update_container_info’); });

$(“#chimg”).click(function()
{
iv1.iviewer(‘loadImage’, “imgtest/test_image2.jpg”);
return false;
});
});
</script>
<link rel=”stylesheet” href=”imgtest/jquery.iviewer.css” />
<style>
.viewer
{
width: 80%;
height: 800px;
border: 1px solid black;
position: relative;
}

.wrapper
{
overflow: hidden;
}
</style>
</head>
<body>
<h1>JQuery.iviewer test</h1>
<!– wrapper div is needed for opera because it shows scroll bars for reason –>
<div class=”wrapper”>
<span>
<a id=”in” href=”#”>+</a>
<a id=”out” href=”#”>-</a>
<a id=”fit” href=”#”>fit</a>
<a id=”orig” href=”#”>orig</a>
<a id=”update” href=”#”>update</a>
</span>
<a href=”#” id=”chimg”>Change Image</a>
<div id=”viewer” class=”viewer”></div>
</div>
</body>
</html>

How to create Collapsible (Sliding) Div using JQuery?

Here is an example:

<html>
<head>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js”></script&gt;

<style>
p.content-one {
display:none;
}
p.content-two {
display:none;
}
</style>

</head>
<body>

<div class=”sitesection” style=”border:1px solid black; width:900px; background-color:LightGrey”>
<a href=”#” class=”expand-one”>Expand</a>
<SELECT id=”u131″ class=”u131″>
<OPTION selected value=”1″>A</OPTION>
<OPTION value=”2″>B</OPTION>
<OPTION value=”3″>C</OPTION>
<OPTION value=”4″>D</OPTION>
</SELECT>
<p class=”content-one”>
<img src=”http://im.rediff.com/200-300/getahead/2013/jul/18food1.jpg”/>&nbsp;&nbsp;
<img src=”http://im.rediff.com/200-300/getahead/2013/jul/18food1.jpg”/&gt;
</p>
</div>
<div class=”sitesection” style=”border:1px solid black; width:900px; background-color:LightGrey”>
<a href=”#” class=”expand-two”>Expand</a>
<SELECT id=”u131″ class=”u131″ data-label=”Loan Selector” >
<OPTION selected value=”11″>AA</OPTION>
<OPTION value=”22″>BB</OPTION>
<OPTION value=”33″>CC</OPTION>
<OPTION value=”44″>DD</OPTION>
</SELECT>
<p class=”content-two”>
<img src=”http://im.rediff.com/200-300/getahead/2013/jul/18food1.jpg”/>&nbsp;&nbsp;
<img src=”http://im.rediff.com/200-300/getahead/2013/jul/18food1.jpg”/&gt;
</p>
</div>
<script type=”text/javascript”>
$(‘.expand-one’).click(function(){
$(‘.content-one’).slideToggle(‘slow’);
});
$(‘.expand-two’).click(function(){
$(‘.content-two’).slideToggle(‘slow’);
});
$(‘.expand-three’).click(function(){
$(‘.content-three’).slideToggle(‘slow’);
});
</script>
</body>
</html>

How to create a curved div/rectangle (with JQuery)?

Ref: https://code.google.com/p/jquerycurvycorners/

Here is an example:

<!DOCTYPE HTML>
<HTML>
<HEAD>
<META content=”text/html; charset=utf-8″ http-equiv=Content-Type>

<SCRIPT type=text/javascript src=”jslib/jquery-1.2.6.min.js”></SCRIPT>
<SCRIPT type=text/javascript src=”jslib/jquery.curvycorners.min.js”></SCRIPT>

<SCRIPT type=text/javascript>
$(function(){
$(‘.inner’).corner({
tl: { radius: 10 },
tr: { radius: 10 },
bl: { radius: 10 },
br: { radius: 10 }});
});
</SCRIPT>
</HEAD>

<BODY>
<br><br><br>
<DIV style=”border: 1px solid”>
Inside a Curved Div…<br>
Hello<br>
Hello
</DIV>
</BODY>
</HTML>

How to select an image area and find its coordinates or crop an image?

JCrop lets you do these:

  • URL http://deepliquid.com/content/Jcrop.html (This is JQuery Plugin, and you can download and use it.)
  • You can select an area by dragging your mouse over the image and it will give out coordinates of the area (rectangle)
  • To actually crop (cut) an image, this can be done too here, but for that there is backend php which does this job.

This is also called Image Mapping.

How to highlight image area, on mouseover of the area, or from a (external) text link?

This can be done by using JQuery Map Highlight Plugin (jquery.maphilight.js).

Here’s the complete code:

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js”></script&gt;
<script type=”text/javascript” src=”jquery.maphilight.js”></script>
<script type=”text/javascript”>$(function() {
$(‘.map’).maphilight();
});</script>

</head>
<body>

<table>
<tr>
<td>
<form>
<a id=”Area1Link” href=”#” onmouseover=”$(‘#area1′).trigger(‘mouseover’);” onmouseout=”$(‘#area1′).trigger(‘mouseout’);”>Area 1</a><br/>
<a id=”Area2Link” href=”#” onmouseover=”$(‘#area2′).trigger(‘mouseover’);” onmouseout=”$(‘#area2′).trigger(‘mouseout’);”>Area 2</a>
</form>
</td>
<td><img src=”demo_simple.png” width=”420″ height=”300″ class=”map” usemap=”#simple”></td>
</tr>
</table>
<map name=”simple”>
<area id=”area2″ href=”#” shape=”poly” coords=”47,62,106,61,134,72,135,118,30,116″ alt=”Link” title=”Default behavior”>
<area href=”#” shape=”poly” coords=”32,157,133,157,127,192,127,211,28,211″ alt=”Link” data-maphilight=’{“strokeColor”:”0000ff”,”strokeWidth”:5,”fillColor”:”ff0000″,”fillOpacity”:0.6}’ title=”Metadata’d up a bit”>
<area id=”area1″ href=”#” shape=”circle” coords=”290,102,30″ alt=”Octoface” data-maphilight=’{“stroke”:false,”fillColor”:”ff0000″,”fillOpacity”:0.6}’ title=”Metadata’d up a bit”>
<area href=”#” shape=”poly” coords=”219,190,225,175,237,157,239,148,245,142,251,140,263,140,265,139,310,139,311,145,364,182,363,201,343,221,333,213,329,181,313,177,330,234,295,231,292,174,279,176,282,204,269,220,255,206,267,167,235,193″ alt=”Legs” data-maphilight=’{“stroke”:false,”fillColor”:”000000″,”fillOpacity”:1,”alwaysOn”:true}’ title=”Metadata’d up a bit”>
</map>
</p>

</body>
</html>

The JavaScript Library is available here: https://github.com/kemayo/maphilight

The above code is a slight modification, of simple demo found here: http://www.jquery4u.com/image-scripts/highlight-image-map-area-hotspots-jquery/ 

You can find the coordinates to use in ‘area’ tag above by using a Image Mapper software.
For eg

The image used for the above example is:

demo_simple

How to configure JBoss datasource (Oracle/RAC/Re-Connect)?

<local-tx-datasource> vs <xa-datasource>

  • <local-tx-datasource> is used for a single JBoss App Server.
  • <xa-datasource> is used in a clustered JBoss App Server environment.
  • Note that both <local-tx-datasource> and <xa-datasource> handle distributed transactions involving multiple data source\

Preventing Stale Connections

For this you can add the following to the datasource (-ds.xml):

<validation>
<valid-connection-checker 
class-name="org.jboss.jca.adapters.jdbc.vendor.OracleValidConnectionChecker"/>
<check-valid-connection-sql>
select 1 from dual
</check-valid-connection-sql>
<stale-connection-checker 
class-name="org.jboss.jca.adapters.jdbc.vendor.OracleStaleConnectionChecker"/>
<exception-sorter 
class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
</validation>

The above has performance implications:

  • The check-valid-connection-sql, wil be invoked everytime a Connection is borrowed from the Pool.
  • Therefore, this should not be used in heavy load scenarios.

Fail-Over with Oracle RAC

This is possible via one of these ways:

  • FCF – Fast Connection Failover.
  • TAF – Transparent Application Failover.

FCF

  • This is possible using JDBC-Thin (Type 4) driver (typically used with this).
  • It is event based, and supports load-balancing across nodes.
  • Works with help of ONS – Oracle Notification Service. A Service that runs in Oracle Database notifying interested parties about Oracle RAC Node status
  • On the client side you need: ojdbcN.jar and ons.jar
  • Do we need ons.config file?
  • A datasource that supports Fast Connection Failover is needed. (it will use ons internally to achieve this?)
  • Tomcat datasource configuration provides support for this. JBoss datasource configuration (eg. oracle-ds.xml) support is not known.
  • Perhaps you can programatically setup the datasource and achieve this.
  • Read Steps here: http://www.drdobbs.com/jvm/jdbc-fast-connection-failover-with-oracl/222700353
  • What happens to the Connection Pool when a node goes down, does it automatically get refreshed?
  • What is the role of ucp here?

Tomcat datasource config:

<Resource name="JDBC/Pool" auth="Container"
 ONSConfiguration="nodes=rac1:6200,rac2:6200"
 connectionCachingEnabled="true"
 description="FCF Datasource"
 driverClassName="oracle.jdbc.OracleDriver"
 factory="oracle.jdbc.pool.OracleDataSourceFactory"
 fastConnectionFailoverEnabled="true"
 implicitCachingEnabled="true"
 connectionCacheProperties=
"(InitialLimit=5, MinLimit=5, MaxLimit=20, ConnectionWaitTimeout=30)"
 connectionCacheName="tomcatConnectionCache"
 user="username" password="password"
 type="oracle.jdbc.pool.OracleDataSource"
 url="jdbc:oracle:thin:@(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = SERVICE)))"
/>

Ref: http://keremerkan.net/posts/supporting-oracle-fcf-in-tomcat/

Spring Datasource Configuration:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:orcl="http://www.springframework.org/schema/data/orcl"
       xsi:schemaLocation=
"http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd


http://www.springframework.org/schema/context


http://www.springframework.org/schema/context/spring-context-3.0.xsd


http://www.springframework.org/schema/data/orcl

http://www.springframework.org/schema/data/orcl/spring-data-orcl-1.0.xsd">

    <orcl:pooling-datasource id="racDataSource"
        url="jdbc:oracle:thin:@(description=(address_list=
            (address=(host=rac1)(protocol=tcp)(port=1521))
            (address=(host=rac2)(protocol=tcp)(port=1521)))
            (connect_data=(service_name=racdb1)))"
        properties-location="classpath:orcl.properties"
        fast-connection-failover-enabled="true" 1
        ONS-configuration="rac1:6200,rac2:6200"/> 2

    <bean id="transactionManager" 
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="racDataSource"/>
    </bean>
</beans>

Ref: http://static.springsource.org/spring-data/jdbc/docs/current/reference/html/orcl.failover.html

TAF

  • This is possible only using Oracle OCI Thick Client.
  • The fail-over happens from within OCI driver.
  • The tnsnames.ora file has the necessary configuration for fail-over across nodes.
  • The failover is configured in tnsnames.ora file, the TAF settings are placed in CONNECT_DATA section of the tnsnames.ora using FAILOVER_MODES parameters.
  • Your datasource configuration (in tomcat or say in jboss oracle-ds.xml) remains same as what it would be to connect via OCI driver.
  • Only SELECT Queries can be retried in case of fail-over. DML (insert/update/delete) are not retried, instead Exception is thrown to the application.

Example Config:

TESTDB1 =
(DESCRIPTION =
(LOAD_BALANCE = ON)
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = TESTRAC1-VIP)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = TESTRAC2-VIP)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = testdb.easyoradba.com)
(FAILOVER_MODE = (TYPE = SELECT)(METHOD = PRECONNECT)(BACKUP=TESTDB2))
)
)

The FAILOVER_MODE can be: SESSION/SELECT/NONE

  • SESSION: Ideal for OLTP systems where transactions are small. In case of failover, a new session is automatically created for the user on the backup node.
  • SELECT: If the connection is lost, Oracle Net establishes a connection to another node and re-executes the SELECT statements with cursor positioned on the row on which it was positioned prior to the failover. This mode involves overhead on the client side and Oracle NET keeps track of SELECT statements. This approach is best for data warehouse systems, where the transactions are big and complex.
  • NONE: Default. Prevents failover.

 

Follow

Get every new post delivered to your Inbox.