Configure java3D lib Settings

Java is complaining because it cannot find the native libraries (the *.so files) on your system path that Java3D comes with. Exactly how you fix this is up to you. You can do anyone one of the following:

1) Make sure that your system path includes the *.so files provided with Java3D

2) Setup your LD_LIBRARY_PATH environment variable: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/”path-to-java3d-libraries”/

3) Set the java.library.path when executing java: java -Djava.library.path=$LD_LIBRARY_PATH:/usr/lib/”path-to-java3d-libraries”/

To be sure you have things set correctly, add the following to your Java code and make sure the path reported contains the shared libraries on it

System.out.println(“LD Library Path:” + System.getProperty(“java.library.path”));

| Leave a comment

Mahout and Hadoop – Run the Logistic Regression

classifier.sgd

# Check infor for help

$mahout org.apache.mahout.classifier.sgd.TrainLogistic –help
$mahout org.apache.mahout.classifier.sgd.RunLogistic –help

# Example of Training

# To train the model– model stored in donut.model, which is a json type file, to read the file better, try http://jsonviewer.stack.hu/

$mahout org.apache.mahout.classifier.sgd.TrainLogistic \
–passes 100 \
–rate 50 –lambda 0.001 \
–input /mahout_examples/donut.csv \

–features 21 \
–output /mahout_examples/donut.model \
–target color \
–categories 2 \
–predictors x y xx xy yy a b c –types n n

Then you should be able to get from the terminal:
Running on hadoop, using HADOOP_HOME=/usr/lib/hadoop
No HADOOP_CONF_DIR set, using /usr/lib/hadoop/conf
11/11/01 17:58:21 WARN driver.MahoutDriver: No org.apache.mahout.classifier.sgd.TrainLogistic.props found on classpath, will use command-line arguments only
21
color ~ 5.048*Intercept Term + 3.747*x + 4.530*y + -3.986*xx + 2.191*xy + -4.723*yy + 0.562*a + -0.580*b + -22.188*c
Intercept Term 5.04769
a 0.56192
b -0.57986
c -22.18806
x 3.74697
xx -3.98555
xy 2.19129
y 4.52954
yy -4.72268
-3.985546155 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 -0.579859597 4.529541855 0.000000000 0.000000000 0.000000000 -4.722678608 5.047685107 0.000000000 0.000000000 2.191286892 0.561916360 -22.188056574 0.000000000 0.000000000 3.746971894
11/11/01 17:58:22 INFO driver.MahoutDriver: Program took 858 ms

# To test the model
/usr/lib/mahout/bin/mahout org.apache.mahout.classifier.sgd.RunLogistic –help

$mahout org.apache.mahout.classifier.sgd.RunLogistic \
–input /mahout_examples/donut-test.csv \
–model /mahout_examples/donut.model –auc \
–scores –confusion

Running on hadoop, using HADOOP_HOME=/usr/lib/hadoop
No HADOOP_CONF_DIR set, using /usr/lib/hadoop/src/conf
11/11/02 10:35:27 WARN driver.MahoutDriver: No org.apache.mahout.classifier.sgd.RunLogistic.props found on classpath, will use command-line arguments only
“target”,”model-output”,”log-likelihood”
0,0.004,-0.003696
0,0.003,-0.002722
1,0.959,-0.042384
1,0.977,-0.023617
0,0.000,-0.000166
1,0.922,-0.081457
1,0.678,-0.388569
0,0.160,-0.174764
0,0.019,-0.019335
0,0.740,-1.348002
0,0.040,-0.040603
1,0.873,-0.135365
1,0.106,-2.242013
1,0.933,-0.069273
1,0.997,-0.003449
0,0.106,-0.112158
1,0.971,-0.029869
0,0.001,-0.001182
1,0.898,-0.107512
0,0.000,-0.000007
0,0.103,-0.108486
0,0.033,-0.034022
0,0.003,-0.003357
0,0.722,-1.281526
0,0.002,-0.002285
1,0.997,-0.002749
1,0.968,-0.032817
0,0.013,-0.013217
0,0.458,-0.613088
0,0.020,-0.019809
0,0.563,-0.827950
0,0.178,-0.195591
0,0.340,-0.416144
0,0.043,-0.043604
0,0.020,-0.020153
0,0.088,-0.091683
1,0.649,-0.432606
0,0.832,-1.786718
0,0.007,-0.006844
0,0.014,-0.014132
AUC = 0.96
confusion: [[23.0, 1.0], [4.0, 12.0]]
entropy: [[-0.2, -2.3], [-4.2, -0.2]]
11/11/02 10:35:28 INFO driver.MahoutDriver: Program took 312 ms

| Leave a comment

Configuring Tomcat To Use SSL

Step 1 – Creating the Keystore

The keys Tomcat will use for SSL transactions are stored in a password-protected file called, creatively, the “keystore.” The first step to enabling SSL on your server is to create and edit this file. You can create this file in one of two ways – by importing an existing key into the keystore, or by creating an entirely new key.

In the interest of simplicity, this guide will only cover the latter (but you can find instructions for importing keys on Apache’s Tomcat Documentation site).

A program called keytool, which is included with your JDK, will do the actual work of creating your new keystore. To create a new keystore using this program, enter the following command at the command-line, substituting syntax appropriate for your OS:

$JAVA_HOME/bin/keytool -genkey -alias [youralias] -keyalg RSA -keystore [/preferred/keystore/path]

Use an [alias] and [path] of your choice.

Next, keytool will ask you to enter the password you want to use for the keystore. Again, choose whatever you like (but don’t forget it).

After you choose the keystore password, you will enter the information required for the Certificate, such as your company and your name. Make sure this information is accurate, as you will have to submit this file to the Certificate Authority of your choice to obtain a certificate.

The last thing keytool will ask you to specify is the key password, which is the password specific to this specific certificates. Rather than enter anything at this prompt, just press ENTER.

This will cause keytool to set the key password to a value equivalent to the keystore password. Matching passwords are REQUIRED for Tomcat to access the certificate. If you choose two different passwords, any attempts to access the keystore will result in a crash (so don’t do it).

Congratulations – if you followed the directions correctly, you should now have a usable keystore file named [youralias], located in the directory you chose.

Step 2 – Creating the Certificate Signing Request

Now that you’ve created your keystore, it’s time to create a file called the Certificate Signing Request, or CSR, which will be used by the Certificate Authority of your choice to generate the Certificate SSL will present to other parties during the handshake.

You can use the keytool to create this file, as well. To do so, enter the following at the command line:

$JAVA_HOME/bin/keytool -certreq -keyalg RSA -alias [youralias] -file [yourcertificatname].csr -keystore [path/to/your/keystore]

Substitute the values you chose earlier for the [placeholders].

If you follow the instructions correctly, keytool will create a file called yourcertificatename.csr, which you can submit to the CA you’ve chosen via the process they provide on their website. Using this file, they will generate a custom certificate for your server, which you can download according to the instructions they provide on their website.

Step 3 – Installing Your New Certificate

Getting tired yet? Don’t worry – there’s light at the end of the tunnel. This is the last thing you’ll need to do to create a keystore for Tomcat to use. Well, the last two things. Hang in there!

SSL verifies the authenticity of a site’s certificate by using something called a “chain of trust,” which basically means that during the handshake, SSL initiates an additional handshake with the Certificate Authority specified in your site’s certificate, to verify that you haven’t simply made up your own CA.

In order to “anchor” your certificate’s chain of trust, you have to download an additional certificate, called a “Root Certificate,” from your CA, and then import both this certificate and your site’s new certificate into your keystore. Your CA should provide information about obtaining a Root Certificate on their website.

Once you’ve downloaded both your own Certificate and the Root certificate provided by your CA, import them into your keystore with the following commands, replacing the [placeholders]:

To import the Root Certificate -

keytool -import -alias root -keystore [path/to/your/keystore] -trustcacerts -file [path/to/the/root_certificate]

To import your new Certificate –

keytool -import -alias [youralias] -keystore [path/to/your/keystore] -file [path/to/your_keystore]

Do everything right? Then pat yourself on the back – you are now the proud owner of a functional, certified keystore.
PART II – Configuring Tomcat to use SSL

Now that we have a functional keystore populated with valid certificates, it’s time to configure Tomcat to use SSL. First, we’ll configure Tomcat’s SSL connectors, and then we’ll specify which webapps we want to use SSL by default.

Step 1 – Configuring Tomcat’s SSL Connectors

Tomcat’s global Connector options are configured in Tomcat’s main configuration file, “$CATALINA_BASE/conf/server.xml”, so you should open this file now. The Connectors we are looking for connect on port 8443 by default, so search for this port, until you come across an entry that looks like this:

<!–

–>

You’ll notice that the comment enclosing this connector talks about a choice between APR and JSSE configurations. This refers to the implementation of SSL you are intending to use. JSSE, which is Tomcat’s default configuration, is supported by default, and included in all JDKs after version 1.4. So if you don’t even know what APR is, you only need to uncomment this entry, and add some additional information to allow Tomcat to find your keystore:

If, on the other hand, you know that using the Apache Portable Runtime (APR), also known as Tomcat’s “native library,” is by far the best practice to follow, especially when using Tomcat as a standalone web server (which you probably are), and have already installed it on your server, then you’ll need to alter this entry as follows to allow Tomcat to use APR’s OpenSSL implementation in place of JSSE, or trying to use SSL will generate an error:

Notice that if you are using APR, the “SSLCertificateFile” and “SSLCertificateKey”-type attributes are used in place of the keystoreFile attribute. For more information on the differences between using APR in place of JSSE, consult Apache’s Tomcat APR Documentation.

Restart Tomcat. Once you’re up and running again, test your configuration by connecting to a secure page, using a URL such as https://[yourhost]:8443. If you followed the directions correctly, you should be able to view the page over a secure HTTPS connection!

Step 2 – Limiting SSL Usage

Enabling SSL in Tomcat’s server.xml file causes all files to be run both as secure and insecure pages, which can cause unnecessary server load. You can choose which applications offer SSL connections on a per-application basis by adding the following element to the application’s WEB-INF/web.xml file:

YourAppsName

/*

CONFIDENTIAL

This configuration allows you to set SSL options for all an application’s pages in one place. For example, to disable SSL for all your application’s pages, change “CONFIDENTIAL” to “NONE”.
Additional Considerations

In the interest of simplicity, this guide does not cover all of the elements of SSL configuration (although they are covered extensively in Apache’s Tomcat SSL Documentation). We will, however, provide you with a short list of other options and important areas of note to consider as you tweak your SSL configuration.
Specifying Implementation

If you have configured connectors for both APR and JSSE, Tomcat will use APR by default if you have installed the native libraries. You can force it to use JSSE by modifying a Connector’s “protocol” attribute as follows:

If you want to force APR, you can do so with a similar edit:

Common Errors Caused By Aliases and Passwords

If you encounter any errors with your SSL configuration, make sure that you have correctly entered settings such as keystore passwords and aliases. These values are case sensitive for some of the supported keystore formats.

| Leave a comment

Generate Random Series in java

import java.util.Random;

/** Generate random integers in a certain range. */
public final class RandomRange {

public static final void main(String… aArgs){
log(“Generating random integers in the range 1..10.”);

long START = 5412;
long END = 5422;
Random random = new Random();
for (int idx = 5412; idx aEnd ) {
throw new IllegalArgumentException(“Start cannot exceed End.”);
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd – (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("Generated : "+"984238"+idx +" Value = " + randomNumber);
}

private static void log(String aMessage){
System.out.println(aMessage);
}
}

| Leave a comment

Java Class File obfuscation

Step 1:
Unzip package proguard4.7.zip or proguard4.7.tar.zip

Step 2:
Pack all application needed java class files -create Zip/Jar File format

Step 3:
Go to proguard4.7/bin Directory

Step 4:
if you are using Linux machine Run command like this:

proguard4.7/bin$ ./proguardgui.sh

if you are using Windows Machine Run command like this:

proguard4.7/bin$ proguardgui.bat

| Leave a comment

Writing Your own Log Messages in java Logger

import java.io.*;
import java.util.logging.*;

public class QuintLog{
public static void main(String[] args) {
try{
FileHandler hand = new FileHandler(“vk.log”);
Logger log = Logger.getLogger(“log_file”);
log.addHandler(hand);
log.warning(“Doing carefully!”);
log.info(“Doing something …”);
log.severe(“Doing strictily “);
System.out.println(log.getName());
}
catch(IOException e){}
}
}

| Tagged | Leave a comment

Convert Set of Images into PPT Presentations Using Java

import java.util.*;
import java.sql.*;
import java.lang.Integer;
import java.text.DecimalFormat;
import java.io.FileInputStream;
import java.io.*;
import java.text.*;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;
import java.awt.Dimension;

import org.apache.poi.hslf.usermodel.SlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.model.Fill;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.model.TextBox;
//import org.apache.commons.codec.binary.Base64;
import org.apache.poi.hslf.HSLFSlideShow;

public class CreatePresentation
{

public DBConnection dbCon;
public Connection c;
public List finallist ;

public List arrList;

public List arrListBullet ;
public List arrListSpark ;

public Vector columnTypeCategorical;
public Vector columnTypeNumeric;

public String strCatFields=”";
public String strNumFields=”";

private SlideShow ppt;
private Slide slide;
private Fill fill;
private int idx;
private FileOutputStream out;

public Vector vcFileName1;

public int i=0;

public void ConnectDatabase()
{
dbCon = new DBConnection();
dbCon.ConnectDB();
c = dbCon.conn;
}

public CreatePresentation()
{
try
{
//create a new empty slide show
ppt = new SlideShow();
ppt.setPageSize(new Dimension(100,50));
out = new FileOutputStream(“/home/ashoka/Desktop/img/slideshow.ppt”);
CreatePresentations123();
}catch(Exception fnfe){}

}

//empty default constructor
public void CreatePresentations123()
{
try
{

//CreatePresentation present = new CreatePresentation();
//for(int k=0;k<SaveImg.vcFileName.size();k++)
for(int k=0;k<10;k++)
{
String tmp ="/home/ashoka/Desktop/img/img"+k+".jpg";
System.out.println(tmp);
createSlideWithChart(tmp);
}
//present.createSlideWithChart("NewSmooth.bmp");
savePPT();
}catch(Exception fnfe){}
}

public void createSlideWithChart(String chartName)
{
try
{
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
fill.setFillType(Fill.FILL_PICTURE);
idx = ppt.addPicture(new File(chartName), Picture.PNG);
fill.setPictureData(idx);
}catch(FileNotFoundException fnfe){}
catch(IOException ioe){}
}

public void savePPT()
{
try
{
ppt.write(out);
out.close();
}catch(FileNotFoundException fnfe){}
catch(IOException ioe){}
}

}

| Tagged | Leave a comment