Use following URL to download Apache Axis2
http://axis.apache.org/axis2/java/core/download.cgi
Steps :
1.UnZip the downloaded Axis2 (Ex:Unzipped to drive C)
2.Set Axis home as a system or user variable(AXIS2_HOME, C:\DOWNLOADED_AXIS2)
3.Run following command using CMD
%AXIS2_HOME%\bin\WSDL2Java -uri D:\Path_For_WSDL\test.wsdl
Ex:
C:\GenerateStubs>%AXIS2_HOME%\bin\WSDL2Java -uri D:\Path_For_WSDL\test.wsdl
Web service client will generate in GenerateStubs folder
ref :
http://axis.apache.org/axis2/java/core/tools/CodegenToolReference.html
To generate stub class separately
%AXIS2_HOME%\bin\WSDL2Java -uri D:\wsdl\CMUEnterprise.wsdl -p org.apache.axis2.axis2userguide -ss -g
To generate Stub class separately with services.xml
%AXIS2_HOME%\bin\WSDL2Java -uri D:\wsdl\TestDialogService.wsdl -p org.apache.axis2.axis2userguide -ss -g -sd
Tuesday, July 16, 2013
Wednesday, June 26, 2013
How to create web service client using wsdl file(IDE : Eclipse)
To create client stub for wsdl file use following steps.
1.File --> New --> Java project
2.Create web service client(Right click on the above project --> File --> New --> Other --> Web Service Client)
3.Then enter the directory path as follows and press next and finish
file:///C:\Documents and Settings\suresh_inova\Desktop\TestWS_nip\CustomECAwsdl0.0.29\wsdl\CUSTOMECA\CUSTOMECA.wsdl
You can check the created stub for provided wsdl file
1.File --> New --> Java project
2.Create web service client(Right click on the above project --> File --> New --> Other --> Web Service Client)
3.Then enter the directory path as follows and press next and finish
file:///C:\Documents and Settings\suresh_inova\Desktop\TestWS_nip\CustomECAwsdl0.0.29\wsdl\CUSTOMECA\CUSTOMECA.wsdl
You can check the created stub for provided wsdl file
Tuesday, June 4, 2013
How to run jar file from command prompt
First go to directory where the jar file is present and execute the following command
java -jar YourSample.jar
If you got following error add MANIFEST.MF file and following entry
Error:Failed to load Main-Class manifest attribute from
Answer : (Enter as Main-Class:package.MainClassName)
manifest-Version: 1.0
Main-Class: com.java.TestSuresh
Ref from: http://stackoverflow.com/questions/2848642/how-to-setup-main-class-in-manifest-file-in-jar-produced-by-netbeans-project
java -jar YourSample.jar
If you got following error add MANIFEST.MF file and following entry
Error:Failed to load Main-Class manifest attribute from
Answer : (Enter as Main-Class:package.MainClassName)
manifest-Version: 1.0
Main-Class: com.java.TestSuresh
Ref from: http://stackoverflow.com/questions/2848642/how-to-setup-main-class-in-manifest-file-in-jar-produced-by-netbeans-project
Java Create URL connection
Following is the sample for creating the URL connection when proxy is present
Test Class
package com.java;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
//import org.apache.commons.codec.binary.Base64;
public class RClient {
public static void main(String[] args) {
Map proxyData = new HashMap();
proxyData.put("pHost", "proxy.site.com");
proxyData.put("pPort", "8080");
proxyData.put("pUser", "USERNAME");
proxyData.put("pPwd", "PWD");
Map mailData = new HashMap();
mailData.put("pQuery", "variable1=G&variable2=7120189&variable3=B");
mailData.put("pUrl", "http://IP/sample/");
String a = new RClient().sendPostRequest(proxyData, mailData);
}
/**
* @param args :
*/
public String sendPostRequest(Map proxyData, Map mailData) {
String data = mailData.get("pQuery");
try {
Authenticator.setDefault(new ProxyAuthenticator(proxyData.get("pUser"), proxyData.get("pPwd")));
System.setProperty("http.proxyHost", proxyData.get("pHost"));
System.setProperty("http.proxyPort", proxyData.get("pPort"));
URL url = new URL(mailData.get("pUrl"));
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
//write parameters
writer.write(data);
writer.flush();
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {//response code is 200
return "OK";
} else {
return "ERROR: "+ con.getResponseCode();
}
} catch (Exception e) {
return "ERROR: "+ e.getMessage();
}
}
}
================================================
Proxy authenticator class
package com.java;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
class ProxyAuthenticator extends Authenticator {
private String user, password;
public ProxyAuthenticator(String user, String password) {
this.user = user;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
Test Class
package com.java;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
//import org.apache.commons.codec.binary.Base64;
public class RClient {
public static void main(String[] args) {
Map
proxyData.put("pHost", "proxy.site.com");
proxyData.put("pPort", "8080");
proxyData.put("pUser", "USERNAME");
proxyData.put("pPwd", "PWD");
Map
mailData.put("pQuery", "variable1=G&variable2=7120189&variable3=B");
mailData.put("pUrl", "http://IP/sample/");
String a = new RClient().sendPostRequest(proxyData, mailData);
}
/**
* @param args :
*/
public String sendPostRequest(Map
String data = mailData.get("pQuery");
try {
Authenticator.setDefault(new ProxyAuthenticator(proxyData.get("pUser"), proxyData.get("pPwd")));
System.setProperty("http.proxyHost", proxyData.get("pHost"));
System.setProperty("http.proxyPort", proxyData.get("pPort"));
URL url = new URL(mailData.get("pUrl"));
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
//write parameters
writer.write(data);
writer.flush();
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {//response code is 200
return "OK";
} else {
return "ERROR: "+ con.getResponseCode();
}
} catch (Exception e) {
return "ERROR: "+ e.getMessage();
}
}
}
================================================
Proxy authenticator class
package com.java;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
class ProxyAuthenticator extends Authenticator {
private String user, password;
public ProxyAuthenticator(String user, String password) {
this.user = user;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
Wednesday, May 22, 2013
Oracle IN OUT cursor with java
Following sample fully developed using
http://www.idevelopment.info/data/Programming/java/jdbc/PLSQL_and_JDBC/RefCursorExample.java
link
How to work with IN/OUT cursor with java
Connection Class
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
/**
*
* @author suresh_inova
*/
public class ConnectionDB {
final static String driverClass = "oracle.jdbc.driver.OracleDriver";
Connection con = null;
/**
* Construct a RefCursorExample object. This constructor will create an Oracle
* database connection.
*/
public ConnectionDB(String connectionURL, String userID, String userPassword) {
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public Connection getConnection() {//TODO have to use singlenton
return con;
}
}
Ref Cursor sample with Oracle imports
import java.sql.Connection;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleResultSet;
import oracle.jdbc.OracleTypes;
import test.ConnectionDB;
/**
*
* @author suresh_inova
*/
public class RefCursorRBM {
ConnectionDB conDb = null;
Connection con = null;
public RefCursorRBM() {
ConnectionDB conDb = new ConnectionDB("jdbc:oracle:thin:@172.26.30.89:1521:TEST", "userName", "pwd");
con = conDb.getConnection();
}
public void performRefCursor() {
OracleCallableStatement oraCallStmt = null;
OracleResultSet deptResultSet = null;
try {
oraCallStmt = (OracleCallableStatement) con.prepareCall("{call RBM_CUSTOM.DBT_GETCOLLECTIONS.GETMONCOLL(?,?,?,?,?)}");
oraCallStmt.registerOutParameter(1, OracleTypes.CURSOR);
oraCallStmt.registerOutParameter(1, OracleTypes.CURSOR);
oraCallStmt.setString(2, "20130501");
oraCallStmt.setString(3, "20130601");
oraCallStmt.setString(4, "HEAD");
oraCallStmt.setString(5, "GSM");
oraCallStmt.execute();
deptResultSet = (OracleResultSet) oraCallStmt.getCursor(1);
while (deptResultSet.next()) {
System.out.println(
" - " + deptResultSet.getString(1) + " - "
+ deptResultSet.getString(2) + " - "
+ deptResultSet.getString(3) + " - ");
}
oraCallStmt.close();
closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Close down Oracle connection.
*/
public void closeConnection() {
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
http://www.idevelopment.info/data/Programming/java/jdbc/PLSQL_and_JDBC/RefCursorExample.java
link
How to work with IN/OUT cursor with java
Connection Class
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
/**
*
* @author suresh_inova
*/
public class ConnectionDB {
final static String driverClass = "oracle.jdbc.driver.OracleDriver";
Connection con = null;
/**
* Construct a RefCursorExample object. This constructor will create an Oracle
* database connection.
*/
public ConnectionDB(String connectionURL, String userID, String userPassword) {
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public Connection getConnection() {//TODO have to use singlenton
return con;
}
}
Ref Cursor sample with Oracle imports
import java.sql.Connection;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleResultSet;
import oracle.jdbc.OracleTypes;
import test.ConnectionDB;
/**
*
* @author suresh_inova
*/
public class RefCursorRBM {
ConnectionDB conDb = null;
Connection con = null;
public RefCursorRBM() {
ConnectionDB conDb = new ConnectionDB("jdbc:oracle:thin:@172.26.30.89:1521:TEST", "userName", "pwd");
con = conDb.getConnection();
}
public void performRefCursor() {
OracleCallableStatement oraCallStmt = null;
OracleResultSet deptResultSet = null;
try {
oraCallStmt = (OracleCallableStatement) con.prepareCall("{call RBM_CUSTOM.DBT_GETCOLLECTIONS.GETMONCOLL(?,?,?,?,?)}");
oraCallStmt.registerOutParameter(1, OracleTypes.CURSOR);
oraCallStmt.registerOutParameter(1, OracleTypes.CURSOR);
oraCallStmt.setString(2, "20130501");
oraCallStmt.setString(3, "20130601");
oraCallStmt.setString(4, "HEAD");
oraCallStmt.setString(5, "GSM");
oraCallStmt.execute();
deptResultSet = (OracleResultSet) oraCallStmt.getCursor(1);
while (deptResultSet.next()) {
System.out.println(
" - " + deptResultSet.getString(1) + " - "
+ deptResultSet.getString(2) + " - "
+ deptResultSet.getString(3) + " - ");
}
oraCallStmt.close();
closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Close down Oracle connection.
*/
public void closeConnection() {
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Subscribe to:
Posts (Atom)