From ad0a1176ba601c12b1cdd29aee7725ff278f5d67 Mon Sep 17 00:00:00 2001 From: Juan Gamez Date: Mon, 6 Aug 2018 13:20:07 -0500 Subject: [PATCH] =?UTF-8?q?Agregado:=20Cancelaci=C3=B3n=20por=20uuid,=20ca?= =?UTF-8?q?ncelaci=C3=B3n=20por=20pfx,=20validaci=C3=B3n=20xml,=20validaci?= =?UTF-8?q?=C3=B3n=20lrfc,=20validaci=C3=B3n=20lco,=20generaci=C3=B3n=20de?= =?UTF-8?q?=20pdf=20Fix:=20cambiadas=20solicitudes=20de=20unirest=20por=20?= =?UTF-8?q?apache.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 34 +++ .project | 23 ++ .settings/org.eclipse.jdt.core.prefs | 9 + .settings/org.eclipse.m2e.core.prefs | 4 + pom.xml | 38 +-- .../SWAuthenticationService.java | 4 +- .../SWBalanceAccountService.java | 7 +- .../Cancelation/SWCancelationService.java | 39 +++- src/main/java/Services/Pdf/SWPdfService.java | 49 ++++ src/main/java/Services/SWService.java | 6 +- .../java/Services/Stamp/SWStampService.java | 10 +- .../Services/Validate/SWValidateService.java | 62 +++++ src/main/java/Utils/Constants.java | 23 +- src/main/java/Utils/EncoderHelper.java | 4 - .../Requests/Authentication/AuthRequest.java | 48 ++-- .../BalanceAccount/BalanceAcctRequest.java | 44 ++-- .../CancelationOptionsRequest.java | 18 +- .../Cancelation/CancelationRequest.java | 218 +++++++++++++----- src/main/java/Utils/Requests/IRequestor.java | 7 +- .../Utils/Requests/Pdf/PdfOptionsRequest.java | 38 +++ .../java/Utils/Requests/Pdf/PdfRequest.java | 89 +++++++ .../Utils/Requests/Stamp/StampRequest.java | 54 ++--- .../Validate/ValidateLcoOptionsRequest.java | 13 ++ .../Requests/Validate/ValidateLcoRequest.java | 62 +++++ .../Validate/ValidateLrfcOptionsRequest.java | 13 ++ .../Validate/ValidateLrfcRequest.java | 62 +++++ .../Validate/ValidateXmlOptionsRequest.java | 17 ++ .../Requests/Validate/ValidateXmlRequest.java | 93 ++++++++ src/main/java/Utils/Responses/DetailData.java | 12 + src/main/java/Utils/Responses/DetailNode.java | 12 + .../java/Utils/Responses/PdfResponse.java | 30 +++ .../Utils/Responses/ValidateLcoResponse.java | 24 ++ .../Utils/Responses/ValidateLrfcResponse.java | 19 ++ .../Utils/Responses/ValidateXmlResponse.java | 27 +++ .../SWAuthenticationServiceTest.java | 2 +- .../SWBalanceAccountServiceTest.java | 5 +- .../Cancelation/SWCancelationServiceTest.java | 189 +++++++++++++-- src/test/java/Tests/Pdf/SWPdfServiceTest.java | 69 ++++++ .../java/Tests/Stamp/SWStampServiceTest.java | 7 - .../Tests/Validate/SWValidateServiceTest.java | 120 ++++++++++ src/test/java/Tests/assets/Sign.java | 25 -- 41 files changed, 1380 insertions(+), 249 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 src/main/java/Services/Pdf/SWPdfService.java create mode 100644 src/main/java/Services/Validate/SWValidateService.java create mode 100644 src/main/java/Utils/Requests/Pdf/PdfOptionsRequest.java create mode 100644 src/main/java/Utils/Requests/Pdf/PdfRequest.java create mode 100644 src/main/java/Utils/Requests/Validate/ValidateLcoOptionsRequest.java create mode 100644 src/main/java/Utils/Requests/Validate/ValidateLcoRequest.java create mode 100644 src/main/java/Utils/Requests/Validate/ValidateLrfcOptionsRequest.java create mode 100644 src/main/java/Utils/Requests/Validate/ValidateLrfcRequest.java create mode 100644 src/main/java/Utils/Requests/Validate/ValidateXmlOptionsRequest.java create mode 100644 src/main/java/Utils/Requests/Validate/ValidateXmlRequest.java create mode 100644 src/main/java/Utils/Responses/DetailData.java create mode 100644 src/main/java/Utils/Responses/DetailNode.java create mode 100644 src/main/java/Utils/Responses/PdfResponse.java create mode 100644 src/main/java/Utils/Responses/ValidateLcoResponse.java create mode 100644 src/main/java/Utils/Responses/ValidateLrfcResponse.java create mode 100644 src/main/java/Utils/Responses/ValidateXmlResponse.java create mode 100644 src/test/java/Tests/Pdf/SWPdfServiceTest.java create mode 100644 src/test/java/Tests/Validate/SWValidateServiceTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..a181678 --- /dev/null +++ b/.classpath @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..c9ceaa6 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + SW-JAVA + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..4e4a3ad --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml index ca38f06..7b507ee 100644 --- a/pom.xml +++ b/pom.xml @@ -1,20 +1,14 @@ - + 4.0.0 - mx.com.sw.services SW-JAVA 0.0.3.4 - jar - https://github.com/lunasoft/sw-sdk-java scm:git:git@github.com:lunasoft/sw-sdk-java.git scm:git:git@github.com:lunasoft/sw-sdk-java.git - @@ -95,6 +89,9 @@ org.apache.maven.plugins maven-gpg-plugin + + true + 1.6 @@ -106,7 +103,6 @@ - org.sonatype.plugins nexus-staging-maven-plugin @@ -118,7 +114,6 @@ true - org.apache.maven.plugins maven-source-plugin @@ -132,7 +127,6 @@ - org.apache.maven.plugins maven-javadoc-plugin @@ -158,9 +152,24 @@ 4.12 - com.github.bingoohuang - unirest-java - 0.0.1 + org.apache.httpcomponents + httpclient + 4.5.6 + + + org.apache.httpcomponents + httpasyncclient + 4.1.4 + + + org.apache.httpcomponents + httpmime + 4.5.6 + + + org.json + json + 20180130 com.googlecode.juniversalchardet @@ -172,8 +181,5 @@ org.apache.servicemix.bundles.not-yet-commons-ssl 0.3.11_1 - - - \ No newline at end of file diff --git a/src/main/java/Services/Authentication/SWAuthenticationService.java b/src/main/java/Services/Authentication/SWAuthenticationService.java index 8d41849..35f50d6 100644 --- a/src/main/java/Services/Authentication/SWAuthenticationService.java +++ b/src/main/java/Services/Authentication/SWAuthenticationService.java @@ -1,5 +1,7 @@ package Services.Authentication; +import java.io.IOException; + import Exceptions.AuthException; import Exceptions.GeneralException; import Services.SWService; @@ -13,7 +15,7 @@ public SWAuthenticationService(String user, String password, String URI) { } - public IResponse Token() throws GeneralException, AuthException { + public IResponse Token() throws GeneralException, AuthException, IOException { AuthOptionsRequest settings = new AuthOptionsRequest(getURI(),getUser(),getPassword()); diff --git a/src/main/java/Services/BalanceAccount/SWBalanceAccountService.java b/src/main/java/Services/BalanceAccount/SWBalanceAccountService.java index d25c08f..59d7ce2 100644 --- a/src/main/java/Services/BalanceAccount/SWBalanceAccountService.java +++ b/src/main/java/Services/BalanceAccount/SWBalanceAccountService.java @@ -1,13 +1,12 @@ package Services.BalanceAccount; +import java.io.IOException; + //@author: Lupita Alvarado import Exceptions.AuthException; import Exceptions.GeneralException; import Services.SWService; -import Utils.Constants; -import Utils.Requests.Authentication.AuthOptionsRequest; -import Utils.Requests.Authentication.AuthRequest; import Utils.Requests.BalanceAccount.BalanceAcctOptionsRequest; import Utils.Requests.BalanceAccount.BalanceAcctRequest; import Utils.Responses.IResponse; @@ -23,7 +22,7 @@ public SWBalanceAccountService(String token, String URI) { super(token, URI); } - public IResponse GetBalanceAccount() throws AuthException, GeneralException { + public IResponse GetBalanceAccount() throws AuthException, GeneralException, IOException { if (getToken()==null){ diff --git a/src/main/java/Services/Cancelation/SWCancelationService.java b/src/main/java/Services/Cancelation/SWCancelationService.java index 64a4cb7..6c7662f 100644 --- a/src/main/java/Services/Cancelation/SWCancelationService.java +++ b/src/main/java/Services/Cancelation/SWCancelationService.java @@ -1,11 +1,10 @@ package Services.Cancelation; +import java.io.IOException; + import Exceptions.AuthException; import Exceptions.GeneralException; import Services.SWService; -import Utils.Constants; -import Utils.Requests.Authentication.AuthOptionsRequest; -import Utils.Requests.Authentication.AuthRequest; import Utils.Requests.Cancelation.CancelationOptionsRequest; import Utils.Requests.Cancelation.CancelationRequest; import Utils.Responses.IResponse; @@ -23,7 +22,7 @@ public SWCancelationService(String token, String URI) { } - public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Cer, String b64Key) throws AuthException, GeneralException { + public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Cer, String b64Key) throws AuthException, GeneralException, IOException { if (getToken()==null){ generateToken(); @@ -38,7 +37,7 @@ public IResponse Cancelation(String uuid, String password_csd, String rfc, Strin } - public IResponse Cancelation(String xml) throws AuthException, GeneralException { + public IResponse Cancelation(String xml) throws AuthException, GeneralException, IOException { if (getToken()==null){ generateToken(); @@ -53,4 +52,34 @@ public IResponse Cancelation(String xml) throws AuthException, GeneralException } + public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Pfx) throws AuthException, GeneralException, IOException { + + if (getToken()==null){ + generateToken(); + } + + //MAKE CANCELATION PROCESS, CUSTOMER ALREADY HAS TOKEN + + CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(),getURI(),uuid, password_csd, rfc, b64Pfx); + + CancelationRequest req = new CancelationRequest(); + return req.sendRequestPfx(settings); + + } + + public IResponse Cancelation(String uuid, String rfc) throws AuthException, GeneralException, IOException { + + if (getToken()==null){ + generateToken(); + } + + //MAKE CANCELATION PROCESS, CUSTOMER ALREADY HAS TOKEN + + CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(),getURI(),uuid, rfc); + + CancelationRequest req = new CancelationRequest(); + return req.sendRequestUuid(settings); + + } + } diff --git a/src/main/java/Services/Pdf/SWPdfService.java b/src/main/java/Services/Pdf/SWPdfService.java new file mode 100644 index 0000000..7a7f54a --- /dev/null +++ b/src/main/java/Services/Pdf/SWPdfService.java @@ -0,0 +1,49 @@ +package Services.Pdf; + +import java.io.IOException; + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Services.SWService; +import Utils.Requests.Pdf.PdfOptionsRequest; +import Utils.Requests.Pdf.PdfRequest; +import Utils.Responses.IResponse; + + +public class SWPdfService extends SWService { + + public SWPdfService(String user, String password, String URI) { + super(user, password, URI); + } + + public SWPdfService(String token, String URI) { + super(token, URI); + } + + public IResponse GeneratePdf(String xml) throws AuthException, GeneralException, IOException { + if (getToken()==null){ + generateToken(); + } + PdfOptionsRequest settings = new PdfOptionsRequest(getToken(),getURI(), xml); + PdfRequest req = new PdfRequest(); + return req.sendRequest(settings); + } + + public IResponse GeneratePdf(String xml, String extras) throws AuthException, GeneralException, IOException { + if (getToken()==null){ + generateToken(); + } + PdfOptionsRequest settings = new PdfOptionsRequest(getToken(),getURI(), xml, extras); + PdfRequest req = new PdfRequest(); + return req.sendRequest(settings); + } + + public IResponse GeneratePdf(String xml, String extras, String templateId) throws AuthException, GeneralException, IOException { + if (getToken()==null){ + generateToken(); + } + PdfOptionsRequest settings = new PdfOptionsRequest(getToken(),getURI(), xml, extras, templateId); + PdfRequest req = new PdfRequest(); + return req.sendRequest(settings); + } +} \ No newline at end of file diff --git a/src/main/java/Services/SWService.java b/src/main/java/Services/SWService.java index dd354c6..4962cf7 100644 --- a/src/main/java/Services/SWService.java +++ b/src/main/java/Services/SWService.java @@ -1,11 +1,11 @@ package Services; +import java.io.IOException; + import Exceptions.AuthException; import Exceptions.GeneralException; -import Utils.Constants; import Utils.Requests.Authentication.AuthOptionsRequest; import Utils.Requests.Authentication.AuthRequest; -import Utils.Responses.IResponse; import Utils.Responses.SuccessAuthResponse; public abstract class SWService { @@ -55,7 +55,7 @@ public void setPassword(String password) { Password = password; } - public void generateToken() throws AuthException, GeneralException { + public void generateToken() throws AuthException, GeneralException, IOException { if (User == null || Password == null) { //CUSTOMER HASN'T TOKEN, USER AND PASSWORD--> WE CANT' DO ANYTHING --> THROW EXCEPTION diff --git a/src/main/java/Services/Stamp/SWStampService.java b/src/main/java/Services/Stamp/SWStampService.java index ff52f77..7048a72 100644 --- a/src/main/java/Services/Stamp/SWStampService.java +++ b/src/main/java/Services/Stamp/SWStampService.java @@ -8,7 +8,7 @@ import Utils.Responses.IResponse; - +import java.io.IOException; import java.nio.charset.Charset; @@ -23,7 +23,7 @@ public SWStampService(String token, String URI) { super(token, URI); } - public IResponse Stamp(String xml, String version) throws AuthException, GeneralException { + public IResponse Stamp(String xml, String version) throws AuthException, GeneralException, IOException { @@ -40,7 +40,7 @@ public IResponse Stamp(String xml, String version) throws AuthException, General } // - public IResponse Stamp(String xml, String version, boolean isb64) throws AuthException, GeneralException { + public IResponse Stamp(String xml, String version, boolean isb64) throws AuthException, GeneralException, IOException { @@ -64,7 +64,7 @@ public IResponse Stamp(String xml, String version, boolean isb64) throws AuthExc } - public IResponse Stamp(byte[] xmlFile, String version, boolean isb64) throws AuthException, GeneralException { + public IResponse Stamp(byte[] xmlFile, String version, boolean isb64) throws AuthException, GeneralException, IOException{ //BINARY XML @@ -86,7 +86,7 @@ public IResponse Stamp(byte[] xmlFile, String version, boolean isb64) throws Aut } - public IResponse Stamp(byte[] xmlFile, String version) throws AuthException, GeneralException { + public IResponse Stamp(byte[] xmlFile, String version) throws AuthException, GeneralException, IOException { //BINARY XML diff --git a/src/main/java/Services/Validate/SWValidateService.java b/src/main/java/Services/Validate/SWValidateService.java new file mode 100644 index 0000000..4232f37 --- /dev/null +++ b/src/main/java/Services/Validate/SWValidateService.java @@ -0,0 +1,62 @@ +package Services.Validate; + +import java.io.IOException; + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Services.SWService; +import Utils.Requests.Validate.ValidateLcoOptionsRequest; +import Utils.Requests.Validate.ValidateLcoRequest; +import Utils.Requests.Validate.ValidateLrfcOptionsRequest; +import Utils.Requests.Validate.ValidateLrfcRequest; +import Utils.Requests.Validate.ValidateXmlOptionsRequest; +import Utils.Requests.Validate.ValidateXmlRequest; +import Utils.Responses.IResponse; + + +public class SWValidateService extends SWService { + + public SWValidateService(String user, String password, String URI) { + super(user, password, URI); + } + + public SWValidateService(String token, String URI) { + super(token, URI); + } + + public IResponse ValidateXml(String xml) throws AuthException, GeneralException, IOException { + + if (getToken()==null){ + generateToken(); + } + + ValidateXmlOptionsRequest settings = new ValidateXmlOptionsRequest(getToken(),getURI(), xml); + + ValidateXmlRequest req = new ValidateXmlRequest(); + return req.sendRequest(settings); + } + + public IResponse ValidateLrfc(String Lrfc) throws AuthException, GeneralException, IOException { + + if (getToken()==null){ + generateToken(); + } + + ValidateLrfcOptionsRequest settings = new ValidateLrfcOptionsRequest(getToken(),getURI(), Lrfc); + + ValidateLrfcRequest req = new ValidateLrfcRequest(); + return req.sendRequest(settings); + } + + public IResponse ValidateLco(String Lco) throws AuthException, GeneralException, IOException { + + if (getToken()==null){ + generateToken(); + } + + ValidateLcoOptionsRequest settings = new ValidateLcoOptionsRequest(getToken(),getURI(), Lco); + + ValidateLcoRequest req = new ValidateLcoRequest(); + return req.sendRequest(settings); + } +} diff --git a/src/main/java/Utils/Constants.java b/src/main/java/Utils/Constants.java index c3b50ea..37a595a 100644 --- a/src/main/java/Utils/Constants.java +++ b/src/main/java/Utils/Constants.java @@ -6,22 +6,11 @@ public class Constants { public static String STAMP_PATH = "/cfdi33/stamp/"; public static String CANCELATION_CSD_PATH = "/cfdi33/cancel/csd"; public static String CANCELATION_XML_PATH = "/cfdi33/cancel/xml"; + public static String CANCELATION_PFX_PATH = "/cfdi33/cancel/pfx"; + public static String CANCELATION_UUID_PATH = "/cfdi33/cancel/"; public static String BALANCE_ACCOUNT_PATH = "/account/balance/"; - - public static String auth_soap_envelope(String user, String pwd){ - return "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " "+user+"\n" + - " \n" + - " "+pwd+"\n" + - " \n" + - " \n" + - ""; - } - - - + public static String VALIDATE_XML_PATH = "/validate/cfdi33"; + public static String VALIDATE_LRFC_PATH = "/lrfc/"; + public static String VALIDATE_LCO_PATH = "/lco/"; + public static String GENERATE_PDF_PATH = "/pdf/v1/generate"; } diff --git a/src/main/java/Utils/EncoderHelper.java b/src/main/java/Utils/EncoderHelper.java index 66650d0..7bd58a9 100644 --- a/src/main/java/Utils/EncoderHelper.java +++ b/src/main/java/Utils/EncoderHelper.java @@ -42,10 +42,6 @@ public static boolean lector( String input, String encoding) { } public static boolean isValidUTF8( String input ) { - - - - try { byte[] buf = new byte[4096]; int nread; diff --git a/src/main/java/Utils/Requests/Authentication/AuthRequest.java b/src/main/java/Utils/Requests/Authentication/AuthRequest.java index 4e7113c..a990077 100644 --- a/src/main/java/Utils/Requests/Authentication/AuthRequest.java +++ b/src/main/java/Utils/Requests/Authentication/AuthRequest.java @@ -5,20 +5,23 @@ import Utils.Requests.IRequest; import Utils.Requests.IRequestor; import Utils.Responses.*; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; -import java.net.MalformedURLException; +import java.io.IOException; public class AuthRequest implements IRequestor { @Override - public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException, IOException { if (request.URI.isEmpty()){ throw new GeneralException(500,"URL VACIA"); @@ -26,35 +29,38 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce String messageDetail = ""; try { - - HttpResponse response = Unirest.post(request.URI) - .header("user",request.User) - .header("password",request.Password).asJson(); - if(!response.getBody().toString().isEmpty()) { - JSONObject body = new JSONObject(response.getBody().toString()); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(request.URI); + httppost.setHeader("user", request.User); + httppost.addHeader("password", request.Password); + + CloseableHttpResponse responseB = client.execute(httppost); + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); if(!body.isNull("messageDetail")){ messageDetail = body.getString("messageDetail"); } - if(response.getStatus()==200){ + if(statusE==200){ JSONObject data = body.getJSONObject("data"); - return new SuccessAuthResponse(response.getStatus(),body.getString("status"),data.getString("token"),"OK","OK"); + return new SuccessAuthResponse(statusE,body.getString("status"),data.getString("token"),"OK","OK"); } else{ - return new SuccessAuthResponse(response.getStatus(),body.getString("status"),"",body.getString("message"),messageDetail); + return new SuccessAuthResponse(statusE,body.getString("status"),"",body.getString("message"),messageDetail); } } else{ - return new SuccessAuthResponse(response.getStatus(),"error","",response.getStatusText(),response.getStatusText()); + return new SuccessAuthResponse(statusE,"error","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase()); } - } catch (UnirestException e) { - - throw new GeneralException(500,"SERVIDOR INACTIVO"); - } - catch(JSONException e){ + } catch(JSONException e){ throw new GeneralException(500,e.getMessage()); } diff --git a/src/main/java/Utils/Requests/BalanceAccount/BalanceAcctRequest.java b/src/main/java/Utils/Requests/BalanceAccount/BalanceAcctRequest.java index d151c5a..a4d2e33 100644 --- a/src/main/java/Utils/Requests/BalanceAccount/BalanceAcctRequest.java +++ b/src/main/java/Utils/Requests/BalanceAccount/BalanceAcctRequest.java @@ -6,9 +6,15 @@ import Utils.Requests.IRequestor; import Utils.Responses.BalanceAcctResponse; import Utils.Responses.IResponse; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; + +import java.io.IOException; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; @@ -16,19 +22,24 @@ public class BalanceAcctRequest implements IRequestor { @Override - public IResponse sendRequest(IRequest request) throws GeneralException, AuthException, GeneralException { + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException, GeneralException, IOException { try { - - HttpResponse response = Unirest.get(request.URI) - .header("Authorization", "bearer " + request.Token).asString(); - - if (!response.getBody().equalsIgnoreCase("{}") && !response.getBody().equalsIgnoreCase("")) { - JSONObject body = new JSONObject(response.getBody()); - - if (response.getStatus() == 200) { + CloseableHttpClient client = HttpClients.createDefault(); + HttpGet httpget = new HttpGet(request.URI); + httpget.setHeader("Authorization", "bearer " + request.Token); + + CloseableHttpResponse responseB = client.execute(httpget); + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if (statusE == 200) { JSONObject data = body.getJSONObject("data"); - return new BalanceAcctResponse(response.getStatus(), body.getString("status"), + return new BalanceAcctResponse(statusE, body.getString("status"), data.getString("idSaldoCliente"), data.getString("idClienteUsuario"), data.getInt("saldoTimbres"), data.getInt("timbresUtilizados"), data.getString("fechaExpiracion"), data.getBoolean("unlimited"), data.getInt("timbresAsignados"),"OK","OK"); } @@ -38,15 +49,12 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce if (!body.isNull("messageDetail")) { messageDetail = body.getString("messageDetail"); } - return new BalanceAcctResponse(response.getStatus(), body.getString("status"), body.getString("message"), messageDetail); + return new BalanceAcctResponse(statusE, body.getString("status"), body.getString("message"), messageDetail); } } else { - return new BalanceAcctResponse(response.getStatus(), "error", response.getStatusText(), response.getStatusText()); + return new BalanceAcctResponse(statusE, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase()); } - } catch (UnirestException e) { - - throw new GeneralException(404, "HOST DESCONOCIDO"); } catch (JSONException e) { throw new GeneralException(500, e.getMessage()); } diff --git a/src/main/java/Utils/Requests/Cancelation/CancelationOptionsRequest.java b/src/main/java/Utils/Requests/Cancelation/CancelationOptionsRequest.java index f7a66c3..24faabe 100644 --- a/src/main/java/Utils/Requests/Cancelation/CancelationOptionsRequest.java +++ b/src/main/java/Utils/Requests/Cancelation/CancelationOptionsRequest.java @@ -10,6 +10,7 @@ public class CancelationOptionsRequest extends IRequest{ private String rfc; private String b64Cer; private String b64key; + private String b64Pfx; private String xml; @@ -23,10 +24,23 @@ public CancelationOptionsRequest(String token, String URI, String uuid, String p this.b64key = b64Key; } + public CancelationOptionsRequest(String token, String URI, String uuid, String password_csd, String rfc, String b64Pfx) { + super(token, URI+ Constants.CANCELATION_CSD_PATH); + this.uuid = uuid; + this.password_csd = password_csd; + this.rfc = rfc; + this.b64Pfx = b64Pfx; + } + public CancelationOptionsRequest(String token, String URI, String xml) { super(token, URI+ Constants.CANCELATION_XML_PATH); this.xml = xml; } + public CancelationOptionsRequest(String token, String URI, String uuid, String rfc) { + super(token, URI+ Constants.CANCELATION_UUID_PATH+rfc+"/"+uuid); + this.uuid = uuid; + this.rfc = rfc; + } public String getUuid() { return uuid; @@ -51,6 +65,8 @@ public String getB64key() { public String getXml() { return xml; } - + public String getB64Pfx() { + return b64Pfx; + } } diff --git a/src/main/java/Utils/Requests/Cancelation/CancelationRequest.java b/src/main/java/Utils/Requests/Cancelation/CancelationRequest.java index a3ab65f..9eb9c61 100644 --- a/src/main/java/Utils/Requests/Cancelation/CancelationRequest.java +++ b/src/main/java/Utils/Requests/Cancelation/CancelationRequest.java @@ -5,57 +5,68 @@ import Utils.Requests.IRequest; import Utils.Requests.IRequestor; import Utils.Responses.*; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.util.UUID; +import org.apache.http.HttpEntity; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicHeader; +import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; public class CancelationRequest implements IRequestor { - public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException, IOException { try { - - HttpResponse response = Unirest.post(request.URI) - .header("Authorization", "bearer " + request.Token) - .header("Content-Type", "application/json") - .body("{\r\n \"uuid\": \"" + ((CancelationOptionsRequest) request).getUuid() + "\",\r\n \"password\": \"" + ((CancelationOptionsRequest) request).getPassword_csd() + "\",\r\n \"rfc\": \"" + ((CancelationOptionsRequest) request).getRfc() + "\",\r\n \"b64Cer\": \"" + ((CancelationOptionsRequest) request).getB64Cer() + "\",\r\n \"b64Key\": \"" + ((CancelationOptionsRequest) request).getB64key() + "\"\r\n}").asString(); - - if (!response.getBody().equalsIgnoreCase("{}") && !response.getBody().equals("")) { - JSONObject body = new JSONObject(response.getBody()); - - if (response.getStatus() == 200) { - - JSONObject data = body.getJSONObject("data"); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(request.URI); + httppost.setHeader(new BasicHeader("Authorization", "bearer " + request.Token));//set First Header + httppost.addHeader(new BasicHeader("Content-Type", "application/json"));//other header + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + Charset chars = Charset.forName("UTF-8"); + builder.setCharset(chars); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + StringEntity sEntity = new StringEntity("{\r\n \"uuid\": \"" + ((CancelationOptionsRequest) request).getUuid() + "\",\r\n \"password\": \"" + ((CancelationOptionsRequest) request).getPassword_csd() + "\",\r\n \"rfc\": \"" + ((CancelationOptionsRequest) request).getRfc() + "\",\r\n \"b64Cer\": \"" + ((CancelationOptionsRequest) request).getB64Cer() + "\",\r\n \"b64Key\": \"" + ((CancelationOptionsRequest) request).getB64key() + "\"\r\n}"); + httppost.setEntity(builder.build()); + httppost.setEntity(sEntity); + CloseableHttpResponse responseB = client.execute(httppost); + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = body.getJSONObject("data"); String uuid = ((CancelationOptionsRequest) request).getUuid().toUpperCase(); JSONObject uuid_data = data.getJSONObject("uuid"); String uuidSC = uuid_data.getString(uuid); - return new CancelationResponse(response.getStatus(), body.getString("status"), data.getString("acuse"), uuid, Integer.parseInt(uuidSC),"OK","OK"); - } - else { - + return new CancelationResponse(statusE, body.getString("status"), data.getString("acuse"), uuid, Integer.parseInt(uuidSC),"OK","OK"); + } + else { String messageDetail = ""; - if (!body.isNull("messageDetail")) { messageDetail = body.getString("messageDetail"); } - return new CancelationResponse(response.getStatus(),body.getString("status"),body.getString("message"),messageDetail); + return new CancelationResponse(statusE,body.getString("status"),body.getString("message"),messageDetail); } - } else { - return new CancelationResponse(response.getStatus(), "error", response.getStatusText(), response.getStatusText()); } - - } catch (UnirestException ex) { - throw new GeneralException(404, "HOST DESCONOCIDO"); + else { + return new CancelationResponse(statusE, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase()); + } } catch (JSONException e) { throw new GeneralException(500, e.getMessage()); } @@ -64,51 +75,134 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce - public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralException, AuthException { + public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralException, AuthException, IOException { try { - - String xmlStr = ((CancelationOptionsRequest) request).getXml(); + String xmlStr = ((CancelationOptionsRequest) request).getXml(); String boundary = UUID.randomUUID().toString(); String raw = "--" + boundary + "\r\nContent-Disposition: form-data; name=xml; filename=xml\r\nContent-Type: application/xml\r\n\r\n" + xmlStr + "\r\n--" + boundary + "--"; - - Unirest.setTimeouts(60000, 360000); - HttpResponse response = Unirest.post(request.URI) - .header("Authorization", "bearer " + request.Token) - .header("content-type", "multipart/form-data; boundary=" + boundary) - .body(raw).asJson(); - - if (!response.getBody().toString().equalsIgnoreCase("{}") && !response.getBody().equals("")) { - JSONObject body = new JSONObject(response.getBody().toString()); - - if (response.getStatus() == 200) { - - JSONObject data = body.getJSONObject("data"); - String xml = ((CancelationOptionsRequest) request).getXml(); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(request.URI); + httppost.setHeader(new BasicHeader("Authorization", "bearer " + request.Token)); + httppost.addHeader(new BasicHeader("content-type", "multipart/form-data; boundary=" + boundary)); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + Charset chars = Charset.forName("UTF-8"); + builder.setCharset(chars); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + builder.addTextBody("xml", raw, ContentType.DEFAULT_BINARY); + httppost.setEntity(builder.build()); + + CloseableHttpResponse responseB = client.execute(httppost); + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = body.getJSONObject("data"); + String xml = ((CancelationOptionsRequest) request).getXml(); String uuid = xml.substring(xml.indexOf("") + 6, xml.indexOf("")).toUpperCase(); JSONObject uuid_data = data.getJSONObject("uuid"); String uuidSC = uuid_data.getString(uuid); - return new CancelationResponse(response.getStatus(), body.getString("status"), data.getString("acuse"), uuid, Integer.parseInt(uuidSC),"OK","OK"); - - } else { - - String messageDetail = null; + return new CancelationResponse(statusE, body.getString("status"), data.getString("acuse"), uuid, Integer.parseInt(uuidSC),"OK","OK"); + } + else { + String messageDetail = null; + if (!body.isNull("messageDetail")) { + messageDetail = body.getString("messageDetail"); + } + return new CancelationResponse(statusE,body.getString("status"),body.getString("message"),messageDetail); + } + } + else { + return new CancelationResponse(statusE, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase()); + } + } catch (JSONException e) { + throw new GeneralException(500, e.getMessage()); + } + } + public IResponse sendRequestPfx(IRequest request) throws ClientProtocolException, IOException, GeneralException { + try { + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(request.URI); + httppost.setHeader(new BasicHeader("Authorization", "bearer " + request.Token));//set First Header + httppost.addHeader(new BasicHeader("Content-Type", "application/json"));//other header + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + Charset chars = Charset.forName("UTF-8"); + builder.setCharset(chars); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + StringEntity sEntity = new StringEntity("{\r\n \"uuid\": \"" + ((CancelationOptionsRequest) request).getUuid() + "\",\r\n \"password\": \"" + ((CancelationOptionsRequest) request).getPassword_csd() + "\",\r\n \"rfc\": \"" + ((CancelationOptionsRequest) request).getRfc() + "\",\r\n \"b64Pfx\": \"" + ((CancelationOptionsRequest) request).getB64Pfx() + "\"\r\n}"); + httppost.setEntity(builder.build()); + httppost.setEntity(sEntity); + CloseableHttpResponse responseB = client.execute(httppost); + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = body.getJSONObject("data"); + String uuid = ((CancelationOptionsRequest) request).getUuid().toUpperCase(); + JSONObject uuid_data = data.getJSONObject("uuid"); + String uuidSC = uuid_data.getString(uuid); + return new CancelationResponse(statusE, body.getString("status"), data.getString("acuse"), uuid, Integer.parseInt(uuidSC),"OK","OK"); + } + else { + String messageDetail = ""; if (!body.isNull("messageDetail")) { messageDetail = body.getString("messageDetail"); } - return new CancelationResponse(response.getStatus(),body.getString("status"),body.getString("message"),messageDetail); + return new CancelationResponse(statusE,body.getString("status"),body.getString("message"),messageDetail); } - } else { - return new CancelationResponse(response.getStatus(), "error", response.getStatusText(), response.getStatusText()); } - - } catch (UnirestException e) { - - throw new GeneralException(404, "HOST DESCONOCIDO"); + else { + return new CancelationResponse(statusE, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase()); + } + } catch (JSONException e) { + throw new GeneralException(500, e.getMessage()); + } + } + + public IResponse sendRequestUuid(IRequest request) throws ClientProtocolException, IOException, GeneralException { + try { + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(request.URI); + httppost.setHeader(new BasicHeader("Authorization", "bearer " + request.Token)); + + CloseableHttpResponse responseB = client.execute(httppost); + + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = body.getJSONObject("data"); + String uuid = ((CancelationOptionsRequest) request).getUuid().toUpperCase(); + JSONObject uuid_data = data.getJSONObject("uuid"); + String uuidSC = uuid_data.getString(uuid); + return new CancelationResponse(statusE, body.getString("status"), data.getString("acuse"), uuid, Integer.parseInt(uuidSC),"OK","OK"); + } + else { + String messageDetail = ""; + if (!body.isNull("messageDetail")) { + messageDetail = body.getString("messageDetail"); + } + return new CancelationResponse(statusE,body.getString("status"),body.getString("message"),messageDetail); + } + } + else { + return new CancelationResponse(statusE, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase()); + } } catch (JSONException e) { throw new GeneralException(500, e.getMessage()); } - } } diff --git a/src/main/java/Utils/Requests/IRequestor.java b/src/main/java/Utils/Requests/IRequestor.java index 875b050..47feebe 100644 --- a/src/main/java/Utils/Requests/IRequestor.java +++ b/src/main/java/Utils/Requests/IRequestor.java @@ -1,5 +1,10 @@ package Utils.Requests; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import org.apache.http.client.ClientProtocolException; + import Exceptions.AuthException; import Exceptions.GeneralException; import Exceptions.GeneralException; @@ -7,6 +12,6 @@ import Utils.Responses.IResponse; public interface IRequestor { - public IResponse sendRequest(IRequest request) throws GeneralException, AuthException, GeneralException; + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException, GeneralException, UnsupportedEncodingException, ClientProtocolException, IOException; } diff --git a/src/main/java/Utils/Requests/Pdf/PdfOptionsRequest.java b/src/main/java/Utils/Requests/Pdf/PdfOptionsRequest.java new file mode 100644 index 0000000..615b3da --- /dev/null +++ b/src/main/java/Utils/Requests/Pdf/PdfOptionsRequest.java @@ -0,0 +1,38 @@ +package Utils.Requests.Pdf; + +import Utils.Constants; +import Utils.Requests.IRequest; + +public class PdfOptionsRequest extends IRequest { + private String xml; + private String templateId; + private String extras; + + public PdfOptionsRequest(String token, String URI, String xml) { + super(token, URI+ Constants.GENERATE_PDF_PATH); + this.xml = xml; + } + public PdfOptionsRequest(String token, String URI, String xml, String extras) { + super(token, URI+ Constants.GENERATE_PDF_PATH); + this.xml = xml; + this.extras = extras; + } + public PdfOptionsRequest(String token, String URI, String xml, String extras, String templateId) { + super(token, URI+ Constants.GENERATE_PDF_PATH); + this.xml = xml; + this.extras = extras; + this.templateId = templateId; + } + + public String getTemplateId() { + return templateId; + } + + public String getExtras() { + return extras; + } + + public String getXml() { + return xml; + } +} \ No newline at end of file diff --git a/src/main/java/Utils/Requests/Pdf/PdfRequest.java b/src/main/java/Utils/Requests/Pdf/PdfRequest.java new file mode 100644 index 0000000..387dc23 --- /dev/null +++ b/src/main/java/Utils/Requests/Pdf/PdfRequest.java @@ -0,0 +1,89 @@ +package Utils.Requests.Pdf; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.UUID; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.JSONException; +import org.json.JSONObject; + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Utils.Requests.IRequest; +import Utils.Requests.IRequestor; +import Utils.Requests.Pdf.PdfOptionsRequest; +import Utils.Responses.IResponse; +import Utils.Responses.PdfResponse; + +public class PdfRequest implements IRequestor{ + + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { + try { + String boundary = UUID.randomUUID().toString(); + String xmlStr = ((PdfOptionsRequest) request).getXml(); + String raw = "--"+boundary+"\r\nContent-Disposition: form-data; name=file; filename=xml\r\nContent-Type: application/xml\r\n\r\n"+xmlStr+"\r\n--"+boundary+"--"; + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost http = new HttpPost(request.URI); + http.setHeader("Authorization", "Bearer " + request.Token); + http.addHeader("Content-Type", "multipart/form-data; boundary="+boundary); + if(((PdfOptionsRequest) request).getTemplateId() != null && !((PdfOptionsRequest) request).getTemplateId().isEmpty()) { + http.setHeader("TemplateId",((PdfOptionsRequest) request).getTemplateId()); + } + else { + http.setHeader("TemplateId","6c757687-7979-4a5b-b4e0-fe5d35d1f970"); + } + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + Charset chars = Charset.forName("UTF-8"); + builder.setCharset(chars); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + builder.addTextBody("file", raw, ContentType.DEFAULT_BINARY); + if(((PdfOptionsRequest) request).getTemplateId() != null && !((PdfOptionsRequest) request).getTemplateId().isEmpty()) { + builder.addTextBody("extras", ((PdfOptionsRequest) request).getExtras(), ContentType.APPLICATION_JSON); + } + http.setEntity(builder.build()); + + CloseableHttpResponse responseB = client.execute(http); + + HttpEntity entity = responseB.getEntity(); + + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + System.out.println(responseString); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = new JSONObject(body.get("data").toString()); + return new PdfResponse(statusE,body.get("message").toString(),data.get("contentB64").toString(),data.getInt("contentSizeBytes"),data.get("uuid").toString(),data.get("serie").toString(),data.get("folio").toString(),data.get("stampDate").toString(),data.get("issuedDate").toString(),data.get("rfcIssuer").toString(),data.get("rfcReceptor").toString(),data.get("total").toString(),"OK","OK"); + } + else { + String messageDetail = ""; + if (!body.isNull("messageDetail")) { + messageDetail = body.getString("messageDetail"); + } + return new PdfResponse(statusE, body.getString("message"), body.getString("message"), messageDetail); + } + } + else { + return new PdfResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase()); + } + } + catch (JSONException e){ + throw new GeneralException(500,e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + throw new GeneralException(500,e.getMessage()); + } + } + +} diff --git a/src/main/java/Utils/Requests/Stamp/StampRequest.java b/src/main/java/Utils/Requests/Stamp/StampRequest.java index abb516f..ae32e8d 100644 --- a/src/main/java/Utils/Requests/Stamp/StampRequest.java +++ b/src/main/java/Utils/Requests/Stamp/StampRequest.java @@ -5,60 +5,47 @@ import Utils.Requests.IRequest; import Utils.Requests.IRequestor; import Utils.Responses.*; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; - -import com.mashape.unirest.request.body.MultipartBody; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; -import org.apache.http.entity.mime.MultipartEntity; -import org.apache.http.entity.mime.content.StringBody; -import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; -import sun.misc.IOUtils; - import java.io.*; import java.nio.charset.Charset; -import java.util.Scanner; import java.util.UUID; public class StampRequest implements IRequestor { public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { - - try { - String xmlStr = ((StampOptionsRequest) request).getXml(); String boundary = UUID.randomUUID().toString(); String raw = "--"+boundary+"\r\nContent-Disposition: form-data; name=xml; filename=xml\r\nContent-Type: application/xml\r\n\r\n"+xmlStr+"\r\n--"+boundary+"--"; CloseableHttpClient client = HttpClients.createDefault(); HttpPost httppost = new HttpPost(request.URI); - MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE ); - StringBody xmlcfdi = new StringBody(raw, Charset.forName( "UTF-8" )); - entity.addPart("xml",xmlcfdi); - httppost.setEntity(entity); httppost.setHeader("Authorization", "bearer " + request.Token); - httppost.setHeader("Content-Type", "multipart/form-data; boundary="+boundary); + httppost.addHeader("Content-Type", "multipart/form-data; boundary="+boundary); httppost.addHeader("Content-Disposition", "form-data; name=xml; filename=xml"); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + Charset chars = Charset.forName("UTF-8"); + builder.setCharset(chars); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + builder.addTextBody("xml", raw, ContentType.DEFAULT_BINARY); + httppost.setEntity(builder.build()); + CloseableHttpResponse responseB = client.execute(httppost); - - InputStream inputStream = responseB.getEntity().getContent(); - - Scanner s = new Scanner(inputStream).useDelimiter("\\A"); - String responseString = s.hasNext() ? s.next() : ""; - + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); int statusE = responseB.getStatusLine().getStatusCode(); client.close(); + responseB.close(); if(!responseString.isEmpty()) { JSONObject body = new JSONObject(responseString); if(statusE==200){ @@ -84,8 +71,6 @@ else if(request.version.equalsIgnoreCase("v3")){ } else{ String messageDetail = ""; - - if (!body.isNull("messageDetail")){ messageDetail = body.getString("messageDetail"); } @@ -123,21 +108,8 @@ else if(request.version.equalsIgnoreCase("v3")){ else{ return new SuccessV1Response(statusE,"error","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase()); } - - } - - - - - - - - - - - } catch (JSONException e){ throw new GeneralException(500,e.getMessage()); diff --git a/src/main/java/Utils/Requests/Validate/ValidateLcoOptionsRequest.java b/src/main/java/Utils/Requests/Validate/ValidateLcoOptionsRequest.java new file mode 100644 index 0000000..1549e14 --- /dev/null +++ b/src/main/java/Utils/Requests/Validate/ValidateLcoOptionsRequest.java @@ -0,0 +1,13 @@ +package Utils.Requests.Validate; + +import Utils.Constants; +import Utils.Requests.IRequest; + +public class ValidateLcoOptionsRequest extends IRequest { + private String lco; + + public ValidateLcoOptionsRequest(String token, String URI, String Lco) { + super(token, URI+ Constants.VALIDATE_LCO_PATH+Lco); + this.lco = Lco; + } +} \ No newline at end of file diff --git a/src/main/java/Utils/Requests/Validate/ValidateLcoRequest.java b/src/main/java/Utils/Requests/Validate/ValidateLcoRequest.java new file mode 100644 index 0000000..195bafa --- /dev/null +++ b/src/main/java/Utils/Requests/Validate/ValidateLcoRequest.java @@ -0,0 +1,62 @@ +package Utils.Requests.Validate; + +import java.io.IOException; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.JSONException; +import org.json.JSONObject; + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Utils.Requests.IRequest; +import Utils.Requests.IRequestor; +import Utils.Responses.IResponse; +import Utils.Responses.ValidateLcoResponse; + +public class ValidateLcoRequest implements IRequestor{ + + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { + try { + CloseableHttpClient client = HttpClients.createDefault(); + HttpGet http = new HttpGet(request.URI); + http.setHeader("Authorization", "bearer " + request.Token); + CloseableHttpResponse responseB = client.execute(http); + + HttpEntity entity = responseB.getEntity(); + + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = new JSONObject(body.get("data").toString()); + return new ValidateLcoResponse(statusE,body.getString("status"),data.get("noCertificado").toString(),data.get("rfc").toString(),data.get("validezObligaciones").toString(),data.get("estatusCertificado").toString(),data.get("fechaInicio").toString(),data.get("fechaFinal").toString(),"OK","OK"); + } + else { + String messageDetail = ""; + if (!body.isNull("messageDetail")) { + messageDetail = body.getString("messageDetail"); + } + return new ValidateLcoResponse(statusE, body.getString("status"), body.getString("message"), messageDetail); + } + } + else { + return new ValidateLcoResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase()); + } + } + catch (JSONException e){ + throw new GeneralException(500,e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + throw new GeneralException(500,e.getMessage()); + } + } + +} diff --git a/src/main/java/Utils/Requests/Validate/ValidateLrfcOptionsRequest.java b/src/main/java/Utils/Requests/Validate/ValidateLrfcOptionsRequest.java new file mode 100644 index 0000000..1e96b45 --- /dev/null +++ b/src/main/java/Utils/Requests/Validate/ValidateLrfcOptionsRequest.java @@ -0,0 +1,13 @@ +package Utils.Requests.Validate; + +import Utils.Constants; +import Utils.Requests.IRequest; + +public class ValidateLrfcOptionsRequest extends IRequest { + private String lrfc; + + public ValidateLrfcOptionsRequest(String token, String URI, String Lrfc) { + super(token, URI+ Constants.VALIDATE_LRFC_PATH+Lrfc); + this.lrfc = Lrfc; + } +} \ No newline at end of file diff --git a/src/main/java/Utils/Requests/Validate/ValidateLrfcRequest.java b/src/main/java/Utils/Requests/Validate/ValidateLrfcRequest.java new file mode 100644 index 0000000..d279c94 --- /dev/null +++ b/src/main/java/Utils/Requests/Validate/ValidateLrfcRequest.java @@ -0,0 +1,62 @@ +package Utils.Requests.Validate; + +import java.io.IOException; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.JSONException; +import org.json.JSONObject; + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Utils.Requests.IRequest; +import Utils.Requests.IRequestor; +import Utils.Responses.IResponse; +import Utils.Responses.ValidateLrfcResponse; + +public class ValidateLrfcRequest implements IRequestor{ + + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { + try { + CloseableHttpClient client = HttpClients.createDefault(); + HttpGet http = new HttpGet(request.URI); + http.setHeader("Authorization", "bearer " + request.Token); + CloseableHttpResponse responseB = client.execute(http); + + HttpEntity entity = responseB.getEntity(); + + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + JSONObject data = new JSONObject(body.get("data").toString()); + return new ValidateLrfcResponse(statusE,body.getString("status"),data.get("contribuyenteRFC").toString(),data.getBoolean("sncf"),data.getBoolean("subcontratacion"),"OK","OK"); + } + else { + String messageDetail = ""; + if (!body.isNull("messageDetail")) { + messageDetail = body.getString("messageDetail"); + } + return new ValidateLrfcResponse(statusE, body.getString("status"), "", messageDetail); + } + } + else { + return new ValidateLrfcResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase()); + } + } + catch (JSONException e){ + throw new GeneralException(500,e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + throw new GeneralException(500,e.getMessage()); + } + } + +} diff --git a/src/main/java/Utils/Requests/Validate/ValidateXmlOptionsRequest.java b/src/main/java/Utils/Requests/Validate/ValidateXmlOptionsRequest.java new file mode 100644 index 0000000..3eb4ad5 --- /dev/null +++ b/src/main/java/Utils/Requests/Validate/ValidateXmlOptionsRequest.java @@ -0,0 +1,17 @@ +package Utils.Requests.Validate; + +import Utils.Constants; +import Utils.Requests.IRequest; + +public class ValidateXmlOptionsRequest extends IRequest { + private String xml; + + public ValidateXmlOptionsRequest(String token, String URI, String Xml) { + super(token, URI+ Constants.VALIDATE_XML_PATH); + this.xml = Xml; + } + + public String getXml() { + return xml; + } +} diff --git a/src/main/java/Utils/Requests/Validate/ValidateXmlRequest.java b/src/main/java/Utils/Requests/Validate/ValidateXmlRequest.java new file mode 100644 index 0000000..4027996 --- /dev/null +++ b/src/main/java/Utils/Requests/Validate/ValidateXmlRequest.java @@ -0,0 +1,93 @@ +package Utils.Requests.Validate; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.LinkedList; +import java.util.UUID; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Utils.Requests.IRequest; +import Utils.Requests.IRequestor; +import Utils.Responses.IResponse; +import Utils.Responses.ValidateXmlResponse; +import Utils.Responses.DetailData; +import Utils.Responses.DetailNode; + +public class ValidateXmlRequest implements IRequestor{ + + public IResponse sendRequest(IRequest request) throws GeneralException, AuthException { + try { + String xmlStr = ((ValidateXmlOptionsRequest) request).getXml(); + String boundary = UUID.randomUUID().toString(); + String raw = "--"+boundary+"\r\nContent-Disposition: form-data; name=xml; filename=xml\r\nContent-Type: application/xml\r\n\r\n"+xmlStr+"\r\n--"+boundary+"--"; + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(request.URI); + httppost.setHeader("Authorization", "bearer " + request.Token); + httppost.addHeader("Content-Type", "multipart/form-data; boundary="+boundary); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + Charset chars = Charset.forName("UTF-8"); + builder.setCharset(chars); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + builder.addTextBody("xml", raw, ContentType.DEFAULT_BINARY); + httppost.setEntity(builder.build()); + CloseableHttpResponse responseB = client.execute(httppost); + HttpEntity entity = responseB.getEntity(); + String responseString = EntityUtils.toString(entity, "UTF-8"); + int statusE = responseB.getStatusLine().getStatusCode(); + client.close(); + responseB.close(); + if(!responseString.isEmpty()) { + JSONObject body = new JSONObject(responseString); + if(statusE==200){ + LinkedList List = new LinkedList(); + JSONArray detailP= new JSONArray(body.get("detail").toString()); + for (int i = 0; i < detailP.length (); i++) { + JSONObject detailNode = new JSONObject(detailP.get(i).toString()); + LinkedList ListItem = new LinkedList(); + JSONArray detail = new JSONArray(detailNode.get("detail").toString()); + for (int j = 0; j < detail.length (); j++) { + JSONObject detaildata = new JSONObject(detail.get(j).toString()); + DetailData nuevo = new DetailData(detaildata.getString("message"),detaildata.getString("messageDetail"),String.valueOf(detaildata.getInt("type"))); + ListItem.add(nuevo); + } + DetailNode x = new DetailNode(detailNode.getString("section"),ListItem); + List.add(x); + } + + return new ValidateXmlResponse(statusE,body.getString("status"),body.get("cadenaOriginalSAT").toString(),body.get("cadenaOriginalComprobante").toString(),body.get("uuid").toString(),body.get("statusSat").toString(),body.get("statusCodeSat").toString(),List,"OK","OK"); + } + else { + String messageDetail = ""; + if (!body.isNull("messageDetail")) { + messageDetail = body.getString("messageDetail"); + } + return new ValidateXmlResponse(statusE, body.getString("status"), body.getString("message"), messageDetail); + } + } + else { + return new ValidateXmlResponse(statusE,"error",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase()); + } + } + catch (JSONException e){ + throw new GeneralException(500,e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + throw new GeneralException(500,e.getMessage()); + } + } + +} diff --git a/src/main/java/Utils/Responses/DetailData.java b/src/main/java/Utils/Responses/DetailData.java new file mode 100644 index 0000000..533fe89 --- /dev/null +++ b/src/main/java/Utils/Responses/DetailData.java @@ -0,0 +1,12 @@ +package Utils.Responses; + +public class DetailData{ + public String message; + public String messageDetail; + public String type; + public DetailData(String message, String messageDetail, String type) { + this.message = message; + this.messageDetail = messageDetail; + this.type = type; + } +} diff --git a/src/main/java/Utils/Responses/DetailNode.java b/src/main/java/Utils/Responses/DetailNode.java new file mode 100644 index 0000000..2d5d978 --- /dev/null +++ b/src/main/java/Utils/Responses/DetailNode.java @@ -0,0 +1,12 @@ +package Utils.Responses; + +import java.util.LinkedList; + +public class DetailNode{ + public String section; + public LinkedList detail; + public DetailNode(String section, LinkedList detail) { + this.section = section; + this.detail = detail; + } +} \ No newline at end of file diff --git a/src/main/java/Utils/Responses/PdfResponse.java b/src/main/java/Utils/Responses/PdfResponse.java new file mode 100644 index 0000000..37226ab --- /dev/null +++ b/src/main/java/Utils/Responses/PdfResponse.java @@ -0,0 +1,30 @@ +package Utils.Responses; + +public class PdfResponse extends IResponse{ + public String contentB64; + public int contentSizeBytes; + public String uuid; + public String serie; + public String folio; + public String stampDate; + public String issuedDate; + public String rfcIssuer; + public String rfcReceptor; + public String total; + public PdfResponse(int httpStatusCode, String status, String contentB64, int contentSizeBytes, String uuid, String serie, String folio, String stampDate, String issuedDate, String rfcIssuer,String rfcReceptor, String total, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + this.contentB64 = contentB64; + this.contentSizeBytes = contentSizeBytes; + this.uuid = uuid; + this.serie = serie; + this.folio = folio; + this.stampDate = stampDate; + this.issuedDate = issuedDate; + this.rfcIssuer = rfcIssuer; + this.rfcReceptor = rfcReceptor; + this.total = total; + } + public PdfResponse(int httpStatusCode, String status, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + } +} diff --git a/src/main/java/Utils/Responses/ValidateLcoResponse.java b/src/main/java/Utils/Responses/ValidateLcoResponse.java new file mode 100644 index 0000000..057e8a2 --- /dev/null +++ b/src/main/java/Utils/Responses/ValidateLcoResponse.java @@ -0,0 +1,24 @@ +package Utils.Responses; + +public class ValidateLcoResponse extends IResponse{ + public String noCertificado; + public String rfc; + public String validezObligaciones; + public String estatusCertificado; + public String fechaInicio; + public String fechaFinal; + + public ValidateLcoResponse(int httpStatusCode, String status, String noCertificado, String rfc, String validezObligaciones, String estatusCertificado, String fechaInicio, String fechaFinal, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + this.noCertificado = noCertificado; + this.rfc = rfc; + this.validezObligaciones = validezObligaciones; + this.estatusCertificado = estatusCertificado; + this.fechaInicio = fechaInicio; + this.fechaFinal = fechaFinal; + } + public ValidateLcoResponse(int httpStatusCode, String status, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + } + +} diff --git a/src/main/java/Utils/Responses/ValidateLrfcResponse.java b/src/main/java/Utils/Responses/ValidateLrfcResponse.java new file mode 100644 index 0000000..a4b827c --- /dev/null +++ b/src/main/java/Utils/Responses/ValidateLrfcResponse.java @@ -0,0 +1,19 @@ +package Utils.Responses; + +public class ValidateLrfcResponse extends IResponse{ + public String contribuyenteRFC; + public boolean sncf; + public boolean subcontratacion; + + + public ValidateLrfcResponse(int httpStatusCode, String status, String contribuyenteRFC, boolean sncf, boolean subcontratacion, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + this.contribuyenteRFC = contribuyenteRFC; + this.sncf = sncf; + this.subcontratacion = subcontratacion; + } + public ValidateLrfcResponse(int httpStatusCode, String status, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + } + +} diff --git a/src/main/java/Utils/Responses/ValidateXmlResponse.java b/src/main/java/Utils/Responses/ValidateXmlResponse.java new file mode 100644 index 0000000..dfe443a --- /dev/null +++ b/src/main/java/Utils/Responses/ValidateXmlResponse.java @@ -0,0 +1,27 @@ +package Utils.Responses; + +import java.util.LinkedList; + +public class ValidateXmlResponse extends IResponse{ + public String cadenaOriginalSAT; + public String cadenaOriginalComprobante; + public String uuid; + public String statusSat; + public String statusCodeSat; + public LinkedList detail; + + + public ValidateXmlResponse(int httpStatusCode, String status, String cadenaOriginalSAT, String cadenaOriginalComprobante, String uuid, String statusSat, String statusCodeSat, LinkedList detail, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + this.cadenaOriginalSAT = cadenaOriginalSAT; + this.cadenaOriginalComprobante= cadenaOriginalComprobante; + this.uuid=uuid; + this.statusSat=statusSat; + this.statusCodeSat= statusCodeSat; + this.detail= detail; + } + public ValidateXmlResponse(int httpStatusCode, String status, String msg, String msgDetail) { + super(httpStatusCode, status, msg, msgDetail); + } + +} diff --git a/src/test/java/Tests/Authentication/SWAuthenticationServiceTest.java b/src/test/java/Tests/Authentication/SWAuthenticationServiceTest.java index 2eaf057..75b2c34 100644 --- a/src/test/java/Tests/Authentication/SWAuthenticationServiceTest.java +++ b/src/test/java/Tests/Authentication/SWAuthenticationServiceTest.java @@ -5,7 +5,7 @@ import Services.Authentication.SWAuthenticationService; import Utils.Responses.IResponse; import Utils.Responses.SuccessAuthResponse; -import junit.framework.Assert; +import org.junit.Assert; import junit.framework.TestCase; /** diff --git a/src/test/java/Tests/BalanceAccount/SWBalanceAccountServiceTest.java b/src/test/java/Tests/BalanceAccount/SWBalanceAccountServiceTest.java index 9d4062a..90ec712 100644 --- a/src/test/java/Tests/BalanceAccount/SWBalanceAccountServiceTest.java +++ b/src/test/java/Tests/BalanceAccount/SWBalanceAccountServiceTest.java @@ -8,6 +8,9 @@ import Tests.Utils; import Utils.Responses.BalanceAcctResponse; import junit.framework.TestCase; + +import java.io.IOException; + import org.junit.Assert; @@ -17,7 +20,7 @@ public class SWBalanceAccountServiceTest extends TestCase { - public void testBalanceAccountService() throws AuthException, GeneralException { + public void testBalanceAccountService() throws AuthException, GeneralException, IOException { SWBalanceAccountService app = new SWBalanceAccountService("demo","123456789",Utils.url_pruebas); BalanceAcctResponse response = null; response = (BalanceAcctResponse) app.GetBalanceAccount(); diff --git a/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java b/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java index e6b7bf7..959ad52 100644 --- a/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java +++ b/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java @@ -16,14 +16,14 @@ public class SWCancelationServiceTest extends TestCase { public String b64Key = "MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIAgEAAoIBAQACAggAMBQGCCqGSIb3DQMHBAgwggS9AgEAMASCBMh4EHl7aNSCaMDA1VlRoXCZ5UUmqErAbucRBAKNQXH8t1GNfLDIQejtcocS39VvWnpNXjZJeCg65Y2wI36UGn78gvnU0NOmyUkXksPVrkz7hqNtAVojPUtN65l+MVAsIRVD6OLJeKZ2bLx5z78zrx6Tp1zCGT/NpxL+CJSy5iY6TKqbJcK/9198noOvT2p8rKVqUUF3wLRvD6R/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mR3o2M3NqNkh4MW9KVXMvUHhZYzVLQS9UK2E1SVhEZFJKYWx4ZmlEWDFuSXlqc2ZRYXlUQk1ldlZkU2tEdU10NFVMdHZKUURLblBxakw0SDl5bUxabDFLNmNPbEp6b3Jtd2Q1V2htRHlTdDZ6eTFRdUNnYnVvK2tuVUdhMmwrVWRCZi9rQkU9.7k2gVCGSZKLzJK5Ky3Nr5tKxvGSJhL13Q8W-YhT0uIo"; public String xml = "3eaeabc9-ea41-4627-9609-c6856b78e2b1rs2ZcFnS9hbfmyJLmR3Mtnklt7g=O/I7ILsU2y1fqeb2NBZSQKlQC3DpN/bgcDB5LWCMIYp4mFCLmLxEq/6ADz0xVQWUw49BqWDZ1GAI4ODIZLDQtafHSIE7BXKy8huvKD1dtpRLQ/39IfpxXsz1g6Q14mH3LxDOQugk/GhKMWILXZnIipyQosv3IbgLMZ/V/4btK7xrFX/KiOt0PcefChyaerj9A815dA3J4JgpBUNzbOz9VlhvdZMJskrHxzZ5riU1TAuSw/oi68dJfA7S+6XrTmeFDQzYxACHyOzj24RjLi/31+Fc/wiqQXNu9O6oWl8p5+GVoz2xtU4aRqLxVh73L6WAAef/WDeKDMfIge1BtMrxYw==OID.1.2.840.113549.1.9.2=Responsable: ACDMA, OID.2.5.4.45=SAT970701NN3, L=Coyoac?n, S=Distrito Federal, C=MX, PostalCode=06300, STREET=\"Av. Hidalgo 77, Col. Guerrero\", E=asisnet@pruebas.sat.gob.mx, OU=Administraci?n de Seguridad de la Informaci?n, O=Servicio de Administraci?n Tributaria, CN=A.C. 2 de pruebas(4096)3230303031303030303030333030303232383135MIIFxTCCA62gAwIBAgIUMjAwMDEwMDAwMDAzMDAwMjI4MTUwDQYJKoZIhvcNAQELBQAwggFmMSAwHgYDVQQDDBdBLkMuIDIgZGUgcHJ1ZWJhcyg0MDk2KTEvMC0GA1UECgwmU2VydmljaW8gZGUgQWRtaW5pc3RyYWNpw7NuIFRyaWJ1dGFyaWExODA2BgNVBAsML0FkbWluaXN0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cjxgp23520G/YpCGhseJv2PWcV0H1rs0coAi3qCr7G+A2MYwGJA4DCAfD92xZWtZgPUpPSELvEBgWqMsW87xd1MSkumJ8e7zGOMXoFRo3ID4wot1FIaWU/EJyzb3xowrbY64Ytquuu9s9ef0weTumPMvkWcnGeqgKaEMnl24Is6CoG+qS+HfvgS8qxiv1TfTTIRmT0nhYWRoEkE/0ue6X4Zs+qT28Z8P/LzcIJECJvd39K5BI0q3RMqEVumgVcKGPB9nkxReDPR1M/cxY9qru99NaOK0dZJAin5AXDVOrCZzOdLeEU5lIRXWZwr9i1/rVvLh6f3tnhVWgbghp+JsuhaX2ALRY74pAosbzVMZJlf31TElMCMGCSqGSIb3DQEJFTEWBBTV2Mqe5ylxDwy8SvKAi/DPPo81QzAxMCEwCQYFKw4DAhoFAAQUro+9ySRmBaYPd9oC4rXFvP20CPkECEuQk0rStkWzAgIIAA=="; //CSD public void testCancelationServiceCSD_authUser() throws Exception { SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); CancelationResponse response = null; - response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Cer, b64Key); - + response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Cer, b64Key); System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.acuse); @@ -38,7 +38,6 @@ public void testCancelationServiceCSD_authToken() throws Exception { SWCancelationService app = new SWCancelationService(token,Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Cer, b64Key); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.acuse); @@ -53,7 +52,6 @@ public void testCancelationServiceCSD_incorrectParams() throws Exception { SWCancelationService app = new SWCancelationService(token,Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse)app.Cancelation("123456", "123456", "123456", "123456", "123456"); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.message); @@ -63,12 +61,10 @@ public void testCancelationServiceCSD_incorrectParams() throws Exception { } - public void testCancelationServiceCSD_incorrectToken() throws Exception { - + public void testCancelationServiceCSD_incorrectToken() throws Exception { SWCancelationService app = new SWCancelationService("wrong token",Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Cer, b64Key); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.message); @@ -78,7 +74,6 @@ public void testCancelationServiceCSD_incorrectToken() throws Exception { } public void testCancelationServiceCSD_emptyUserParams() throws Exception { - try{ SWCancelationService app = new SWCancelationService("","",""); CancelationResponse response = null; @@ -97,20 +92,16 @@ public void testCancelationServiceCSD_emptyUserParams() throws Exception { public void testCancelationServiceCSD_emptyCancelationParams() throws Exception { - SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse) app.Cancelation("", "", "", "", ""); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.message); System.out.println(response.messageDetail); - int expected_HttpStatusCode = 400; Assert.assertTrue(response.message.contains("CACFDI33")); Assert.assertTrue(expected_HttpStatusCode == response.HttpStatusCode); - } @@ -121,7 +112,6 @@ public void testCancelationServiceXML_validXML() throws Exception { SWCancelationService app = new SWCancelationService("demo", "123456789", Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse) app.Cancelation(xml); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.message); @@ -138,13 +128,11 @@ public void testCancelationServiceXML_invalidXML() throws Exception { SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse)app.Cancelation("wrong xml"); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.message); System.out.println(response.messageDetail); String expect_status = "error"; - Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); Assert.assertTrue(response.message.contains("CA1000")); } @@ -153,7 +141,6 @@ public void testCancelationServiceXML_nullXML() throws Exception { SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); CancelationResponse response = null; response = (CancelationResponse)app.Cancelation(""); - System.out.println(response.Status); System.out.println(response.HttpStatusCode); System.out.println(response.message); @@ -163,4 +150,174 @@ public void testCancelationServiceXML_nullXML() throws Exception { Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); Assert.assertTrue(response.message.contains("CA1000")); } + + //Pfx + public void testCancelationServicePfx_authUser() throws Exception { + SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Pfx); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.acuse); + System.out.println(response.uuid); + System.out.println(response.uuidStatusCode); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + + public void testCancelationServicePfx_authToken() throws Exception { + SWCancelationService app = new SWCancelationService(token,Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Pfx); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.acuse); + System.out.println(response.uuid); + System.out.println(response.uuidStatusCode); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + + public void testCancelationServicePfx_incorrectParams() throws Exception { + SWCancelationService app = new SWCancelationService(token,Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation("123456", "123456", "123456", "123456"); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + + public void testCancelationServicePfx_incorrectToken() throws Exception { + SWCancelationService app = new SWCancelationService("wrong token",Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Pfx); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + String expect_message = "Unauthorized"; + Assert.assertTrue(expect_message.equalsIgnoreCase(response.message)); + } + + public void testCancelationServicePfx_emptyUserParams() throws Exception { + try{ + SWCancelationService app = new SWCancelationService("","",""); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, password_csd, rfc, b64Pfx); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + } + catch(Exception e){ + System.out.println("Correcto excepcion lanzada"); + System.out.println(e.getMessage()); + Assert.assertNotNull("some bad happend", e); + } + } + + + public void testCancelationServicePfx_emptyCancelationParams() throws Exception { + SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse) app.Cancelation("", "", "", ""); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + int expected_HttpStatusCode = 400; + Assert.assertTrue(response.message.contains("CACFDI33")); + Assert.assertTrue(expected_HttpStatusCode == response.HttpStatusCode); + } + + //Uuid + public void testCancelationServiceUuid_authUser() throws Exception { + SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, rfc); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.acuse); + System.out.println(response.uuid); + System.out.println(response.uuidStatusCode); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + + public void testCancelationServiceUuid_authToken() throws Exception { + SWCancelationService app = new SWCancelationService(token,Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, rfc); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.acuse); + System.out.println(response.uuid); + System.out.println(response.uuidStatusCode); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + + public void testCancelationServiceUuid_incorrectParams() throws Exception { + SWCancelationService app = new SWCancelationService(token,Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation("123456", "123456"); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + + public void testCancelationServiceUuid_incorrectToken() throws Exception { + SWCancelationService app = new SWCancelationService("wrong token",Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, rfc); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + String expect_message = "Unauthorized"; + Assert.assertTrue(expect_message.equalsIgnoreCase(response.message)); + } + + public void testCancelationServiceUuid_emptyUserParams() throws Exception { + try{ + SWCancelationService app = new SWCancelationService("","",""); + CancelationResponse response = null; + response = (CancelationResponse)app.Cancelation(uuid, rfc); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + } + catch(Exception e){ + System.out.println("Correcto excepcion lanzada"); + System.out.println(e.getMessage()); + Assert.assertNotNull("some bad happend", e); + } + } + + + public void testCancelationServiceUuid_emptyCancelationParams() throws Exception { + SWCancelationService app = new SWCancelationService("demo","123456789",Utils.url_pruebas); + CancelationResponse response = null; + response = (CancelationResponse) app.Cancelation("", ""); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + int expected_HttpStatusCode = 404; + Assert.assertTrue(response.message.equalsIgnoreCase("Not Found")); + Assert.assertTrue(expected_HttpStatusCode == response.HttpStatusCode); + } } diff --git a/src/test/java/Tests/Pdf/SWPdfServiceTest.java b/src/test/java/Tests/Pdf/SWPdfServiceTest.java new file mode 100644 index 0000000..0b8703f --- /dev/null +++ b/src/test/java/Tests/Pdf/SWPdfServiceTest.java @@ -0,0 +1,69 @@ +package Tests.Pdf; + + +import Exceptions.AuthException; +import Exceptions.GeneralException; +import Services.Pdf.SWPdfService; +import Tests.Utils; +import Utils.Responses.PdfResponse; +import junit.framework.TestCase; + +import java.io.IOException; + +import org.junit.Assert; + + +public class SWPdfServiceTest extends TestCase { + + public String token = "T2lYQ0t4L0RHVkR4dHZ5Nkk1VHNEakZ3Y0J4Nk9GODZuRyt4cE1wVm5tbXB3YVZxTHdOdHAwVXY2NTdJb1hkREtXTzE3dk9pMmdMdkFDR2xFWFVPUXpTUm9mTG1ySXdZbFNja3FRa0RlYURqbzdzdlI2UUx1WGJiKzViUWY2dnZGbFloUDJ6RjhFTGF4M1BySnJ4cHF0YjUvbmRyWWpjTkVLN3ppd3RxL0dJPQ.T2lYQ0t4L0RHVkR4dHZ5Nkk1VHNEakZ3Y0J4Nk9GODZuRyt4cE1wVm5tbFlVcU92YUJTZWlHU3pER1kySnlXRTF4alNUS0ZWcUlVS0NhelhqaXdnWTRncklVSWVvZlFZMWNyUjVxYUFxMWFxcStUL1IzdGpHRTJqdS9Zakw2UGRiMTFPRlV3a2kyOWI5WUZHWk85ODJtU0M2UlJEUkFTVXhYTDNKZVdhOXIySE1tUVlFdm1jN3kvRStBQlpLRi9NeWJrd0R3clhpYWJrVUMwV0Mwd3FhUXdpUFF5NW5PN3J5cklMb0FETHlxVFRtRW16UW5ZVjAwUjdCa2g0Yk1iTExCeXJkVDRhMGMxOUZ1YWlIUWRRVC8yalFTNUczZXdvWlF0cSt2UW0waFZKY2gyaW5jeElydXN3clNPUDNvU1J2dm9weHBTSlZYNU9aaGsvalpQMUxrSkhlVUY2aXpLNWZkaHZlcDFtMWFhWkJpdGFxSFpRMXZSWUp5QUZsalZWd2huVWx3NUM3dVF6aWxJaGJqUU9QbFdWZW0zMTQxTmd6dUJ3dHR0SDlvTjhLUzFoT3VsMnRXWFlTWGFOUDNaeEhmUklFOWVEZjB6OE9QVGhzWnZ1bjRzWkUyeWd3UXlFMUtENVRXQ1pxRjg9.6Us1aA5VkXQTHyEBeaq-98l_5NTADHRAayJXQPT9qIA"; + public String xml = " "; + + + public void testPdfService() throws AuthException, GeneralException, IOException { + SWPdfService app = new SWPdfService(token ,Utils.url_pruebas); + PdfResponse response = null; + response = (PdfResponse) app.GeneratePdf(xml); + + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.contentB64); + System.out.println(response.contentSizeBytes); + System.out.println(response.uuid); + System.out.println(response.serie); + System.out.println(response.folio); + System.out.println(response.stampDate); + System.out.println(response.issuedDate); + System.out.println(response.rfcIssuer); + System.out.println(response.rfcReceptor); + System.out.println(response.total); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + + public void testBalanceAccountService_incorrectToken() throws Exception { + + SWPdfService app = new SWPdfService("wrong this" ,Utils.url_pruebas); + PdfResponse response = null; + response = (PdfResponse) app.GeneratePdf(xml); + + //System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.messageDetail); + String expect_message = "Access Denied"; + Assert.assertTrue(expect_message.equalsIgnoreCase(response.message)); + } + + public void testBalanceAccountService_emptyUserParams() throws AuthException, GeneralException { + SWPdfService app = new SWPdfService("","" ,Utils.url_pruebas); + PdfResponse response = null; + try { + response = (PdfResponse) app.GeneratePdf(xml); + } + catch(Exception e){ + System.out.println("Correcto excepcion lanzada"); + System.out.println(e.getMessage()); + Assert.assertNotNull("some bad happend", e); + } + } +} diff --git a/src/test/java/Tests/Stamp/SWStampServiceTest.java b/src/test/java/Tests/Stamp/SWStampServiceTest.java index a9fe0e0..3d232ef 100644 --- a/src/test/java/Tests/Stamp/SWStampServiceTest.java +++ b/src/test/java/Tests/Stamp/SWStampServiceTest.java @@ -1,13 +1,9 @@ package Tests.Stamp; -import Exceptions.AuthException; -import Exceptions.GeneralException; -import Services.Authentication.SWAuthenticationService; import Services.Stamp.SWStampService; import Tests.Utils; import Utils.Responses.*; import junit.framework.TestCase; -import org.json.JSONObject; import org.junit.Assert; @@ -21,11 +17,8 @@ public void testStampREAL_XML_STRING_USER_PASSWORD_AUTH_V1() throws Exception { SWStampService api = new SWStampService("demo","123456789",Utils.url_pruebas); SuccessV1Response response = null; Utils ut = new Utils(); - - response = (SuccessV1Response) api.Stamp(ut.StringgenBasico(),"v1"); System.out.println(response.Status); - System.out.println(response.HttpStatusCode); System.out.println(response.tfd); System.out.println(response.message); diff --git a/src/test/java/Tests/Validate/SWValidateServiceTest.java b/src/test/java/Tests/Validate/SWValidateServiceTest.java new file mode 100644 index 0000000..e691fc3 --- /dev/null +++ b/src/test/java/Tests/Validate/SWValidateServiceTest.java @@ -0,0 +1,120 @@ +package Tests.Validate; + +import java.util.LinkedList; + +import org.junit.Assert; + +import Services.Validate.SWValidateService; +import Tests.Utils; +import Utils.Responses.DetailData; +import Utils.Responses.DetailNode; +import Utils.Responses.ValidateLcoResponse; +import Utils.Responses.ValidateLrfcResponse; +import Utils.Responses.ValidateXmlResponse; +import junit.framework.TestCase; + +public class SWValidateServiceTest extends TestCase { + public void testValidateREAL_XML_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateXmlResponse response = null; + Utils ut = new Utils(); + System.out.println(ut.StringgenBasico()); + response = (ValidateXmlResponse) api.ValidateXml(ut.StringgenBasico()); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + LinkedList List = response.detail; + for(int i = 0; i < List.size(); i++) { + DetailNode node = List.get(i); + LinkedList ListData = node.detail; + for(int j = 0; j < ListData.size(); j++) { + DetailData datos = ListData.get(j); + System.out.println("\t\t"+datos.message); + System.out.println("\t\t"+datos.messageDetail); + System.out.println("\t\t"+datos.type); + } + System.out.println("\t"+node.section); + } + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateNULL_XML_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateXmlResponse response = null; + response = (ValidateXmlResponse) api.ValidateXml(null); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateEMPTY_XML_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateXmlResponse response = null; + response = (ValidateXmlResponse) api.ValidateXml(""); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateREAL_LRFC_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateLrfcResponse response = null; + response = (ValidateLrfcResponse) api.ValidateLrfc("LAN7008173R5"); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.contribuyenteRFC); + System.out.println(response.sncf); + System.out.println(response.subcontratacion); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateNULL_LRFC_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateLrfcResponse response = null; + response = (ValidateLrfcResponse) api.ValidateLrfc(null); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateFAKE_LRFC_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateLrfcResponse response = null; + response = (ValidateLrfcResponse) api.ValidateLrfc("BKI7008173Q8"); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateFAKE_Lco_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateLcoResponse response = null; + response = (ValidateLcoResponse) api.ValidateLco("20001000000300094637"); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + String expect_status = "error"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } + public void testValidateREAL_LCO_STRING_USER_PASSWORD() throws Exception { + SWValidateService api = new SWValidateService("demo","123456789",Utils.url_pruebas); + ValidateLcoResponse response = null; + response = (ValidateLcoResponse) api.ValidateLco("20001000000300022815"); + System.out.println(response.Status); + System.out.println(response.HttpStatusCode); + System.out.println(response.message); + System.out.println(response.noCertificado); + System.out.println(response.rfc); + System.out.println(response.validezObligaciones); + System.out.println(response.estatusCertificado); + System.out.println(response.fechaInicio); + System.out.println(response.fechaFinal); + String expect_status = "success"; + Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); + } +} diff --git a/src/test/java/Tests/assets/Sign.java b/src/test/java/Tests/assets/Sign.java index 391e0c1..0457548 100644 --- a/src/test/java/Tests/assets/Sign.java +++ b/src/test/java/Tests/assets/Sign.java @@ -1,24 +1,12 @@ package Tests.assets; - - - - - - import org.apache.commons.ssl.PKCS8Key; import javax.xml.bind.DatatypeConverter; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; import javax.xml.transform.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import java.io.*; -import java.security.KeyFactory; -import java.security.PrivateKey; import java.security.Signature; -import java.security.cert.X509Certificate; -import java.security.spec.PKCS8EncodedKeySpec; @@ -27,17 +15,13 @@ */ public class Sign { private String getKey() { - - try { File file = new File("src/test/java/Tests/assets/key.key"); //path: es la ruta del archivo de llave privada FileInputStream fileInputStream = new FileInputStream(file); byte[] fileBytes = new byte[fileInputStream.available()]; fileInputStream.read(fileBytes); fileInputStream.close(); - String fileString = DatatypeConverter.printBase64Binary(fileBytes); - return fileString; } catch (IOException e) { e.printStackTrace(); @@ -48,7 +32,6 @@ private String getKey() { } public String getSign(String cadena, String keyWord){ - try { String archivoLlavePrivada = this.getKey(); InputStream myInputStream = new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(archivoLlavePrivada)); @@ -58,7 +41,6 @@ public String getSign(String cadena, String keyWord){ signature.initSign(pk); signature.update(cadena.getBytes("UTF-8")); return new String(DatatypeConverter.printBase64Binary(signature.sign())); - }catch (Exception e){ e.printStackTrace(); } @@ -68,15 +50,8 @@ public String getSign(String cadena, String keyWord){ public String getCadena(String xml) { - - try { - - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - - Source xslt = new StreamSource(new File("src/test/java/Tests/assets/cadenaoriginal_3_3.xslt")); Transformer transformer = transformerFactory.newTransformer(xslt); Source xmlSource = new StreamSource(new StringReader(xml));