Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/0.0.4.3 #41

Merged
merged 9 commits into from
Sep 6, 2019
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
<artifactId>SW-JAVA</artifactId>
<version>0.0.4.2</version>
<version>0.0.4.3</version>
<packaging>jar</packaging>
<scm>
<url>https://github.com/lunasoft/sw-sdk-java</url>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/Services/Csd/SWCsdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,47 @@ public IResponse UploadMyCsd(String b64Cer, String b64Key, String passwordCsd, S
CsdRequest req = new CsdRequest();
return req.sendRequest(settings);
}

public IResponse DisableMyCsd(String certificateNumber) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), certificateNumber, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.DisableCsdRequest(settings);
}

public IResponse GetListCsd() throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetListCsdRequest(settings);
}

public IResponse GetListCsdByType(String type) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), "type/" + type, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetListCsdRequest(settings);
}

public IResponse GetListCsdByRfc(String rfc) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), "rfc/" + rfc, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetListCsdRequest(settings);
}

public IResponse SearchMyCsd(String certificateNumber) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), certificateNumber, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetInfoCsdRequest(settings);
}

public IResponse SearchActiveCsd(String rfc, String type) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), "rfc/" + rfc, type, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetInfoCsdRequest(settings);
}
}

4 changes: 3 additions & 1 deletion src/main/java/Utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public class Constants {
public static String RELACIONADOS_XML_PATH = "/relations/xml";
public static String RELACIONADOS_UUID_PATH = "/relations/";
public static String PENDIENTES_CANCELAR_PATH = "/pendings/";
public static String SAVE_CSD = "/csd/save";
public static String SAVE_CSD = "/certificates/save";
public static String DISABLE_SEARCH_CSD = "/certificates/";
public static String LIST_CSD = "/certificates";
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV1 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -22,7 +22,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV1Response(status, "error", "","Error con c�digo "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV1Response(status, "error", "","Error con c�digo "+status+": "+reason.getReasonPhrase(), response);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV2 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -22,7 +22,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV2Response(status, "error", "", "","Error con c�digo "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV2Response(status, "error", "", "","Error con c�digo "+status+": "+reason.getReasonPhrase(), response);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV3 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -22,7 +22,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV3Response(status, "error", "","Error con c�digo "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV3Response(status, "error", "","Error con c�digo "+status+": "+reason.getReasonPhrase(), response);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV4 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -27,7 +27,7 @@ public IResponse getResponse() {
}
}
else {
return new SuccessV4Response(status, "error", "", "", "", "", "", "", "", "", "", "Error con c�digo "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV4Response(status, "error", "", "", "", "", "", "", "", "", "", "Error con c�digo "+status+": "+reason.getReasonPhrase(), response);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/Utils/Helpers/RequestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static JSONArray buildJSONFromMap(Map<String, String> map) throws General
}

public static void setProxy(Builder build, String host, int port) throws GeneralException {
if(host != null){
if(!stringEmptyOrNull(host)){
try {
HttpHost proxy = new HttpHost(host, port);
build.setProxy(proxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -88,7 +88,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
} else {
return new AceptarRechazarCancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Utils/Requests/Authentication/AuthRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if(!responseString.isEmpty()) {
if(!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if(!body.isNull("messageDetail")){
messageDetail = body.getString("messageDetail");
Expand All @@ -57,7 +57,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
}
else{
return new SuccessAuthResponse(status,"error","",0,responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
return new SuccessAuthResponse(status,"error","",0,responseB.getStatusLine().getReasonPhrase(), responseString);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if(!responseString.isEmpty()) {
if(!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -52,7 +52,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
return new BalanceAcctResponse(status, body.getString("status"), body.getString("message"), messageDetail);
}
} else {
return new BalanceAcctResponse(status, "error", responseB.getStatusLine().getReasonPhrase(), responseB.getStatusLine().getReasonPhrase());
return new BalanceAcctResponse(status, "error", responseB.getStatusLine().getReasonPhrase(), responseString);
}

} catch (JSONException e) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/Utils/Requests/Cancelation/CancelationRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -76,7 +76,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down Expand Up @@ -111,7 +111,7 @@ public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralExce
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -131,7 +131,7 @@ public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralExce
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down Expand Up @@ -165,7 +165,7 @@ public IResponse sendRequestPfx(IRequest request) throws ClientProtocolException
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -184,7 +184,7 @@ public IResponse sendRequestPfx(IRequest request) throws ClientProtocolException
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand All @@ -206,7 +206,7 @@ public IResponse sendRequestUuid(IRequest request) throws ClientProtocolExceptio
int status = responseB.getStatusLine().getStatusCode();
client.close();
responseB.close();
if (!responseString.isEmpty()) {
if (!responseString.isEmpty() && status < 500) {
JSONObject body = new JSONObject(responseString);
if (status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -225,7 +225,7 @@ public IResponse sendRequestUuid(IRequest request) throws ClientProtocolExceptio
}
} else {
return new CancelationResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
responseB.getStatusLine().getReasonPhrase());
responseString);
}
} catch (JSONException e) {
throw new GeneralException(500, e.getMessage());
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/Utils/Requests/Csd/CsdOptionsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public CsdOptionsRequest(String token, String URI, String b64Cer, String b64Key,
this.isActive = isActive;
}

public CsdOptionsRequest(String token, String URI, String CertificateNumber, String proxyHost, int proxyPort) {
super(token, URI + Constants.DISABLE_SEARCH_CSD + CertificateNumber, proxyHost, proxyPort);
}
public CsdOptionsRequest(String token, String URI, String CertificateNumber, String type, String proxyHost, int proxyPort) {
super(token, URI + Constants.DISABLE_SEARCH_CSD + CertificateNumber + "/" + type, proxyHost, proxyPort);
}

public CsdOptionsRequest(String token, String URI, String proxyHost, int proxyPort) {
super(token, URI + Constants.LIST_CSD, proxyHost, proxyPort);
}

public String getB64Cer() {
return b64Cer;
}
Expand Down
Loading