Skip to content

Commit

Permalink
Merge pull request #25 from lunasoft/MDA-11050
Browse files Browse the repository at this point in the history
Mda 11050
  • Loading branch information
rbarusta authored Dec 14, 2017
2 parents 3c1b16f + f62ddf9 commit 4b50fcb
Show file tree
Hide file tree
Showing 38 changed files with 3,772 additions and 121 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ Descargas el modulo mediante Maven:
<dependency>
<groupId>mx.com.sw.services</groupId>
<artifactId>SW-JAVA</artifactId>
<version>0.0.3.3</version>

<version>0.0.3.4</version>

</dependency>
</dependencies>
```
##Instalación manual (sin Maven)
Descargar el modulo directamente de los siguientes links:

* [Relase Github](https://github.com/lunasoft/sw-sdk-java/releases)
* [Maven](https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=mx.com.sw.services&a=SW-JAVA&v=0.0.3.3&e=jar)

* [Maven](https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=mx.com.sw.services&a=SW-JAVA&v=0.0.3.4&e=jar)

Asi como instalar manualmente cada una de las dependencias:
* [Unirest](http://unirest.io/java.html)
* [org.json](http://www.json.org/java)
Expand Down
40 changes: 16 additions & 24 deletions SW-JAVA.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="com.github.bingoohuang:unirest-java:0.0.1" level="project" />
<orderEntry type="module-library" scope="TEST">
<orderEntry type="module-library" exported="" scope="TEST">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit.jar!/" />
Expand All @@ -22,7 +22,7 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit.jar!/" />
Expand All @@ -31,7 +31,7 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<orderEntry type="module-library" exported="">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
Expand All @@ -41,26 +41,18 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$USER_HOME$/Desktop/CDI/juniversalchardet-1.0.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: com.github.bingoohuang:unirest-java:0.0.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.3" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.0.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.3.6" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.juniversalchardet:juniversalchardet:1.0.3" level="project" />
<orderEntry type="library" exported="" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" exported="" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" exported="" name="Maven: com.github.bingoohuang:unirest-java:0.0.1" level="project" />
<orderEntry type="library" exported="" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
<orderEntry type="library" exported="" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
<orderEntry type="library" exported="" name="Maven: commons-logging:commons-logging:1.1.3" level="project" />
<orderEntry type="library" exported="" name="Maven: commons-codec:commons-codec:1.6" level="project" />
<orderEntry type="library" exported="" name="Maven: org.apache.httpcomponents:httpasyncclient:4.0.2" level="project" />
<orderEntry type="library" exported="" name="Maven: org.apache.httpcomponents:httpcore-nio:4.3.2" level="project" />
<orderEntry type="library" exported="" name="Maven: org.apache.httpcomponents:httpmime:4.3.6" level="project" />
<orderEntry type="library" exported="" name="Maven: org.json:json:20140107" level="project" />
<orderEntry type="library" exported="" name="Maven: com.googlecode.juniversalchardet:juniversalchardet:1.0.3" level="project" />
<orderEntry type="library" exported="" name="org.apache.servicemix.bundles:org.apache.servicemix.bundles.not-yet-commons-ssl:0.3.11_1" level="project" />
</component>
</module>
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>mx.com.sw.services</groupId>
<artifactId>SW-JAVA</artifactId>
<version>0.0.3.3</version>
<version>0.0.3.4</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -167,6 +167,12 @@
<artifactId>juniversalchardet</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.not-yet-commons-ssl</artifactId>
<version>0.3.11_1</version>
</dependency>

</dependencies>


Expand Down
81 changes: 52 additions & 29 deletions src/main/java/Utils/Requests/Stamp/StampRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@
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.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.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 {
Expand All @@ -28,32 +41,43 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
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<JsonNode> 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("{}")) {
JSONObject body = new JSONObject(response.getBody().toString());
if(response.getStatus()==200){
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-Disposition", "form-data; name=xml; filename=xml");
CloseableHttpResponse responseB = client.execute(httppost);

InputStream inputStream = responseB.getEntity().getContent();

Scanner s = new Scanner(inputStream).useDelimiter("\\A");
String responseString = s.hasNext() ? s.next() : "";

int statusE = responseB.getStatusLine().getStatusCode();
client.close();
if(!responseString.isEmpty()) {
JSONObject body = new JSONObject(responseString);
if(statusE==200){
JSONObject data = body.getJSONObject("data");

if (request.version.equalsIgnoreCase("v1")) {
return new SuccessV1Response(response.getStatus(),body.getString("status"),data.getString("tfd"),"OK","OK");
return new SuccessV1Response(statusE,body.getString("status"),data.getString("tfd"),"OK","OK");
}
else if(request.version.equalsIgnoreCase("v2")){
return new SuccessV2Response(response.getStatus(),body.getString("status"),data.getString("tfd"),data.getString("cfdi"),"OK","OK");
return new SuccessV2Response(statusE,body.getString("status"),data.getString("tfd"),data.getString("cfdi"),"OK","OK");
}
else if(request.version.equalsIgnoreCase("v3")){
return new SuccessV3Response(response.getStatus(),body.getString("status"),data.getString("cfdi"),"OK","OK");
return new SuccessV3Response(statusE,body.getString("status"),data.getString("cfdi"),"OK","OK");

}else if(request.version.equalsIgnoreCase("v4")){
return new SuccessV4Response(response.getStatus(),body.getString("status"),data.getString("cfdi"),data.getString("cadenaOriginalSAT"),data.getString("noCertificadoSAT"),data.getString("noCertificadoCFDI"),data.getString("uuid"),data.getString("selloSAT"),data.getString("selloCFDI"),data.getString("fechaTimbrado"),data.getString("qrCode"),"OK","OK");
return new SuccessV4Response(statusE,body.getString("status"),data.getString("cfdi"),data.getString("cadenaOriginalSAT"),data.getString("noCertificadoSAT"),data.getString("noCertificadoCFDI"),data.getString("uuid"),data.getString("selloSAT"),data.getString("selloCFDI"),data.getString("fechaTimbrado"),data.getString("qrCode"),"OK","OK");
}
else{
return new SuccessV1Response(response.getStatus(),body.getString("status"),data.toString(),"OK","OK");
return new SuccessV1Response(statusE,body.getString("status"),data.toString(),"OK","OK");
}


Expand All @@ -66,38 +90,38 @@ else if(request.version.equalsIgnoreCase("v3")){
messageDetail = body.getString("messageDetail");
}
if (request.version.equalsIgnoreCase("v1")) {
return new SuccessV1Response(response.getStatus(),body.getString("status"),"",body.getString("message"),messageDetail);
return new SuccessV1Response(statusE,body.getString("status"),"",body.getString("message"),messageDetail);
}
else if(request.version.equalsIgnoreCase("v2")){
return new SuccessV2Response(response.getStatus(),body.getString("status"),"","",body.getString("message"),messageDetail);
return new SuccessV2Response(statusE,body.getString("status"),"","",body.getString("message"),messageDetail);
}
else if(request.version.equalsIgnoreCase("v3")){
return new SuccessV3Response(response.getStatus(),body.getString("status"),"",body.getString("message"),messageDetail);
return new SuccessV3Response(statusE,body.getString("status"),"",body.getString("message"),messageDetail);

}else if(request.version.equalsIgnoreCase("v4")){
return new SuccessV4Response(response.getStatus(),body.getString("status"),"","","","","","","","","",body.getString("message"),messageDetail);
return new SuccessV4Response(statusE,body.getString("status"),"","","","","","","","","",body.getString("message"),messageDetail);
}
else{
return new SuccessV1Response(response.getStatus(),body.getString("status"),"",body.getString("message"),messageDetail);
return new SuccessV1Response(statusE,body.getString("status"),"",body.getString("message"),messageDetail);
}

}
}
else{
if (request.version.equalsIgnoreCase("v1")) {
return new SuccessV1Response(response.getStatus(),"error","",response.getStatusText(),response.getStatusText());
return new SuccessV1Response(statusE,"error","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
}
else if(request.version.equalsIgnoreCase("v2")){
return new SuccessV2Response(response.getStatus(),"error","","",response.getStatusText(),response.getStatusText());
return new SuccessV2Response(statusE,"error","","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
}
else if(request.version.equalsIgnoreCase("v3")){
return new SuccessV3Response(response.getStatus(),"error","",response.getStatusText(),response.getStatusText());
return new SuccessV3Response(statusE,"error","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());

}else if(request.version.equalsIgnoreCase("v4")){
return new SuccessV4Response(response.getStatus(),"error","","","","","","","","","",response.getStatusText(),response.getStatusText());
return new SuccessV4Response(statusE,"error","","","","","","","","","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
}
else{
return new SuccessV1Response(response.getStatus(),"error","",response.getStatusText(),response.getStatusText());
return new SuccessV1Response(statusE,"error","",responseB.getStatusLine().getReasonPhrase(),responseB.getStatusLine().getReasonPhrase());
}


Expand All @@ -114,15 +138,14 @@ else if(request.version.equalsIgnoreCase("v3")){



} catch (UnirestException e) {

throw new GeneralException(404,"HOST DESCONOCIDO");
}
catch (JSONException e){
throw new GeneralException(500,e.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new GeneralException(500,e.getMessage());
}



}
}
Loading

0 comments on commit 4b50fcb

Please sign in to comment.