Advance ZIP example – Recursively

Advance ZIP example – Recursively Read all files from folder “C:\\testzip” and compress it into a zip file – “C:\\MyFile.zip“. It will recursively zip a directory as well. package com.mkyong.zip; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class AppZip {     List<String> fileList;  …

Read More

FTP Upload

String ftpUrl = "ftp://%s:%s@%s/%s;type=i"; String host = "www.myserver.com"; String user = "tom"; String pass = "secret"; String filePath = "E:/Work/Project.zip"; String uploadPath = "/MyProjects/archive/Project.zip"; ftpUrl = String.format(ftpUrl, user, pass, host, uploadPath); System.out.println("Upload URL: " + ftpUrl); try { URL url = new URL(ftpUrl); URLConnection conn = url.openConnection(); OutputStream outputStream = conn.getOutputStream(); FileInputStream inputStream = new…

Read More

MapDB example

Simple MapDB example program   package org.ragin.mapdb; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.mapdb.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import java.util.concurrent.ConcurrentMap; /** * Hello world! * */ public class MapDBInformant {     public static final String MAPDBINFORMANT = "MapDBInformant";     public static final String CFG_LOG4J_PROPERTIES…

Read More

Log4J Logging with categories

Procedure Create the following directories: c:\demo c:\demo\com c:\demo\com\mobilefish c:\demo\com\mobilefish\bean Create the file c:\demo\com\mobilefish\bean\Message.java. package com.mobilefish.bean; import org.apache.log4j.Logger; public class Message { Logger log = Logger.getLogger("com.mobilefish.bean.Message"); private String msg; public void setMessage(String msg) { this.msg = msg; log.debug("This is my debug message."); log.info("This is my info message."); log.warn("This is my warn message."); log.error("This is my error…

Read More

Create Java Classes from WSDL

Using Axis: echo on set CP=e:\dev\axis\lib\ set CLASSPATH=%CP%axis.jar;%CP%log4j-1.2.8.jar;%CP%commons-logging-1.0.4.jar;%CP%commons-discovery-0.2.jar;%CP%jaxrpc.jar;%CP%wsdl4j-1.5.1.jar echo CLASSPATH is %CLASSPATH% java org.apache.axis.wsdl.WSDL2Java -o ../src/java ISpaix4Pumps.xml REM java org.apache.axis.wsdl.WSDL2Java -o fromURL http://prevservice.wilo-select.com/service/s4pumps.dll/wsdl/ISpaix4Pumps java org.apache.axis.wsdl.WSDL2Java -o ../src/java/copy http://prevservice.wilo-select.com/service/s4pumps.dll/wsdl/ISpaix4Pumps   Using Eclipse: In Eclipse Kepler it is very easy to generate Web Service Client classes,You can achieve this by following steps . RightClick on any Project->Create…

Read More

Need only one new Logfile appender..

boolean inspectorAppenderWasFound = false; for (Enumeration appenders = logger.getAllAppenders(); appenders.hasMoreElements(); ) { Appender appender = (Appender) appenders.nextElement(); String currentAppName = appender.getName(); if (currentAppName.equalsIgnoreCase(INSPECTOR_FILE_LOGGER )) inspectorAppenderWasFound = true; } if (inspectorAppenderWasFound == false) { // was not created before FileAppender fa = new FileAppender(); fa.setName(INSPECTOR_FILE_LOGGER); fa.setFile(LOGFILE_PATH); fa.setLayout(new PatternLayout(LOGFILE_PATTERN)); fa.setThreshold(Level.DEBUG); fa.setAppend(true); fa.activateOptions(); logger.addAppender(fa); }

Read More

How to determine which jar a class is loaded from?

Did you ever encounter an runtime exception saying a method not found? How can the code compile if the method is not defined? Or after you made some changes to the code, you don't see it takes effect, even after you clean built, and redeploy for a couple of times? When these situations occurs, besides…

Read More

resource-env-ref vs. resource-ref

DD Elemente, die Referenzen auf Resourcen oder EJB Resourcen darstellen sind: <ejb-ref>: Erzeugt einen Alias für eine Bean <resource-ref>: Referenz zu Resource Manager, geliefert werden funktionierende Connections,  z.B. javax.sql.DataSource <resource-env-ref>: Referenz zu Umgebungs-Informationen, mit deren Hilfe Connections erzeugt werden können: z.B. JMS The way I think of it, for the purposes of the OCWCD exam is:…

Read More

Expression Language – Implicit object

JSTL Implicit Objects   Implicit Object Type Key Value cookie Map Cookie name Cookie header Map Request header name Request header value headerValues Map Request header name String[] of request header values initParam Map Initialization parameter name Initialization parameter value param Map Request parameter name Request parameter value paramValues Map Request parameter name String[] of…

Read More

Servlet 3.0 Security Annotations

The following is the update on Servlet 3.0 security annotations: As in servlet 2.5, @DenyAll, @PermitAll, @RolesAllowed will not apply to servlets. @TransportProtected will not be added to JSR 250. The following new annotations will be added to javax.servlet.annotation: ServletSecurity HttpConstraint HttpMethodConstraint Note that @ServletSecurity is a type level annotation and the rests are used…

Read More