Tuesday, April 30, 2013

Recursively List File Name in DOS/Windows

for /r %i in (*) do @echo %~ni >> list.txt

If you end up wanting the extensions, change %~ni to %~nxi

To use in a batch file, change all the % to %%

Wednesday, April 24, 2013

Date and Time Method

    public static String getCurrentDateTime(){
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
        Date date = new Date();
        log.info("Current System Date_Time as : " + dateFormat.format(date));
        return dateFormat.format(date);
    } // end of method
   
    public static void storeCurrentDateTimeinPropertyFile(String currentDateTime) {
        //long hour = 3600 * 1000; // 3600 seconds times 1000 milliseconds
        Properties prop = new Properties();
        try {
            // set the properties value
            prop.setProperty("CurrentDateTime", currentDateTime);
            prop.store(new FileOutputStream(getCurrentDirPath()+"//" +"time.properties"), null);
            log.info("store current start_Date_Time to property file : " +  currentDateTime);
        } catch (IOException ex) {
            ex.printStackTrace();
        } // end of catch
    }
   
    // load from property file and parse to date and then increment it by one second
    public static void incDateTimeByOneSecoud(){
    try {
        Properties prop = loadProperty();
        String startTime = prop.getProperty("StartDateTime");
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
        Date date = dateFormat.parse(startTime);
        Date newDt = new Date(date.getTime() + 1000L);
        String newDT = dateFormat.format(newDt).toString();
        prop.setProperty("StartDateTime", newDT);
        prop.store(new FileOutputStream(getCurrentDirPath()+"//" +"time.properties"), null);
        log.info("increment C1_START_DATE_TIME  to property file : " + newDT);
        } catch (Exception ex) {
            ex.printStackTrace();
        } // end of catch
    } // end of method

 // load property file if missing then create new and reload it
private static Properties loadProperty(){
        Properties prop = new Properties();
        try {
            // load a properties file from class path, inside static method
            //prop.load(SyncTimeProperty.class.getClassLoader().getResourceAsStream("config.properties"));
             prop.load(new FileInputStream("time.properties"));
            log.info("loading property file : ");
        } catch (IOException ex) {
            ex.printStackTrace();
            log.info("Creating new property file : ");
            storeCurrentDateTimeinPropertyFile(getCurrentDateTime());
            return loadProperty();
        } // end of catch
        return prop;
    } // end of method

/shift the given Date by exactly 24 hours. 
private final static long MILLISECONDS_PER_DAY = 1000L * 60 * 60 * 24; 
public static void shiftDate(Date d) {
    long time = d.getTime();
    time += MILLISECONDS_PER_DAY;
    d.setTime(time);
}

Thursday, April 18, 2013

Generating JAX-WS Portable Artifacts and Webservices Tutorials

wsimport tool (client):
The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services.
Example :
  • clientjar option for wsimport, which automatically downloads the wsdl and schema and packages all the generated client-side artifacts into a jar file.
    wsimport -clientjar wsclient.jar http://example.com/service/hello?WSDL
  • wsimport -keep wsdl_URL
  • wsimport -keep -verbose -wsdllocation /META-INF/wsdl/MyService.wsdl
  • wsimport -verbose -p ec.estat.edit -target 2.1 -Xnocompile editWS.wsdl
wsgen tool (server):
The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment.
Example:
  • Generating service endfpoints artifacts (target\classes>) folder
    wsgen -verbose -keep -cp com.jini.HelloWorld
  • Generating wsdl
    wsgen -verbose -keep -cp . com.jini.HelloWorld -wsdl

Tutorials:
- JAX-WS Tutorial @ Mykyong
- Developerworks -Top 10 SOA and web services tutorials and articles
- Oracle - Creating and Using SOAP Message Handlers
- Pedict 8
- JAXWS using Maven
Online Webservice:
- Online service registry
- WebserviceX.NET

Artifacts and Client Generation using Maven:
    <build>
        <finalName>HelloService</finalName>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.1</version>
                <executions>

                    <execution>
                        <id>generate-wsdl</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>wsgen</goal>
                        </goals>
                        <configuration>
                            <sei>com.jini.service.Hello</sei>
                            <sourceDestDir>src/main/java</sourceDestDir>
                            <keep>true</keep>
                            <genWsdl>true</genWsdl>
                            <wsdlDirectory>src/resources</wsdlDirectory>
                            <verbose>true</verbose>
                        </configuration>
                    </execution>

                    <execution>
                        <id>generate-stubs</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <keep>true</keep>
                            <verbose>true</verbose>
                            <wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
                            <wsdlFiles>
                                <wsdlFile>
                                    HelloService.wsdl
                                </wsdlFile>
                            </wsdlFiles>
<!--                         <wsdlLocation>http://localhost:8080/test</wsdlLocation> -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>