We use Nutch2 to crawl our internal documentation site, and save index to Solr. We noticed that if the title is too long (longer than 100 characters), the title would be truncated to the frist 100 chracters.
For example:
The original title is:
Getting Started -….(omit 62 characters) Firewall for Windows File System
In solr search result, the title would be:
Getting Started -….(omit 62 characters) Firewall for Wi
This is bad for the user experience. We want to save entire title to Solr.
How Nutch Works?
In parsing phrase, Nutch gets the entire title:
org.apache.nutch.parse.html.DOMContentUtils.getTitle(StringBuilder, Node)
org.apache.nutch.parse.html.HtmlParser.getParse(String, WebPage)
utils.getTitle(sb, root); // extract title
title = sb.toString().trim();
Parse parse = new Parse(text, title, outlinks, status);
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
But in indexing phrase, in BasicIndexingFilter, it will only crawl the first X characters of title. X is defined by property indexer.max.title.length.
org.apache.nutch.indexer.basic.BasicIndexingFilter
It will read property indexer.max.title.length from nutch-default.xml or nutch-site.xml. The value in nutch-site.xml will overwrite the one in nutch-default.xml.
public void setConf(Configuration conf) { this.conf = conf; this.MAX_TITLE_LENGTH = conf.getInt("indexer.max.title.length", 100); LOG.info("Maximum title length for indexing set to: " + this.MAX_TITLE_LENGTH); } public NutchDocument filter(NutchDocument doc, String url, WebPage page) throws IndexingException { String title = TableUtil.toString(page.getTitle()); if (title.length() > MAX_TITLE_LENGTH) { // truncate title if needed title = title.substring(0, MAX_TITLE_LENGTH); } if (title.length() > 0) { doc.add("title", title); } }
The default value of indexer.max.title.length is 100, as defined in nutch-default.xml.
<property> <name>indexer.max.title.length</name> <value>100</value> <description>The maximum number of characters of a title that are indexed. Used by index-basic. </description> </property>
The Solution
Now the fix is straightforward, we can define indexer.max.title.length to a larger value in nutch-site.xml such as indexer.max.title.length=500.
Misc
Nutch includes many indexer plugin such as index-(basic|static|metadata), which add some field name and value pairs. We can check all added fields by opening call hierarchy on method: org.apache.nutch.indexer.NutchDocument.add(String, String).
Resources
nutch-default.xml
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/nutch2-save-entire-title-to-solr.html
Commonly Used Windows PowerShell Commands- From http://lifelongprogrammer.blogspot.com/
23 Monday Dec 2013
Posted Uncategorized
inBut sometimes, we have to work on Windows, and not able to install cygwin.
Luckily, Microsoft provides PowerShell, and it’s integrated with Win7, Windows Server 2008 R2 and later Windows release.
Power Shell is cool and useful, it’s different from Linux’s Shell, as it’s completely object-oriented.
Extract lines from files
Get first 10 lines as head -10 in linux
Get-Content -Path my.csv -TotalCount 10
Get last 10 lines as tail -10 in Linux
Get-Content -Path my.csv | Select-Object -Last 10
Get-Content -Path my.csv | Select-Object -Index(10)
Get the 10th to 100th lines
Get-Content -Path my.csv | Select-Object -Index(10..100)
Get 10th and 100th lines
Get-Content -Path my.csv | Select-Object -Index(10, 100)
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
Search recursively for a certain string within files
Get-ChildItem -Recurse -Filter *.log | Select-String Exception
Get-ChildItem -Recurse -Filter *.log | Select-String -CaseSensitive -Pattern Exception
Tail -f in PowerShell
Get-Content error.log -wait | Where-Object { $_ -match “Exception” }
-match is case-insensitive. -cmath is case-sensitive.
Find the five processes using the most memory
Get-Process | Sort-Object -Property WS -Descending | Select-Object -First 10
Delete all files within a directory
Remove-Item foldername -Recurse
Rename all .TXT files as .LOG files in the current directory:
Get-Childitem -Path *.txt | rename-item -NewName {$_.name -replace “.txt”,”.log”}
Miscs
Restart-Computer –Force –ComputerName TARGETMACHINE
Run a script on a remote computer
invoke-command -computername machine1, machine2 -filepath c:\Script\script.ps1
Using Get-WmiObject
List all WMI classes:
Get-WmiObject -List
Get-WmiObject -Class Win32_ComputerSystem
Get-WmiObject -Class Win32_BIOS -ComputerName .
gwmi win32_service -filter “name like ‘Oracle%'” | select name
gwmi win32_service -filter “startmode=’auto'” | select name,startmode
(gwmi win32_service -filter “name=’alerter'”).StopService()
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/commonly-used-windows-powershell-commands.html
A Complete DNS Setup Guide on Redhat(CentOS)- From http://lifelongprogrammer.blogspot.com/
17 Tuesday Dec 2013
Posted Uncategorized
inWhen install cloudera cluster recently, I have to setup a private DNS server.
Environment
Private DNS server: 172.19.97.224(bigdatam.localdomain.com)
DNS client: 172.19.101.66(bigdata1.localdomain.com) and 172.19.102.56(bigdata2.localdomain.com.
Install bind and caching-nameserver
yum install bind bind-utils bind-libs bind-chroot caching-nameserver -y
Run service named restart to start named server first.
Configure DNS Server
Enable Caching nameserver and Create Zones
Edit /var/named/chroot/etc/named.conf:
1. Use forwarders block to forward DNS requests it can’t resolve to upstream DNS server.
2. Add forward and reverse zones block for localdomain.com and 19.172.in-addr.arpa.
3. Add forward and reverse zones block for locahost and 0.0.127.in-addr.arpa.
vi /var/named/chroot/etc/named.conf
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
acl localdomain-com { 172.19/16; }; options { directory "/var/named"; allow-query { localdomain-com; }; # The block will cause the caching name server to forward DNS requests it can't resolve to upstream DNS server. forwarders { upstream-dns-server1; upstream-dns-server2}; #forward only; }; zone "localdomain.com" IN { type master; file "localdomain.com.zone"; }; zone "19.172.in-addr.arpa" IN { type master; file "172.19.zone"; }; zone "locahost" IN { type master; file "localhost.zone"; allow-update{none;}; }; zone "0.0.127.in-addr.arpa" { type master; file "named.local"; }; zone "." { type hint; file "named.ca"; };
Add Zone files
Go to /var/named/chroot/var/named directory, create files: localdomain.com.zone and 19.172.in-addr.arpa.
cd /var/named/chroot/var/named
touch localdomain.com.zone && chown named:named localdomain.com.zone && chmod 644 localdomain.com.zone
touch 19.172.in-addr.arpa && chown named:named 19.172.in-addr.arpa && chmod 644 19.172.in-addr.arpa
vi localdomain.com.zone
$TTL 1D $ORIGIN localdomain.com. @ IN SOA bigdatam.localdomain.com. foo.bar.tld. ( 200612060 ; serial 2H ; refresh slaves 5M ; retry 1W ; expire 1M ; Negative TTL ) @ IN NS bigdatam bigdatam IN A 172.19.97.224 bigdata1 IN A 172.19.101.66 bigdata2 IN A 172.19.102.56
vi 172.19.zone
$TTL 1D $ORIGIN 19.172.IN-ADDR.ARPA. @ IN SOA bigdatam.localdomain.com. foo.bar.tld. ( 200612060 ; serial 2H ; refresh slaves 5M ; retry 1W ; expire 1M ; Negative TTL ) IN NS bigdatam.localdomain.com. 224.97 IN PTR bigdatam.localdomain.com. 66.101 IN PTR bigdata1.localdomain.com. 56.102 IN PTR bigdata2.localdomain.com.
localhost.zone, named.local and named.ca are already in /var/named/chroot/var/named, they are created automatically, we just need refer them in /var/named/chroot/etc/named.conf.
Restart named server
service named restart
chkconfig named on
Reload configuration and zones
rndc reload
Toggle query logging
rndc querylog
Sometimes, we need disable SELinux and firewall
Disable SELinux
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
Disable firewall
/etc/init.d/iptables stop
chkconfig iptables off
Configure DNS Client
Do following steps in all 3 servers.
Prevent /etc/resolv.conf get overwritten
/etc/sysconfig/network-scripts/ifcfg-eth0 (replace eth0 with your network interface if different) and change PEERDNS=yes to PEERDNS=no
Setup DNS Name resolution
vi /etc/resolv.conf
search localdomain.com
nameserver 172.19.97.224 # the private dns server ip address.
Restart network
/etc/init.d/network restart
Test DNS Setup
Run nslookup to start a session, and run the folloiwng command in all hosts.
# nslookup
> 127.0.0.1 Server: 172.19.97.224 Address: 172.19.97.224#53 1.0.0.127.in-addr.arpa name = localhost. > localhost Server: 172.19.97.224 Address: 172.19.97.224#53 Non-authoritative answer: Name: localhost Address: 127.0.0.1 > bigdatam Server: 172.19.97.224 Address: 172.19.97.224#53 Name: bigdatam.localdomain.com Address: 172.19.97.224 > bigdata1 Server: 172.19.97.224 Address: 172.19.97.224#53 Name: bigdata1.localdomain.com Address: 172.19.101.66
dig bigdaam
host -v -t A `hostname
vi /etc/hosts
127.0.0.1 localhost.localdomain localhost
Resources
How to set up a home DNS server
How to set up a home DNS server, part II
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/a-complete-dns-setup-guide-on-redhat-centos.html
Using Decompiler JDEclipse-Realign to Debug Classes without Source in Eclipse- From http://lifelongprogrammer.blogspot.com/
17 Tuesday Dec 2013
Posted Uncategorized
inLuckily, we can use JDEclipse-Realign to easily debug classes without sources in Eclipse.
1. Install and Configure JDEclipse-Realign in eclipse
Install via JDEclipse-Realign update site http://mchr3k-eclipse.appspot.com/.
Click “Window” -> “Preferences”, type “File Association”. Select “class without source”, in the dialogue below,select “Class File Viewer [Decompiled]” as default.
2. Find jars contained classes which we want to debug
In linux, Use grep -r -s full_class_name * to find the jar.
3. Create a java project with the jars
Create a java project in Eclipse, add the jar(related jars) into the project’s build path.
Now if we right click on the jar, select “Attach Source”, we can see “Decompiled Source” is selected..
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
4. Enable remote debug
Add the -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y in JVM options to remote java application.
Then configure Eclipse for remote debugging by click “Run” -> “Debug Configuration”, then create a new “Remote Java Application”, enter the host, and port number: 1044 in this case, be sure to slect the previously-created project in project textbox.
Other tools
JD-GUI from http://jd.benow.ca/
Resources
Mchr3k – JDEclipse-Realign
JDEclipse-Realign Github
JD-GUI
Advanced Usage of Linux Grep Command- From http://lifelongprogrammer.blogspot.com/
16 Monday Dec 2013
Posted Uncategorized
ingrep -r “127” /etc
Use grep to search words only: -w, –word-regexp
Select only those lines containing matches that form whole words
grep -w “boo” file
-s, –no-messages
Suppress error messages about nonexistent or unreadable files.
Ignore binary files: -I
When we search, we may only want to search text files and ignore binary files for better performance. we can use: -I.
-I Process a binary file as if it did not contain matching data; this is equivalent to the –binary-files=without-match option.
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
Combine grep and find
grep “some_string” `find some_folder -name “*.some_extension”`
find . -name “*.php” -exec grep -H “some_string” {} \;
Find jars that contain matched classes
Grep can be used to find the jar that contains the matched class fileL
grep -r com.cloudera.cmf.inspector.Inspector /usr/share/cmf/lib
Miscs
-c, –count
Suppress normal output; instead print a count of matching lines for each input file
-n, –line-number
-h, –no-filename
-H, –with-filename
-v, –invert-match
–color[=WHEN], –colour[=WHEN]
grep –color root /etc/passwd
Resources
Grep Manual
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/advanced-usage-of-linux-grep-command.html
Linux Mount and Unmout Remote File System- From http://lifelongprogrammer.blogspot.com/
16 Monday Dec 2013
Posted Uncategorized
insudo mkdir /mnt/ip-shared
Mount a windows shared folder
mount //server-name/share-name /mnt/ip-shared -o username=shareuser,password=sharepassword,domain=sharedomain
Here, -o is used top specify mount options, in this case, we specify the login credential: username, password, and domain . Its format can be -o username=sharedomain/shareuser,password=sharepassword
Here we don’t use -t to specify vfstype, thus mount will try to guess the desired type. Check the list here at mount Manual.
If
Common Mount Options
loop Mounts an image as a loop device.
ro Mounts the file system for reading only.
rw Mounts the file system for both reading and writing.
Unmount it
If we don’t need to access the remote file system, we can use umount to unmount it: Notice, it’s umount, not unmount.
umount /mnt/ip-shared
Resource
Linux Mount Manual
Linux mount CIFS Windows Share
via Blogger
Using Chrome DevTools to Hack Client-Side Only Validation – From http://lifelongprogrammer.blogspot.com/
12 Thursday Dec 2013
Posted Uncategorized
inAs user can easily bypass the validation, change value of javascript object using tools like Chrome DevTools or Firebug. We must always appropriate server-side validation as well.
Using Chrome DevTools to Hack it
One website limits the max value of one field, and I am wondering whether I can bypass the verification.
1. Found the pattern
I noticed that when I input invalid value, and go to next field, it will change the color of the field to red.
2. Beak on DOM Attributes Modifications
So when the color of the field changes, I want Chrome to stop at that moment, so I can figure out how this website do the verification.
So I right click the input textbox, click “Inspect Element”, this will open Chrome DevTools, and select the checked element in “Elements” tab.
<input title=”” class=”input_field_” type=”text” name=”Memory” id=”memory”>
Right click it, and select “Break on…” -> “Attributes modifications”.
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
This will cause Chrome pauses when attribute of this input textbox changes.
It would be better if Chrome DevTools allows us to stop when a particular attribute changes, in this case: class field. or even better to stop when a particular attribute changes to a particular value. But anyhow this works.
3. Reproduce It
Now input the invalid value, then trigger the event that will cause the client side validation. Usually this will happen when we focus leaves current field or we click next or submit.
This will cause Chrome stops execution, and switch to “Sources” tab and stops at the code that change
4. Check the Call Stack
Now we can check the call stack.
To make javascript much easier to read, we can press the “Pretty print” button (marked with curly braces{}) from the bottom of the “Sources” tab.
Follow the call stack, I found it do verification like below:
function validateSteps(step) { var isStepValid = true; // omitted if (step == step_config) { return validateField('#memory', selectedPolicy.minMemory, selectedPolicy.maxMemory) &&...); } return isStepValid; // we can set a breakpoint value here to change isStepValid to true. }
The code compare the value from memory textbox with selectedPolicy.minMemory, selectedPolicy.maxMemory.
5. Hack it
Now there are several ways to hack it: we can step into validateField method and change return value.
The simpler way is to directly modify the object selectedPolicy, change maxMemory to a much bigger value. We go to the “Console” tab, and type selectedPolicy.maxMemory, this will print current value, it’s 4. We can type selectedPolicy.maxMemory=100.
Now unclick all breakpoints, and press resume, and submit the form. It works, this site doesn’t check the value in server side at all.
Later if I want to so the same trick: bypass the verification, I can go to “Console” tab directly, and type selectedPolicy.maxMemory=100.
In Console tab, we can do many things, run any valid javascript code in current scope.
We can check windows object, and detect any custom properties and functions.
Happy Hacking!!!
Resources
Tips And Tricks
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/using-chrome-devtools-to-hack-client-only-verification.html
Using Guava Splitter and Joiner- From http://lifelongprogrammer.blogspot.com/
12 Thursday Dec 2013
Posted Uncategorized
inIf we have to write our own code, the code would look like below:
public void splitOnOurOwn() { String mapStr = "topic: title, url: link, description: description "; String[] pairs = mapStr.split(","); Map<String,String> map = new HashMap<String,String>(); for (String pair : pairs) { String[] str = pair.split(":"); map.put(str[0].trim(), str[1].trim()); } System.out.println("toString: " + Objects.toString(map)); }
But if we use Guava it would be just two lines:
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
private static MapSplitter splitter = Splitter.on(",").trimResults() .withKeyValueSeparator(Splitter.on(':').trimResults()); private static MapJoiner joinner = Joiner.on(",").withKeyValueSeparator(":"); public void guavaSplit() { String mapStr = "topic: title, url: link, description: description "; Map<String,String> map = splitter.split(mapStr.trim()); System.out.println("toString: " + Objects.toString(map)); System.out.println("join: " + joinner.join(map)); }
Guava Splitter provides some other useful methods such as fixedLength, omitEmptyStrings, trimResults, limit.
As described in code above, Guava provides a Joiner that can join text with a separator. Joiner also provides useful methods such as skipNulls, useForNull(nullText).
Resources
Strings Explained
Splitter Javadoc
Joiner Javadoc
Guava Splitter vs StringUtils
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/using-guava-splitter-and-joiner.html
Configure Tomcat SSL Using PFX(PKCS12) Certificate- From http://lifelongprogrammer.blogspot.com/
06 Friday Dec 2013
Posted Uncategorized
inEntrust provides a pfk file to us. pfx means Personal Information Exchange, it stores many cryptography objects as a single file. Read more about PKCS #12
To import the pfx(PKCS_12) to tomcat or other java web server, the easy solution is to convert the pfx(PKCS_12) file to Java Key Store file.
1. Using keytool
Since JDK6, we can use JDK keytool to convert pkcs12 to JKS.
keytool -importkeystore -srckeystore file.pfx -srcstoretype PKCS12 -destkeystore cert.jks -deststoretype JKS
2. Using XWSS
For older JDK, we can use XWSS utility to convert pkcs12 to JKS.
XWSS – XML and WebServices Security Project is part of Project Metro in the Glassfish community. It provide some utility that can be downloaded from here.
Download the pkcs12import.zip, unzip it, we can find pkcs12import.bat.
pkcs12import usage
pkcs12import -file pkcs12-file [ -keystore keystore-file ]
[ -pass pkcs12-password ] [ -storepass store-password ] [ -keypass key-password ] [ -alias alias ]
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
Add SSL Connector in server.xml
Restart tomcat, and try to access https://localhost/
Resources
Keytool
PKCS 12 Wiki
Converting .pfx Files to .jks Files
How to import PFX file into JKS using pkcs12import utility
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/configure-tomcat-ssl-using-pfx-pkcs12-certificate.html
Using Guava Stopwatch- From http://lifelongprogrammer.blogspot.com/
05 Thursday Dec 2013
Posted Uncategorized
inI have a doubt about the performance difference between the one uses regular expression ltrim and the straightforward ltrim3. So I use Guava topwatch
to test their performance.
Guava Usage
1. Use Stopwatch static factory method to create one instance.
Stopwatch stopwatch = Stopwatch.createStarted()
2. Use stopwatch.elapsed(TimeUnit) to get elapsed time.
3. We can reuse same stopwatch instance to measures another operation, but we have to first call reset(), and start().
reset() method would reset internal variable: elapsedNanos=0, isRunning=false. Calling start() would start again to measure time elapsed.
Conclusion
The test result is as what I expected, the straightforward one gives the best performance.
458 for ltrim3(the straightforward one)
3967 for ltrim(using regular expression)
//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
} else {
if (window.CHITIKA === undefined) {
window.CHITIKA = { ‘units’ : [] };
};
var unit = {
‘publisher’ : “jefferyyuan”,
‘width’ : 728,
‘height’ : 90,
‘type’ : “mpu”,
‘sid’ : “Chitika Default”,
‘color_site_link’ : “FFFFFF”,
‘color_title’ : “FFFFFF”,
‘color_border’ : “FFFFFF”,
‘color_text’ : “4E2800”,
‘color_bg’ : “F7873D”
};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(“
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘http://scripts.chitika.net/getads.js’;
try {
document.getElementsByTagName(‘head’)[0].appendChild(s);
} catch(e) {
document.write(s.outerHTML);
}
}
//]]>
The code looks like below:
import com.google.common.base.Stopwatch; public class LTrimTester { private final static Pattern LTRIM = Pattern.compile("^\\s+"); private final static Pattern RTRIM = Pattern.compile("\\s+$"); public static void main(String[] args) { int times = 10000000; Stopwatch stopwatch = Stopwatch.createStarted(); for (int i = 0; i < times; i++) { String str = " hello world "; ltrim(str); } System.out.println(stopwatch.elapsed(TimeUnit.MILLISECONDS) + " for ltrim(using regular expression)"); stopwatch.reset(); stopwatch.start(); for (int i = 0; i < times; i++) { String str = " hello world "; ltrim3(str); } System.out.println(stopwatch.elapsed(TimeUnit.MILLISECONDS) + " for ltrim3(the straightforward one)"); stopwatch.stop(); } public static String ltrim(String s) { return LTRIM.matcher(s).replaceAll(""); } public static String ltrim3(String s) { int i = 0; while (i < s.length() && Character.isWhitespace(s.charAt(i))) { i++; } return s.substring(i); } }
Resources
TRIM, LTRIM and RTRIM in Java
Guava Stopwatch Javadoc
Guava Stopwatch
via Blogger http://lifelongprogrammer.blogspot.com/2013/12/using-guava-stopwatch.html