Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Thursday, May 26, 2016

Java - XMLGregorianCalendar to java.sql.date

Refer below..


private Date toDate(XMLGregorianCalendar calendar){
        if(calendar == null) {
            return null;
        }
     
        java.util.Date dt = calendar.toGregorianCalendar().getTime();
        java.sql.Date sqlDt = new java.sql.Date(dt.getTime());
        return sqlDt;
       
    }

Sunday, April 3, 2016

Curl - Send Webservice Request thru Linux terminal

Below is step by step to test request and response on webservice.

Create a request01.xml in server.
Example command : cat > request01.xml

and then paste your xml.

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:NSS="http://tempuri.org/MyService">
   <soapenv:Header/>
   <soapenv:Body>
      <NSS:retrieveDataReq>
         <AgencyCode>123456</AgencyCode>
         <BranchCode>MyBranch011</BranchCode>
         <RequestDateTime>2016-01-18T14:35:00</RequestDateTime>
      </NSS:retrieveDataReq>
   </soapenv:Body>
</soapenv:Envelope>

Ctrl + c to exit the cat command.

Use below curl command to send the request.

curl --header "Content-Type: application/soap+xml;charset=UTF-8" --data @request01.xml http://192.168.1.20:82/webserviceName?wsdl

The response will show in terminal with the raw XML. this curl is use for test the request and response on webservice.

Java wsimport - create webservice client


mkdir C:\temp
cd C:\temp

"C:\Program Files\Java\jdk1.8.0_73\bin\wsimport" -keep http://localhost:83/yourWebservice?wsdl


Monday, July 16, 2012

Java : Count lines in file


long lines = 1;
        try {
LineNumberReader  lnr = new LineNumberReader(new FileReader(new File("C:/testfile.txt")));
lnr.skip(Long.MAX_VALUE);
lines = lnr.getLineNumber();
} catch (FileNotFoundException e1) {
} catch (IOException e) {
}

The faster way to get total line in file...

Wednesday, May 16, 2012

Java : Create File


Source code for create file. Example : text.txt, sample.dat, etc..



import java.io.File;
import java.io.IOException;

public class MakeFile {
public static void main(String[] args) {
File myFile = new File("myJava.java"); //change this filename
try {
myFile.createNewFile();
} catch (IOException e) {
System.out.println("Cannot created.");
}
}
public String createFile(String fileName) {
File myFile = new File(fileName);
try {
myFile.createNewFile();
return "0:OK";
} catch (IOException e) {
System.out.println(e.getMessage());
return "1:Not OK";
}
}
}

save as MakeFile.java

Wednesday, January 4, 2012

JAVA : I/O Create file

Just a sample code for I/O...



import java.io.File;
import java.io.IOException;
public class CreateFile {
public static void main(String[] args)
{
try{
File file = new File("MyFile.txt"); if (file.createNewFile())
{
System.out.println("Sucess");
}
else
{
System.out.println("Already exist..");
}
}
catch (IOException e)
{
}
}
}

JAVA : OOP - Interface

Below example for Interface programming.


interface calc {
public int calc(int a, int b);
}
public class MyInterface implements calc{
public int calc(int a,int b )
{
return a + b; }
public static void main(String[] args)
{
MyInterface testInterface = new MyInterface();
int total;
total = testInterface.calc(1,7);
System.out.println("Total:" + total);
}
}


Interface only declare the method only. not include with the method body.

Java : OOP - Pass object to Method

Example for Pass object to Method.


class Kira {
void print(String str) {
System.out.println("In Kira :" + str);
}
}
public class test {
public static void main(String[] args) {
//System.out.println("testing 1 2 3....");
Kira kira = new Kira();
kira.print("Testing Kira");
}
}


Save file as test.java. Compile and run.....