Posts

Redirect StdErr to Stdin in Batch and Shell Scripts

On windows command prompt : mybatch.bat 1> log.txt 2>&1 This redirects stdin to log.txt and stderr to stdin On Bash Linux Shell: grep * &> allout.txt

Get Remote IP Address In Axis SOAP Server

Obtain remote IP from ServletRequest (Axis 1.0 only) import javax.servlet.http.HttpServletRequest; import org.apache.axis.MessageContext; import org.apache.axis.transport.http.HTTPConstants; public static String getSOAPRemoteIP() { MessageContext context = MessageContext. getCurrentContext (); String address = null ; if (context!=null && context.containsProperty(HTTPConstants. MC_HTTP_SERVLETREQUEST )) { HttpServletRequest servletReq = (HttpServletRequest) context.getProperty(HTTPConstants. MC_HTTP_SERVLETREQUEST ); if (servletReq != null ) address = servletReq.getRemoteAddr(); } return address; }

Google Chrome Ready For Download

Google has released a new browser named Google Chrome. This browser is expected to become most widespred computer program ever written. Google Chrome will set the standarts for Web2.0 and Web3.0 technologies. Chrome is a ligtweight browser and does not consume your CPU and memory and it makes Chrome fast and reliable. Download Here Here is a gread comic book for chrome on googlebooks site At first impression Google Chrome is not working properly with PHP-Admin !!!

Console Beep On Error Line of a Log File

Ok folks , this is non-java :) Today I had to watch a log file and alert some ppl when an error phrase seen on log file. This is a terrible jıb todo. First I run on my linux server: #tail -f mylogfile | grep ERRORSTRING this worked but put me in front of the screen. Why not my console beep when ERRORSTRING exists in the log file ? I need an application to beep when read a line from stdin. This is piece of cake in java but i did not want to load JVM for this purpose because of memory needs. So I warped to good old days and decided to write a C program to do this job. #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char *argv[]) { char buf[1024]; int n; while (fgets(buf, sizeof buf, stdin) != NULL) { n = strlen(buf); if (n > 0 && buf[n-1] == '\n') { printf("\a"); printf("%s\n", buf); ...

Using Java Properties File

Many programmers use properties files for keeping configuration parameters (DB Server IP etc.) Here is a sample class code for accessing configuration parameters from a properties file. You can pass JVM parameter like this : java -DMyPropertiesFile=/usr/local/java/proj/myconfig.properties MyClass package javacream; import java.io.InputStream; import java.util.Properties; public class AppProperties { private static Properties prop; static { initiate(); } protected static void initiate() { try { //Pass Java VM following arguement // -DMyPropertiesFile="[PATH]/[PROPERTIESFILENAME]" prop = new Properties(); String propertiesFile = System.getProperty("MyPropertiesFile"); if (propertiesFile == null) { System.out .println("Could not find content.properties property in System Properties."); System.out .println("This property file is needed for the application to operate."); System.out .println("Se...

Java MD5 Hash Sample

MD5 (Message Digest) is an encryption algorithm that creates a unique hash from a given data which is completely reverseble. This means you cannot recalculate original data using its hash , and hash is universally unique. Here is a sample code that produces MD5 hash of a given string : package javacream ; import java.security.MessageDigest ; import java.security.NoSuchAlgorithmException ; public class MD5HashTest {     private static String getMD5Digest ( String str ) {         try {             byte [ ] buffer = str. getBytes ( ) ;             byte [ ] result = null ;             StringBuffer buf = null ;             MessageDigest md5 = MessageDigest . getInstance ( "MD5" ) ;             //allocate room for the hash ...

Java HTPPS SSL Client

HTTPS secure HTTP connection , HTTP over secure socket layer (SSL). To establish an HTTPS connection to a remote server , you should use the certificate obtained by the server. This certificate is validated using a local trust store. Default trust store is /lib/security/cacerts. You can define another trust store using keytool application in /bin. Certificates can be added to trust store with keytool application also. You should give trust store parameter to JVM like this : -Djavax.net.ssl.trustStore=/mypath/my.keystore -Djavax.net.ssl.trustStorePassword=mypassword Here is the sample code to create an HTTPS connection: package javacream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URLEncoder; import java.security.Security; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class HTTPSClient { public static void main(String[] args...