Leaderboard1

Leaderboard2

Thursday, December 20, 2012

Tomcat: How to send the log messages to a File

Sometimes it's needed to send logs to separate file without mixing  them in server log files.. Thats makes it easy to understand & prevent disk overflow situation. We can use log4g.jar for this.

Log4j File Appenders – example for Logging messages to a file:
In most cases, either Rolling File Appender or Daily Rolling File Appender classes are used in production scenarios for logging messages into a file. A Rolling File Appender will send all the log messages to the configured file, until the file reaches a certain size. Once the log file reaches a maximum size, the current file will be backed up and a new log file will be created (thus the name Rolling File Appender). The Daily Rolling File Appender is also similar to Rolling File Appender except that the rolling happens at given frequency. Below is an example for using RollingFileAppender
  1. Add Log4j logging support to your project.
  2. In your log4j.properties file, add below lines:
    log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
    log4j.appender.rollingFile.File=D:/myapp/mylog.log
    log4j.appender.rollingFile.MaxFileSize=2MB
    log4j.appender.rollingFile.MaxBackupIndex=2
    log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
    log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
  3. As you can see from the above log4j  configuration, we are creating a new log4j appender in the name ofrollingFile and setting it’s options. I guess most of the options are self explanatory. The MaxBackupIndex tells the log4j to keep a maximum of 2 backup files for the log mylog.log. If the log file is exceeding theMaximumFileSize, then the contents will be copied to a backup file and the logging will be added to a new empty mylog.log file. From the above configuration, there can be a maximum of 2 backup files can be created.
  4. Next we need to direct our logs to go into this log4j appender.
    log4j.rootLogger = INFO, rollingFile
  5. That’s it. From now on, when you log something from your Java class, the log message will go into the mylog.log file.
 Copy this log4j.properties file in webcontent. Give its path in servlet class. See below one.

public void init(ServletConfig config) throws ServletException {
//1.
logger.info("XML_FetcherInitServlet is initializing log4j");
String log4jLocation = config.getInitParameter("log4j-properties-location");

ServletContext sc = config.getServletContext();

if (log4jLocation == null) {
System.err.println("*** No log4j-properties-location init param, so initializing log4j with BasicConfigurator");
BasicConfigurator.configure();
} else {
String webAppPath = sc.getRealPath("/");
String log4jProp = webAppPath + log4jLocation;
File log4jPropsFile = new File(log4jProp);
if (log4jPropsFile.exists()) {
System.out.println("Initializing log4j with: " + log4jProp);
PropertyConfigurator.configure(log4jProp);
} else {
System.err.println("*** " + log4jProp + " file not found, so initializing log4j with BasicConfigurator");
BasicConfigurator.configure();
}
}
logger.debug("RealPath" + sc.getRealPath("/"));
//3.
super.init(config);
}

If log4j.properties not found then default will be used by server..

Monday, December 17, 2012

How To Find Your Windows 7 Product Key

To Use "ProduKey" to See Product Key Number in Windows 7

NOTE: This option shows you how to use the free program ProduKey to see what the product key number is from within a Windows 7 that it has already been entered in (ex: activated). ProduKey will not show the product key number for Windows 7 Enterprise though.
1. Download, extract, and run the free ProduKey program.

2. You will now see Windows product key listed.
Product Key Number for Windows 7 - Find and See-produkey.jpg

Friday, December 14, 2012

Change Stack Overflow profile picture

Your Gravatar is an image that follows you from site to site appearing beside your name when you do things like comment or post on a blog. Avatars help identify your posts on blogs and web forums
It's tied to the gravatar that your Email address uses.
  • Go to Gravatar.com
  • create a profile and upload a picture.
  • Add that Email address to your Stack Overflow profile.
  • Wait a few hours for it to propogate.

Thursday, December 13, 2012

connecting Beanstalk java application to RDS

The security group for your RDS instance needs to be modified to allow connections from your Beanstalk instance(s). The beanstalk instance is using the elasticbeanstalk-default security. Please add a rule to your DB Security Group that allows connections from the elasticbeanstalk-default security group.

Connection timeout for DriverManager getConnection


You can set the Timeout on the Drivermanager like this:
 DriverManger.setLoginTimeout(10);
 Connection c = DriverManger.getConnection(url, username, password);
OR
String qqq = "jdbc:mysql://localhost/Test?connectTimeout=TIME_IN_MILLIS";
conn = DriverManager.getConnection(qqq, db_user, db_pass);

org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection


FTPClient uses 'active mode' by default, which is problematic as it requires FTP client to open a port for FTP server to connect back. Using a passive mode should circumvent this issue. After connecting and logging in, add the following line in your FTP code.
FTPClient ftp = new FTPClient();
// connect and login code here
ftp.enterLocalPassiveMode();
This should fix your problem.

Sunday, December 9, 2012

Access Amazon S3 Bucket using Java


SETUP

The following examples may require some or all of the following java classes to be imported:
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.List;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.util.StringUtils;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3ObjectSummary;

CREATING A CONNECTION

This creates a connection so that you can interact with the server.
String accessKey = "insert your access key here!";
String secretKey = "insert your secret key here!";

AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 conn = new AmazonS3Client(credentials);
conn.setEndpoint("objects.dreamhost.com");

LISTING OWNED BUCKETS

This gets a list of Buckets that you own. This also prints out the bucket name and creation date of each bucket.
List<Bucket> buckets = conn.listBuckets();
for (Bucket bucket : buckets) {
        System.out.println(bucket.getName() + "\t" +
                StringUtils.fromDate(bucket.getCreationDate()));
}
The output will look something like this:
mahbuckat1   2011-04-21T18:05:39.000Z
mahbuckat2   2011-04-21T18:05:48.000Z
mahbuckat3   2011-04-21T18:07:18.000Z

CREATING A BUCKET

This creates a new bucket called my-new-bucket
Bucket bucket = conn.createBucket("my-new-bucket");

LISTING A BUCKET’S CONTENT

This gets a list of objects in the bucket. This also prints out each object’s name, the file size, and last modified date.
ObjectListing objects = conn.listObjects(bucket.getName());
do {
        for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
                System.out.println(objectSummary.getKey() + "\t" +
                        ObjectSummary.getSize() + "\t" +
                        StringUtils.fromDate(objectSummary.getLastModified()));
        }
        objects = conn.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
The output will look something like this:
myphoto1.jpg 251262  2011-08-08T21:35:48.000Z
myphoto2.jpg 262518  2011-08-08T21:38:01.000Z

DELETING A BUCKET

Note
 
The Bucket must be empty! Otherwise it won’t work!
conn.deleteBucket(bucket.getName());

FORCED DELETE FOR NON-EMPTY BUCKETS

Attention
 
not available

CREATING AN OBJECT

This creates a file hello.txt with the string "Hello World!"
ByteArrayInputStream input = new ByteArrayInputStream("Hello World!".getBytes());
conn.putObject(bucket.getName(), "hello.txt", input, new ObjectMetadata());

CHANGE AN OBJECT’S ACL

This makes the object hello.txt to be publicly readable, and secret_plans.txt to be private.
conn.setObjectAcl(bucket.getName(), "hello.txt", CannedAccessControlList.PublicRead);
conn.setObjectAcl(bucket.getName(), "secret_plans.txt", CannedAccessControlList.Private);

DOWNLOAD AN OBJECT (TO A FILE)

This downloads the object perl_poetry.pdf and saves it in /home/larry/documents
conn.getObject(
        new GetObjectRequest(bucket.getName(), "perl_poetry.pdf"),
        new File("/home/larry/documents/perl_poetry.pdf")
);

DELETE AN OBJECT

This deletes the object goodbye.txt
conn.deleteObject(bucket.getName(), "goodbye.txt");

GENERATE OBJECT DOWNLOAD URLS (SIGNED AND UNSIGNED)

This generates an unsigned download URL for hello.txt. This works because we made hello.txt public by setting the ACL above. This then generates a signed download URL for secret_plans.txt that will work for 1 hour. Signed download URLs will work for the time period even if the object is private (when the time period is up, the URL will stop working).
Note
 
The java library does not have a method for generating unsigned URLs, so the example below just generates a signed URL.
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket.getName(), "secret_plans.txt");
System.out.println(conn.generatePresignedUrl(request));
The output will look something like this:
https://my-bucket-name.objects.dreamhost.com/secret_plans.txt?Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX&Expires=1316027075&A

Wednesday, December 5, 2012

Migrate database to Amazon RDS

Here i am migrating MySql database to Amazon RDS, Steps are the same for every database like SqlServer or oracle etc.. Sometimes [error 87] comes when migrating database tables containing data or records,, So to avoid it migrate empty tables...

Follow steps:

1) In MySql go to migrate option in database option and insert local database details, username = root and password = root if you have these one..









2) Insert target database host name , see in 3rd picture, end point is host name. Copy this from your Amazon console and paste it..


3) Now download RazorSQL , this is used to access remote database,

4) Create a conenction and connect to remote database.
5) Now insert your data into tables or update records..

You are done.. This approach is very handful b'coz sometimes while migrating data parameters are not adjustable and create problems..

Pls do comment on this and like this !


Android Books

Ways to Secure Your Computer System

If time were no object, we'd all live a more secure computer life—we'd beef up our browsers, use complex passwords, and keep our data locked up with encryption Skynet couldn't crack. But that kind of stuff requires obscure software, tricky command line work, and most of a free weekend, right? Nope. Anybody can feel more secure about their systems with the help of some free software and easy tweaks and add-ons. We've rounded up a good deal of these swift and simple security fixes for Windows, Mac, and Linux, so bust out the tinfoil hats and check 'em out after the jum.

Lock Down Firefox

Firefox is pretty secure in its own right, but its vast library of add-ons include a number of tools that can make it even tighter. Here's a few easy-to-use ways to lock down the fox:
  • Vidalia (original post): The Tor anonymity network isn't a fail-proof secrecy system, or a great way to quickly transfer lots of data, but the Tor setup tool Vidalia does make it a one-installation, one-button system for anonymizing your browsing on Windows, Mac, or Linux. In short: Tor won't defeat an intrepid IT manager, but it works pretty well for most situations.
  • SafeHistory & SafeCache: Prevent web sites from seeing where you came from and what you were looking at before you got there with these lightweight twin extensions.
  • Change settings for better privacy: It's not just nosy co-workers you don't want seeing what you do online, but also any over-the shoulder hackers or snoopers who strike while you're away from the keys.  Take some of Adam's advice and set Firefox to erase your private data on exit, stop keeping "address bar history," and enable a master password if you don't want to remember your legion of site logins. Here's more on locking down your autofilling web site logins with a single master password. Don't forget to set a timer to disable the Master Password accessibility if you tend to leave Firefox open when you walk away.
  • Always use https connections: Fans of Google's services might not know that almost every one of the search giant's tools offer a connection through SSL, the scrambled, harder-to-eavesdrop-on protocol than plain old HTTP. Can't seem to remember the "s"? Try thisGreasemonkey script, which can automatically make the switch for you at pre-defined sites.

Encryption made easy

When it comes to solid, dependable encryption on a hard disk or flash drive, nothing beatsTrueCrypt, now available in GUI form for Windows, Mac, and Linux, and it's not that hard to set up. Still, you don't need to set up system-wide encryption or virtual drives to ensure no nefarious third parties are looking at your communications:
  • Guest writer Jason Thomas showed us how to set up Thunderbird with encryption in four easy steps using the Enigmail extension.
  • The FireGPG Firefox extension employs selective encryption in the browser, including in GMail messages (as does the GMail Encrypt Greasemonkey script).
  • Multi-protocol, open-source, cross-platform instant messenging client Pidgin  (and its OS X cousin Adium) supports encryption through a one-button "Off the Record" plug-in. Windows users can grab it here, Adium chatters can learn how to enable encryption chatshere, and most Linux users can find plug-ins in their repositories (Ubuntu users, for example, can grabpidgin-otr).
  • If you just need to send a few documents securely to someone else, you could always compress and password-protect them with a zip utility like Lifehacker's favorite cross-platform tool 7-Zip.
  • For a file-by-file encryption solution in Windows, check out AxCrypt. It's still pretty beta in some ways, but the Big Bonus is adding encryption to Windows' right-click menu—doesn't get much easier than that.

Make strong but memorable passwords

The heart of any secure computer lies in its passwords—from commonly-used web passwords down to ultra-paranoid stuff like BIOS locking. If you find yourself resorting all too often to birthdays and pet names, check out the following resources:
  • If you're the type of person who writes their passwords down, like security expert Bruce Schneier, it never hurts to have at least one ultra-secure master password. For that, look no further than the Ultra High Security Password Generator—you can just use 6-10 of the totally random characters, unless you feel up for memorizing more than 60 of them.
  • Once you've got that uber-tight password, feel free to use it for your Windows/Mac/Linux login password or your multi-app keychain program, and then pick more basic, easy-to-grok passwords for web sites and the like, as suggested by a recent Macworld article. With the auto-suspend/lockout features in many systems, having a single, secure gateway into your data makes sense.
  • It won't work for every site, but getting set up with an OpenID could give you fewer passwords to keep track of and faster access to you favorite sites.
  • If you must write down your passwords, don't do it on a monitor Post-It note or even a plain text file. Here's how to securely track your passwords in an encrypted desktop database, KeePass.
  • Low-Hassle Ways to Secure Your Computer SystemMade your passwords so secure that you forgot one? Don't worry—we've got you covered for Firefox, in software and web pages, and at user login too, using an OphCrack Live CD.

Bolt down your network

Unfortunately, there aren't a lot of shortcuts to the basics of setting up a decently secure home wireless network—setting an SSID, WPA encryption, and MAC filters are just part of the (acronym-crazy) game. Going forward, though, you can make sure the computers in your home or small office are safe without weekend-consuming projects:
  • We've shown you the extensive way of scanning for port security holes, but here's a much easier tool for novices— the Audit My PC online firewall test. I highly doubt it catches everything and hands out extensive troubleshooting help, but for just knowing what should and shouldn't be accessible to the outside world it is worth the price of admission.
  • For networking n00bs looking for a little GUI-fied help, check out the free version ofNetwork Magic, which can help move you through the basics.
  • If you're not behind a router or physical/corporate firewall, be sure to turn on your operating system's firewall (not enabled by default, for instance, in OS X Leopard) andmake it secure.

Lojack your laptop (and USB drives)

All the best proxies, lock-downs and passwords will only help you so much if your whole system ends up in a thief's hands. Here's how to secure, and possibly even locate, your lost goods with free tools:
  • iPods digital cameras and USB drives are appealing, easy-to-grab targets for thieves—believe me, I know. GadgetTheft, a free auto-run trick that you can install on any device that you can transfer a file to, will send you as much information as it can grab from a computer once you've turned on tracking. iHound, a free USB-drive-only tool, works in a similar way, but actually sends rough geo-location info based on the IP address of its captive users' computer.
  • A dedicated thief might not let some wailing laptop speakers stop his crime, but you can help keep coffee shop patrons honest with tools like iAlertU for the Mac andLaptop Alarm for PCs. Both can make a racket—or evensnap a few incriminating pictures—if they detect something fishy going on.
  • Windows users have their own webcam-into-security-cam tool in Yawcam, which can even be set to send regular photos to an FTP server.