Commit f6e02bd8 authored by steurwadkar's avatar steurwadkar

F17ABAS001 source code commit


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@106085 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 563301d8
...@@ -4,6 +4,7 @@ import java.io.InputStream; ...@@ -4,6 +4,7 @@ import java.io.InputStream;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.security.PrivateKey;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -14,11 +15,13 @@ import java.util.Calendar; ...@@ -14,11 +15,13 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.XML;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
...@@ -26,11 +29,13 @@ import org.w3c.dom.NodeList; ...@@ -26,11 +29,13 @@ import org.w3c.dom.NodeList;
import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode; import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.Unirest;
import com.sun.jmx.snmp.Timestamp;
import ibase.utility.E12GenericUtility; import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.fin.FinCommon; import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.util.gst.AESEncryption; import ibase.webitm.util.gst.AESEncryption;
import ibase.webitm.util.gst.GSPSignature;
import ibase.webitm.util.gst.PubKeyEncryption; import ibase.webitm.util.gst.PubKeyEncryption;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
...@@ -38,7 +43,13 @@ import ibase.webitm.utility.ITMException; ...@@ -38,7 +43,13 @@ import ibase.webitm.utility.ITMException;
public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWizEJBLocal, GSTDataSubmitWizEJBRemote public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWizEJBLocal, GSTDataSubmitWizEJBRemote
{ {
private String GST_API_URL = ""; private String GST_API_URL = "";
private String GSP_API_URL = "";
private String AUTH_TOKEN_URL_V2 = ""; private String AUTH_TOKEN_URL_V2 = "";
private String GSTR1_URL_V2 = "";
private String GSTR2_URL_V2 = "";
private String GSTR1_URL_V3 = "";
private String GSTR2_URL_V3 = "";
private final String APPLICATION_JSON = "application/json";
private String appKey = ""; private String appKey = "";
InetAddress ipAddress = null; InetAddress ipAddress = null;
private byte[] appKeyInBytes = null; private byte[] appKeyInBytes = null;
...@@ -47,7 +58,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -47,7 +58,10 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
private String clientSecret = ""; private String clientSecret = "";
AESEncryption aesEncryption = null; AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null; PubKeyEncryption pubKeyEncryption = null;
GSPSignature gspSignature;
PrivateKey aspPrivateKey = null;
Connection conn = null; Connection conn = null;
@PostConstruct @PostConstruct
public void postConstruct() public void postConstruct()
{ {
...@@ -66,6 +80,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -66,6 +80,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
pubKeyEncryption = new PubKeyEncryption(pubKeyInpStream); pubKeyEncryption = new PubKeyEncryption(pubKeyInpStream);
ipAddress = Inet4Address.getLocalHost(); ipAddress = Inet4Address.getLocalHost();
System.out.println("host ipAddress["+ipAddress.getHostAddress()+"]"); System.out.println("host ipAddress["+ipAddress.getHostAddress()+"]");
gspSignature = new GSPSignature();
String privateKeyPath = "/ibase/webitm/resources/gst/privatekey.pem";
aspPrivateKey = gspSignature.loadPrivateKey(Thread.currentThread().getContextClassLoader().getResourceAsStream(privateKeyPath));
sql = "SELECT SERVICE_CODE, SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE METHOD_NAME = 'GST_API_URL'"; sql = "SELECT SERVICE_CODE, SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE METHOD_NAME = 'GST_API_URL'";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
...@@ -74,6 +91,11 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -74,6 +91,11 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
{ {
switch(rs.getString("SERVICE_CODE")) switch(rs.getString("SERVICE_CODE"))
{ {
case "gsp_base_url" :
{
GSP_API_URL = rs.getString("SERVICE_URI");
}
break;
case "gst_base_url" : case "gst_base_url" :
{ {
GST_API_URL = rs.getString("SERVICE_URI"); GST_API_URL = rs.getString("SERVICE_URI");
...@@ -84,6 +106,26 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -84,6 +106,26 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
AUTH_TOKEN_URL_V2 = rs.getString("SERVICE_URI"); AUTH_TOKEN_URL_V2 = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr1_url_v2" :
{
GSTR1_URL_V2 = rs.getString("SERVICE_URI");
}
break;
case "gstr2_url_v2" :
{
GSTR2_URL_V2 = rs.getString("SERVICE_URI");
}
break;
case "gstr1_url_v3" :
{
GSTR1_URL_V3 = rs.getString("SERVICE_URI");
}
break;
case "gstr2_url_v3" :
{
GSTR2_URL_V3 = rs.getString("SERVICE_URI");
}
break;
} }
} }
if(pstmt!=null) if(pstmt!=null)
...@@ -97,6 +139,13 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -97,6 +139,13 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
rs = null; rs = null;
} }
System.out.println("GST_API_URL["+GST_API_URL+"]");
System.out.println("AUTH_TOKEN_URL_V2["+AUTH_TOKEN_URL_V2+"]");
System.out.println("GSTR1_URL_V2["+GSTR1_URL_V2+"]");
System.out.println("GSTR2_URL_V2["+GSTR2_URL_V2+"]");
System.out.println("GSTR1_URL_V3["+GSTR1_URL_V3+"]");
System.out.println("GSTR2_URL_V3["+GSTR2_URL_V3+"]");
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -276,19 +325,80 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -276,19 +325,80 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
} }
break; break;
} }
/*case 2: case 2:
{ {
String otp = "", transactionId = "", authToken = "", sek = "", retXML = "";
String gspAuthString = "", gspAuthSignature = "";
long timeStamp = new Timestamp().getDateTime();
byte[] authSEK = null;
System.out.println(" -------- Inside itemchange case 2222222 ------------ "); System.out.println(" -------- Inside itemchange case 2222222 ------------ ");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" )) if( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
{ {
transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gstinNo = checkNull(e12genericUtility.getColumnValue("gstin", dom1));
periodCode = checkNull(e12genericUtility.getColumnValue("period_code", dom1));
stateCode = checkNull(e12genericUtility.getColumnValue("state_code", dom1));
userName = checkNull(e12genericUtility.getColumnValue("username", dom1));
appKey = checkNull(e12genericUtility.getColumnValue("app_key", dom1));
appKeyInBytes = aesEncryption.decodeBase64StringTOByte(appKey);
appKeyEncryptedAndCoded = pubKeyEncryption.encrypt(appKeyInBytes);
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
otp = checkNull(e12genericUtility.getColumnValue("otp", dom1));
String encryptedOTP = aesEncryption.encryptEK(otp.getBytes(), appKeyInBytes);
JSONObject authTokenReq = new JSONObject();
authTokenReq.put("action", "AUTHTOKEN");
authTokenReq.put("username", userName);
authTokenReq.put("app_key", appKeyEncryptedAndCoded);
authTokenReq.put("otp", encryptedOTP);
HttpResponse<JsonNode> authTokenResp = Unirest.post(String.format("%s%s", GSP_API_URL, AUTH_TOKEN_URL_V2))
.header("Content-Type",APPLICATION_JSON)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("state-cd", stateCode)
.header("ip-usr", ipAddress.getHostAddress())
.header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(authTokenReq.toString()))
.asJson();
System.out.println(String.format("authTokenResp Request : Status[%s] Response[%s]", authTokenResp.getStatus(), authTokenResp.getBody()));
if (authTokenResp.getStatus() == 200)
{
JSONObject object = authTokenResp.getBody().getObject();
if (object.has("auth_token") && object.has("sek") && object.has("status_cd") && Objects.equals(object.getString("status_cd"), "1"))
{
authToken = object.getString("auth_token");
sek = object.getString("sek");
authSEK = aesEncryption.decrypt(sek, appKeyInBytes);
System.out.println("AuthSEK = "+ aesEncryption.encodeBase64String(authSEK));
retXML = downloadGstr1Data(gstinNo, periodCode, authToken, userName, stateCode, appKeyEncryptedAndCoded, authSEK);
}
}
valueXmlString.append("<Detail2 domID='1'>"); valueXmlString.append("<Detail2 domID='1'>");
valueXmlString.append("<gstin><![CDATA[" ).append("33GSPTN2071G1ZC").append( "]]></gstin>"); valueXmlString.append("<auth_token><![CDATA["+ authToken +"]]></auth_token>");
valueXmlString.append("<invoice_id><![CDATA[").append("INV0000001").append( "]]></invoice_id>"); valueXmlString.append("<auth_sek><![CDATA["+ authSEK +"]]></auth_sek>");
valueXmlString.append("<invoice_date><![CDATA[12-03-2017]]></invoice_date>"); valueXmlString.append("</Detail2>" );
valueXmlString.append("<Detail2 domID='2'>");
valueXmlString.append(retXML);
valueXmlString.append("</Detail2>" ); valueXmlString.append("</Detail2>" );
} }
break; break;
}*/ }
} }
valueXmlString.append( "</Root>" ); valueXmlString.append( "</Root>" );
} }
...@@ -485,7 +595,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -485,7 +595,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
} }
@Override @Override
public String handleRequest(HashMap<String, String> reqParamMap) public String handleRequest(HashMap<String, String> reqParamMap) throws ITMException
{ {
String retResponseXML = "", action = ""; String retResponseXML = "", action = "";
String sql = ""; String sql = "";
...@@ -499,8 +609,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -499,8 +609,9 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
if("GENERATE_OTP".equalsIgnoreCase(action)) if("GENERATE_OTP".equalsIgnoreCase(action))
{ {
String userName = "", stateCode = ""; String userName = "", stateCode = "", gspAuthString = "", gspAuthSignature = "", gstinNo = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
long timeStamp = new Timestamp().getDateTime();
if("NULLFOUND".equalsIgnoreCase(clientId) || "NULLFOUND".equalsIgnoreCase(clientSecret)) if("NULLFOUND".equalsIgnoreCase(clientId) || "NULLFOUND".equalsIgnoreCase(clientSecret))
{ {
...@@ -510,14 +621,18 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -510,14 +621,18 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
userName = reqParamMap.get("user_name"); userName = reqParamMap.get("user_name");
stateCode = reqParamMap.get("state_code"); stateCode = reqParamMap.get("state_code");
gstinNo = reqParamMap.get("gstin_no");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
JSONObject otpRequest = new JSONObject(); JSONObject otpRequest = new JSONObject();
otpRequest.put("action", "OTPREQUEST"); otpRequest.put("action", "OTPREQUEST");
otpRequest.put("app_key", appKeyEncryptedAndCoded); otpRequest.put("app_key", appKeyEncryptedAndCoded);
otpRequest.put("username", userName); otpRequest.put("username", userName);
HttpResponse<JsonNode> otpResp = Unirest.post(String.format("%s%s", GST_API_URL,AUTH_TOKEN_URL_V2)) HttpResponse<JsonNode> otpResp = Unirest.post(String.format("%s%s", GSP_API_URL,AUTH_TOKEN_URL_V2))
.header("Content-Type", "application/json") .header("Content-Type", APPLICATION_JSON)
.header("clientid", clientId) .header("clientid", clientId)
.header("client-secret", clientSecret) .header("client-secret", clientSecret)
.header("state-cd", stateCode) .header("state-cd", stateCode)
...@@ -525,6 +640,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -525,6 +640,8 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
.header("username", userName) .header("username", userName)
.header("txn", transactionId) .header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded) .header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(otpRequest.toString())) .body(new JsonNode(otpRequest.toString()))
.asJson(); .asJson();
...@@ -611,6 +728,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -611,6 +728,7 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
{ {
System.out.println("GSTDataSubmitWizEJB.handleRequest()["+e.getMessage()+"]"); System.out.println("GSTDataSubmitWizEJB.handleRequest()["+e.getMessage()+"]");
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e);
} }
finally finally
{ {
...@@ -631,6 +749,100 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi ...@@ -631,6 +749,100 @@ public class GSTDataSubmitWizEJB extends ValidatorEJB implements GSTDataSubmitWi
System.out.println("final retResonseXML ["+retResponseXML+"]"); System.out.println("final retResonseXML ["+retResponseXML+"]");
return retResponseXML; return retResponseXML;
} }
private String downloadGstr1Data (String gstinNo, String periodCode, String authToken, String userName, String stateCode, String appKeyEncryptedAndCoded, byte[] authSek) throws ITMException
{
StringBuffer retStringBuff = new StringBuffer();
String[] gstr1Section = {"B2B","B2CL","B2CS","CDNR","CDNUR","AT","TXP","NIL","EXP","HSNSUM"};
String gspAuthString = "", gspAuthSignature = "";
try
{
for(String action : gstr1Section)
{
long timeStamp = new Timestamp().getDateTime();
System.out.println("calling for ["+action+"]");
String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstinNo;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpResponse<JsonNode> getDataResp = Unirest.get(String.format("%s%s", GSP_API_URL,GSTR1_URL_V2))//TODO need to change URL to v0.3
.queryString("action", action)
.queryString("gstin", gstinNo)
.queryString("ret_period", periodCode)
.header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode)
.header("clientid", clientId)
.header("client-secret", clientSecret)
.header("ip-usr", ipAddress.getHostAddress())
.header("username", userName)
.header("auth-token", authToken)
.header("app_key", appKeyEncryptedAndCoded)
.header("txn", transactionId)
.header("ret_period", periodCode)
.header("gstin", gstinNo)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.asJson();
if(getDataResp.getStatus() == 200)
{
JSONObject getDataRespObj = getDataResp.getBody().getObject();
if(getDataRespObj.has("data") && getDataRespObj.has("rek"))
{
String getdata = getDataRespObj.getString("data");
String getrek = getDataRespObj.getString("rek");
byte[] getapiEK = aesEncryption.decrypt(getrek, authSek);
String getrespJsoninBase64 = new String(aesEncryption.decrypt(getdata, getapiEK));
byte[] getrespJsonInBytes = aesEncryption.decodeBase64StringTOByte(getrespJsoninBase64);
String getjsonData = new String(getrespJsonInBytes);
System.out.println("json response["+getjsonData+"] for ["+action+"]");
if("B2B".equalsIgnoreCase(action))
{
String b2bXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<b2b_invoices>");
retStringBuff.append(b2bXML);
retStringBuff.append("</b2b_invoices>");
}
else if("B2CL".equalsIgnoreCase(action))
{
String b2clXML = XML.toString(new JSONObject(new String(getrespJsonInBytes)));
retStringBuff.append("<b2cl_invoices>");
retStringBuff.append(b2clXML);
retStringBuff.append("</b2cl_invoices>");
}
}
else
{
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
//errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
//retString = getError(errMsg, "GSTAPIERR", conn);
System.out.println("errorJSON["+errorJSON+"]");
}
}
else
{
JSONObject errorJSON = getDataResp.getBody().getObject().getJSONObject("error");
//errMsg = "Message : "+errorJSON.getString("desc")+" \nError code : "+errorJSON.getString("code");
//retString = getError(errMsg, "GSTAPIERR", conn);
System.out.println("errorJSON["+errorJSON+"]");
}
}
}
catch (Exception e)
{
System.out.println("GSTDataSubmitWizEJB.downloadGstr1Data()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("final retStringBuff.toSting["+retStringBuff.toString()+"]");
return retStringBuff.toString();
}
private String checkNull(String input) private String checkNull(String input)
{ {
if (input==null) if (input==null)
......
...@@ -17,5 +17,5 @@ public interface GSTDataSubmitWizEJBLocal extends ValidatorLocal ...@@ -17,5 +17,5 @@ public interface GSTDataSubmitWizEJBLocal extends ValidatorLocal
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException; public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException; public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String handleRequest(HashMap<String, String> reqParamMap); public String handleRequest(HashMap<String, String> reqParamMap) throws ITMException;
} }
...@@ -17,5 +17,5 @@ public interface GSTDataSubmitWizEJBRemote extends ValidatorRemote ...@@ -17,5 +17,5 @@ public interface GSTDataSubmitWizEJBRemote extends ValidatorRemote
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException; public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext,String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException; public String wfValData(Document currFormDataDom, Document hdrDataDom, Document allFormDataDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String handleRequest(HashMap<String, String> reqParamMap); public String handleRequest(HashMap<String, String> reqParamMap) throws ITMException;
} }
...@@ -4,6 +4,7 @@ import java.io.InputStream; ...@@ -4,6 +4,7 @@ import java.io.InputStream;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.security.PrivateKey;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -32,6 +33,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -32,6 +33,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode; import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.Unirest;
import com.sun.jmx.snmp.Timestamp;
import ibase.utility.CommonConstants; import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility; import ibase.utility.E12GenericUtility;
...@@ -59,6 +61,7 @@ import ibase.webitm.ejb.ITMDBAccessEJB; ...@@ -59,6 +61,7 @@ import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.fin.FinCommon; import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.util.gst.AESEncryption; import ibase.webitm.util.gst.AESEncryption;
import ibase.webitm.util.gst.GSPSignature;
import ibase.webitm.util.gst.PubKeyEncryption; import ibase.webitm.util.gst.PubKeyEncryption;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator; import ibase.webitm.utility.TransIDGenerator;
...@@ -66,6 +69,7 @@ import ibase.webitm.utility.TransIDGenerator; ...@@ -66,6 +69,7 @@ import ibase.webitm.utility.TransIDGenerator;
@javax.ejb.Stateless @javax.ejb.Stateless
public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWizPosLocal, GSTDataSubmitWizPosRemote public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWizPosLocal, GSTDataSubmitWizPosRemote
{ {
private String GSP_API_URL = "";
private String GST_API_URL = ""; private String GST_API_URL = "";
private String AUTH_TOKEN_URL_V2 = ""; private String AUTH_TOKEN_URL_V2 = "";
private String GSTR1_URL_V2 = ""; private String GSTR1_URL_V2 = "";
...@@ -82,7 +86,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -82,7 +86,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
AESEncryption aesEncryption = null; AESEncryption aesEncryption = null;
PubKeyEncryption pubKeyEncryption = null; PubKeyEncryption pubKeyEncryption = null;
Connection conn = null; Connection conn = null;
GSPSignature gspSignature;
PrivateKey aspPrivateKey = null;
E12GenericUtility e12GeneticUitlity = null; E12GenericUtility e12GeneticUitlity = null;
@PostConstruct @PostConstruct
public void postConstruct() public void postConstruct()
{ {
...@@ -102,6 +110,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -102,6 +110,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
pubKeyEncryption = new PubKeyEncryption(pubKeyInpStream); pubKeyEncryption = new PubKeyEncryption(pubKeyInpStream);
ipAddress = Inet4Address.getLocalHost(); ipAddress = Inet4Address.getLocalHost();
System.out.println("host ipAddress["+ipAddress.getHostAddress()+"]"); System.out.println("host ipAddress["+ipAddress.getHostAddress()+"]");
gspSignature = new GSPSignature();
String privateKeyPath = "/ibase/webitm/resources/gst/privatekey.pem";
aspPrivateKey = gspSignature.loadPrivateKey(Thread.currentThread().getContextClassLoader().getResourceAsStream(privateKeyPath));
sql = "SELECT SERVICE_CODE, SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE METHOD_NAME = 'GST_API_URL'"; sql = "SELECT SERVICE_CODE, SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE METHOD_NAME = 'GST_API_URL'";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
...@@ -110,34 +121,39 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -110,34 +121,39 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
switch(rs.getString("SERVICE_CODE")) switch(rs.getString("SERVICE_CODE"))
{ {
case "gsp_base_url" :
{
GSP_API_URL = rs.getString("SERVICE_URI");
}
break;
case "gst_base_url" : case "gst_base_url" :
{ {
GST_API_URL = checkNullandTrim(rs.getString("SERVICE_URI")); GST_API_URL = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr_auth_url_v2" : case "gstr_auth_url_v2" :
{ {
AUTH_TOKEN_URL_V2 = checkNullandTrim(rs.getString("SERVICE_URI")); AUTH_TOKEN_URL_V2 = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr1_url_v2" : case "gstr1_url_v2" :
{ {
GSTR1_URL_V2 = checkNullandTrim(rs.getString("SERVICE_URI")); GSTR1_URL_V2 = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr2_url_v2" : case "gstr2_url_v2" :
{ {
GSTR2_URL_V2 = checkNullandTrim(rs.getString("SERVICE_URI")); GSTR2_URL_V2 = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr1_url_v3" : case "gstr1_url_v3" :
{ {
GSTR1_URL_V3 = checkNullandTrim(rs.getString("SERVICE_URI")); GSTR1_URL_V3 = rs.getString("SERVICE_URI");
} }
break; break;
case "gstr2_url_v3" : case "gstr2_url_v3" :
{ {
GSTR2_URL_V3 = checkNullandTrim(rs.getString("SERVICE_URI")); GSTR2_URL_V3 = rs.getString("SERVICE_URI");
} }
break; break;
} }
...@@ -189,7 +205,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -189,7 +205,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
Document allXMLDom = null; Document allXMLDom = null;
NodeList detail1NList = null, detail1ChildNList = null; NodeList detail1NList = null, detail1ChildNList = null;
String retString = "", nodeName = "", otp = "", stateCode = "", sek = "", returnsType = "", gstin = "", periodCode = "", grossTurnover = "", String retString = "", nodeName = "", otp = "", stateCode = "", sek = "", returnsType = "", gstin = "", periodCode = "", grossTurnover = "",
action = "", siteCode = ""; action = "", siteCode = "", gspAuthString = "", gspAuthSignature = "";
byte[] authSEK = null; byte[] authSEK = null;
try try
...@@ -269,7 +285,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -269,7 +285,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
authTokenReq.put("app_key", appKeyEncryptedAndCoded); authTokenReq.put("app_key", appKeyEncryptedAndCoded);
authTokenReq.put("otp", encryptedOTP); authTokenReq.put("otp", encryptedOTP);
HttpResponse<JsonNode> authTokenResp = Unirest.post(String.format("%s%s", GST_API_URL, AUTH_TOKEN_URL_V2)) long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpResponse<JsonNode> authTokenResp = Unirest.post(String.format("%s%s", GSP_API_URL, AUTH_TOKEN_URL_V2))
.header("Content-Type",APPLICATION_JSON) .header("Content-Type",APPLICATION_JSON)
.header("clientid", clientId) .header("clientid", clientId)
.header("client-secret", clientSecret) .header("client-secret", clientSecret)
...@@ -277,6 +297,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -277,6 +297,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("ip-usr", ipAddress.getHostAddress()) .header("ip-usr", ipAddress.getHostAddress())
.header("txn", transactionId) .header("txn", transactionId)
.header("app_key", appKeyEncryptedAndCoded) .header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(authTokenReq.toString())) .body(new JsonNode(authTokenReq.toString()))
.asJson(); .asJson();
...@@ -475,7 +497,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -475,7 +497,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.num = lineRs.getInt("LINE_NO"); invLineItem.num = lineRs.getInt("LINE_NO");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT"); invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
...@@ -544,7 +566,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -544,7 +566,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.num = lineRs.getInt("LINE_NO"); invLineItem.num = lineRs.getInt("LINE_NO");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT"); invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
...@@ -622,7 +644,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -622,7 +644,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
b2cs.typ = supplyType; b2cs.typ = supplyType;
b2cs.etin = rs.getString("ECOM_REG_NO"); b2cs.etin = rs.getString("ECOM_REG_NO");
b2cs.pos = posStateCode; b2cs.pos = posStateCode;
b2cs.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); b2cs.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
b2cs.iamt = lineRs.getDouble("IGST_AMT"); b2cs.iamt = lineRs.getDouble("IGST_AMT");
b2cs.camt = lineRs.getDouble("CGST_AMT"); b2cs.camt = lineRs.getDouble("CGST_AMT");
b2cs.samt = lineRs.getDouble("SGST_AMT"); b2cs.samt = lineRs.getDouble("SGST_AMT");
...@@ -656,7 +678,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -656,7 +678,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.num = lineRs.getInt("LINE_NO"); invLineItem.num = lineRs.getInt("LINE_NO");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT"); invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
...@@ -730,7 +752,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -730,7 +752,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT"); invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.samt = lineRs.getDouble("SGST_AMT"); invLineItem.samt = lineRs.getDouble("SGST_AMT");
...@@ -783,7 +805,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -783,7 +805,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.taxval = rs.getDouble("AMOUNT"); invLineItem.taxval = rs.getDouble("AMOUNT");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.samt = lineRs.getDouble("SGST_AMT"); invLineItem.samt = lineRs.getDouble("SGST_AMT");
...@@ -827,7 +849,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -827,7 +849,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.taxval = rs.getDouble("AMOUNT"); invLineItem.taxval = rs.getDouble("AMOUNT");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
invLineItem.samt = lineRs.getDouble("SGST_AMT"); invLineItem.samt = lineRs.getDouble("SGST_AMT");
...@@ -867,7 +889,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -867,7 +889,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
{ {
invLineItem = new InvLineItem(); invLineItem = new InvLineItem();
invLineItem.num = lineRs.getInt("LINE_NO"); invLineItem.num = lineRs.getInt("LINE_NO");
invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC")+lineRs.getDouble("CESS_PERC"); invLineItem.rate = lineRs.getDouble("IGST_PERC")+lineRs.getDouble("CGST_PERC")+lineRs.getDouble("SGST_PERC");
invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT"); invLineItem.taxval = lineRs.getDouble("TAXABLE_AMT");
invLineItem.iamt = lineRs.getDouble("IGST_AMT"); invLineItem.iamt = lineRs.getDouble("IGST_AMT");
invLineItem.camt = lineRs.getDouble("CGST_AMT"); invLineItem.camt = lineRs.getDouble("CGST_AMT");
...@@ -1044,6 +1066,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1044,6 +1066,9 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
if(isDataFound) if(isDataFound)
{ {
String gspAuthString = "", gspAuthSignature = "", gspAuthStringRet = "", gspAuthSignatureRet = "";
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(gstr1); String json = objectMapper.writeValueAsString(gstr1);
...@@ -1065,7 +1090,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1065,7 +1090,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
gstr1HeaderObj.put("data", encryptedPayload); gstr1HeaderObj.put("data", encryptedPayload);
gstr1HeaderObj.put("hmac", new String(Base64.getEncoder().encode(resBuf))); gstr1HeaderObj.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
HttpResponse<JsonNode> gstr1Resp = Unirest.put(String.format("%s/%s", GST_API_URL, GSTR1_URL_V3)) long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpResponse<JsonNode> gstr1Resp = Unirest.put(String.format("%s/%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("clientid", clientId) .header("clientid", clientId)
.header("client-secret", clientSecret) .header("client-secret", clientSecret)
...@@ -1077,6 +1106,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1077,6 +1106,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("ip-usr", ipAddress.getHostAddress()) .header("ip-usr", ipAddress.getHostAddress())
.header("app_key", appKeyEncryptedAndCoded) .header("app_key", appKeyEncryptedAndCoded)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(gstr1HeaderObj.toString())) .body(new JsonNode(gstr1HeaderObj.toString()))
.asJson(); .asJson();
...@@ -1103,7 +1134,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1103,7 +1134,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
while(true) while(true)
{ {
HttpResponse<JsonNode> retStatusResp = Unirest.get(String.format("%s/%s", GST_API_URL, GSTR1_URL_V3)) long timeStampRet = new Timestamp().getDateTime();
gspAuthStringRet = clientId + ":" + transactionId + ":" + timeStampRet + ":" + gstin;
gspAuthSignatureRet = gspSignature.sign(gspAuthStringRet, aspPrivateKey);
HttpResponse<JsonNode> retStatusResp = Unirest.get(String.format("%s/%s", GSP_API_URL, GSTR1_URL_V3))
.queryString("action","RETSTATUS") .queryString("action","RETSTATUS")
.queryString("gstin", gstin) .queryString("gstin", gstin)
.queryString("ret_period", periodCode) .queryString("ret_period", periodCode)
...@@ -1119,6 +1154,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1119,6 +1154,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("txn", transactionId) .header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthStringRet)
.header("X-Asp-Auth-Signature", gspAuthSignatureRet)
.asJson(); .asJson();
System.out.println(String.format("retStatusResp Request : Status[%s] Response[%s]", retStatusResp.getStatus(), retStatusResp.getBody())); System.out.println(String.format("retStatusResp Request : Status[%s] Response[%s]", retStatusResp.getStatus(), retStatusResp.getBody()));
...@@ -1212,12 +1249,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1212,12 +1249,15 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String getGstr1Summary(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String action, Connection conn) throws ITMException private String getGstr1Summary(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSek, String action, Connection conn) throws ITMException
{ {
String retString = ""; String retString = "";
String errMsg = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
try try
{ {
long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpResponse<JsonNode> getGstr1SumryResp = Unirest.get(String.format("%s/%s", GST_API_URL, GSTR1_URL_V3)) HttpResponse<JsonNode> getGstr1SumryResp = Unirest.get(String.format("%s/%s", GSP_API_URL, GSTR1_URL_V3))
.queryString("action","RETSUM") .queryString("action","RETSUM")
.queryString("gstin", gstin) .queryString("gstin", gstin)
.queryString("ret_period", periodCode) .queryString("ret_period", periodCode)
...@@ -1232,6 +1272,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1232,6 +1272,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("txn", transactionId) .header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.asJson(); .asJson();
System.out.println(String.format("getGstr1SumryResp Request : Status[%s] Response[%s]", getGstr1SumryResp.getStatus(), getGstr1SumryResp.getBody())); System.out.println(String.format("getGstr1SumryResp Request : Status[%s] Response[%s]", getGstr1SumryResp.getStatus(), getGstr1SumryResp.getBody()));
...@@ -1256,6 +1298,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1256,6 +1298,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
if("FILE".equalsIgnoreCase(action)) if("FILE".equalsIgnoreCase(action))
{ {
String gspAuthStringFile = "", gspAuthSignatureFile = "";
byte[] jsonBase64 = Base64.getEncoder().encode(gstr1SumryJsonObj.toString().getBytes()); byte[] jsonBase64 = Base64.getEncoder().encode(gstr1SumryJsonObj.toString().getBytes());
String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek); String encryptedPayload = aesEncryption.encryptEK(jsonBase64, authSek);
...@@ -1274,7 +1318,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1274,7 +1318,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
fileGstr1DataJsonObj.put("st", "DSC"); fileGstr1DataJsonObj.put("st", "DSC");
fileGstr1DataJsonObj.put("sid", "AMAPT8269L"); fileGstr1DataJsonObj.put("sid", "AMAPT8269L");
HttpResponse<JsonNode> fileGstr1Resp = Unirest.post(String.format("%s/%s", GST_API_URL, GSTR1_URL_V3)) long timeStampFile = new Timestamp().getDateTime();
gspAuthStringFile = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignatureFile = gspSignature.sign(gspAuthStringFile, aspPrivateKey);
HttpResponse<JsonNode> fileGstr1Resp = Unirest.post(String.format("%s/%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("state-cd", stateCode) .header("state-cd", stateCode)
.header("clientid", clientId) .header("clientid", clientId)
...@@ -1286,6 +1334,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1286,6 +1334,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("txn", transactionId) .header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthStringFile)
.header("X-Asp-Auth-Signature", gspAuthSignatureFile)
.body(new JsonNode(fileGstr1DataJsonObj.toString())) .body(new JsonNode(fileGstr1DataJsonObj.toString()))
.asJson(); .asJson();
...@@ -1347,7 +1397,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1347,7 +1397,7 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, Connection conn) throws ITMException private String submitGstr1(String authToken, String stateCode, String userName, String gstin, String periodCode, byte[] authSEK, Connection conn) throws ITMException
{ {
String retString = ""; String retString = "";
String errMsg = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
try try
{ {
...@@ -1369,7 +1419,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1369,7 +1419,11 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
reqBody.put("data", encryptedPayload); reqBody.put("data", encryptedPayload);
reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf))); reqBody.put("hmac", new String(Base64.getEncoder().encode(resBuf)));
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s/%s", GST_API_URL, GSTR1_URL_V3)) long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpResponse<JsonNode> gstr1SubmitResp = Unirest.post(String.format("%s/%s", GSP_API_URL, GSTR1_URL_V3))
.header("Content-Type", APPLICATION_JSON) .header("Content-Type", APPLICATION_JSON)
.header("action", "RETSUBMIT") .header("action", "RETSUBMIT")
.header("state-cd", stateCode) .header("state-cd", stateCode)
...@@ -1382,6 +1436,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1382,6 +1436,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("txn", transactionId) .header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.body(new JsonNode(reqBody.toString())) .body(new JsonNode(reqBody.toString()))
.asJson(); .asJson();
...@@ -1431,12 +1487,16 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1431,12 +1487,16 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
private String getGstr2Invoices(String authToken, String stateCode, String userName, String gstin, String periodCode, String siteCode, byte[] authSEK, Connection conn) throws ITMException private String getGstr2Invoices(String authToken, String stateCode, String userName, String gstin, String periodCode, String siteCode, byte[] authSEK, Connection conn) throws ITMException
{ {
String retString = ""; String retString = "";
String errMsg = ""; String errMsg = "", gspAuthString = "", gspAuthSignature = "";
String transactionId = UUID.randomUUID().toString().replaceAll("-", ""); String transactionId = UUID.randomUUID().toString().replaceAll("-", "");
try try
{ {
HttpResponse<JsonNode> getGstr2InvoicesResp = Unirest.get(String.format("%s/%s", GST_API_URL, GSTR2_URL_V3)) long timeStamp = new Timestamp().getDateTime();
gspAuthString = clientId + ":" + transactionId + ":" + timeStamp + ":" + gstin;
gspAuthSignature = gspSignature.sign(gspAuthString, aspPrivateKey);
HttpResponse<JsonNode> getGstr2InvoicesResp = Unirest.get(String.format("%s/%s", GSP_API_URL, GSTR2_URL_V3))
.queryString("action", "B2B") .queryString("action", "B2B")
.queryString("gstin", gstin) .queryString("gstin", gstin)
.queryString("ret_period", periodCode) .queryString("ret_period", periodCode)
...@@ -1451,6 +1511,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi ...@@ -1451,6 +1511,8 @@ public class GSTDataSubmitWizPos extends ValidatorEJB implements GSTDataSubmitWi
.header("txn", transactionId) .header("txn", transactionId)
.header("ret_period", periodCode) .header("ret_period", periodCode)
.header("gstin", gstin) .header("gstin", gstin)
.header("X-Asp-Auth-Token", gspAuthString)
.header("X-Asp-Auth-Signature", gspAuthSignature)
.asJson(); .asJson();
System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody())); System.out.println(String.format("getGstr2InvoicesResp Request : Status[%s] Response[%s]", getGstr2InvoicesResp.getStatus(), getGstr2InvoicesResp.getBody()));
......
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDAgsfg1BtqUKuA
VA0fNgVdkAK8osu+RrdgypJIrwdrYPm2MR1HqnwgbnUbNBZdX+kvW8VtM0QEwUvp
kllEmx6+oPgARo57V/man/BpdcftBqlKRTNR8d5CIiHvSkY7Hgf7WteuiSQ5d7WA
4mwnILmCgaPBGgvZikUev+ZJeXWVxtyOk/MYZRwJ0Tznz8BuD2xNz5MAI6Inv71A
ygUzy3gh0AdLGaRtqZTnZ/2jTfehvg/+A/ticiy74bc49jBdjSpEUpuSWckpEIFr
Ey1vj+fvVHSoOiogGtiuRifsC33mLb9TK1xpZYDPbM8UN8I2vB64QtpigoOEL/J+
IzKXooj9AgMBAAECggEAFZTTuYWtyR5gC5PgoLYapeGGHQWXF66v0h8DhThx+Xy2
odEhui4Hmk8nu7P8Kd2ds5xzJonPv0S4MOgiL8nACZjcFJPUV0mGhuoVNo1oq07K
3bOiTDZ0Ny/CZCQMeYYlWO1XLo7bS8H6zAcWHtDRWysTY4t69plEpGzY8TW3k+G0
g1xwgXBr/S5WGZBpU/dHNA7ubAnI/zy27ez5YahgQHeWmwHnh4Ap0rcSjoNNauQX
QlfUJp6+Gt/IqWSlm5d6QeC1SZe+lDmbH4K7TRs3PtnF6o0kmyJZQFIzVNlcxZfX
9kxL1xN6n/EoZcuxvxTJDV2MDsq1bwogdt5PB1XDQQKBgQDf3xUqDVHviMUw12Ws
ZztUJfLxFnP/THi0Erl9z/1+xy8TNFIg37eOF+g4tx106n1lvVLTlyRcOtTHiX/W
+G3sHPu/ybVVau0N6S5sQHzSE0XS3blES50vp6laO9SnJSYrvVSs8hfEZNEOKXxB
M2Oqo5hBkA+Ebmpjd68QJkky0QKBgQDcI4cnDpjAXJa3kg046doU50p6ttdbdclY
4YzXlD8U0RHPp/UJV4eRAbaR0hicJTP5/vAi72f99Ei1zZd8Z7KRspPmVL/nQI2/
o0eCb2nnnnykow7QAgij4WIaadb2AsJSYw/KSHZFKkJDD7vVYOsbmy3FPI7LUL5L
JiKIepcGbQKBgQDKngp2s/WLeVsXmGvCPPB6eZpGz46O6vR37laJ4xxIiRg3JmyK
qlBkP4kDA+CaN7zkvxRewvW6r9hy/CSDOPer8pN7gqEnPQ5uP7SvbzJJo/3XGqwa
fuE2B2YEcBBIcxv4DHS9zqLqMmDvk2aNUGiNQWGFPVB+CL0rZ2A/mpc3cQKBgQCa
On3m3DAinPuu8rE2zYfPm1ev78ejuTrufV8qbh9f2zXqUVa4S82bxyJ8uUAqrVnj
7TuajjZCUtJaJQbbzt7per5p4bhtMOneeGuSM7Jz5rKWufKXwsUA49fSf5Jt2vL/
u42FgAz0Wi4AQ9aqIPO27Jo9lDbKtPANQFNzYMfMZQKBgAF5I0HUF4taJ6/+lJot
0ELRZw2yuXSbxf0OYRW3LEgcTt7i+Gp9bY/AiBzEOcyL2lVZ8NWpK2aUMrUjWms8
4ZWEIS58FyvKjmWe7k7IVY0Bd9bOVMZsbjqRB42EyrXWyIHwroSEufSANTdl8UiW
RbN/8Jo2oRwiL5s9tSeON5Oa
-----END PRIVATE KEY-----
package ibase.webitm.util.gst;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import javax.crypto.KeyGenerator;
import javax.xml.bind.DatatypeConverter;
import ibase.planner.utility.ITMException;
public class GSPSignature
{
private static KeyGenerator KEYGEN;
final String CHARACTER_ENCODING = "UTF-8";
final String AES_ALGORITHM = "AES";
final int ENC_BITS = 256;
public GSPSignature()
{
try
{
KEYGEN = KeyGenerator.getInstance(AES_ALGORITHM);
KEYGEN.init(ENC_BITS);
}
catch (Exception e)
{
System.out.println("GSPSignature.GSPSignature()["+e.getMessage()+"]");
e.printStackTrace();
}
}
public PrivateKey loadPrivateKey(InputStream privateKeyInputStream) throws IOException, GeneralSecurityException, ITMException
{
PrivateKey key = null;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(privateKeyInputStream));
StringBuilder builder = new StringBuilder();
boolean inKey = false;
for (String line = br.readLine(); line != null; line = br.readLine())
{
if (!inKey)
{
if (line.startsWith("-----BEGIN ") && line.endsWith(" PRIVATE KEY-----"))
{
inKey = true;
}
continue;
}
else
{
if (line.startsWith("-----END ") && line.endsWith(" PRIVATE KEY-----"))
{
inKey = false;
break;
}
builder.append(line);
}
}
byte[] encoded = DatatypeConverter.parseBase64Binary(builder.toString());
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
KeyFactory kf = KeyFactory.getInstance("RSA");
key = kf.generatePrivate(keySpec);
}
catch (Exception e)
{
System.out.println("GSPSignature.loadPrivateKey()["+e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
return key;
}
public String sign(String message, PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException
{
Signature sig = Signature.getInstance("SHA1WithRSA");
sig.initSign(privateKey);
sig.update(message.getBytes());
byte[] signatureBytes = sig.sign();
String signature = Base64.getEncoder().encodeToString(signatureBytes);
System.out.println("Signature:" + signature);
return signature;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment