-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
315dcec
commit 2f57ec7
Showing
47 changed files
with
1,904 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "interactive" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>xhandler-parent</artifactId> | ||
<version>5.0.3-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>examples-parent</artifactId> | ||
<name>Examples - Parent</name> | ||
<description>Examples parent</description> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>xbuilder</module> | ||
<module>xsender</module> | ||
<module>wildfly</module> | ||
<module>tomcat</module> | ||
<module>springbot</module> | ||
</modules> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.4.0</version> | ||
<configuration> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Demo XBuilder and XSender using Spring Boot | ||
|
||
Download this repository and execute | ||
|
||
```shell | ||
mvn spring-boot:run | ||
``` | ||
|
||
### Use the demo | ||
|
||
Open [http://localhost:8080](http://localhost:8080) | ||
|
||
![Screenshot](./screenshot.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>examples-parent</artifactId> | ||
<version>5.0.3-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>examples-springbot</artifactId> | ||
<name>Examples - Springbot</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<surefire.plugin.version>3.0.0-M4</surefire.plugin.version> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<spring.boot-version>2.7.8</spring.boot-version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring.boot-version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.springboot</groupId> | ||
<artifactId>camel-spring-boot-bom</artifactId> | ||
<version>3.20.3</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<!-- Openubl dependencies --> | ||
<dependency> | ||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>xbuilder</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.project-openubl</groupId> | ||
<artifactId>spring-boot-xsender</artifactId> | ||
<version>4.1.4</version> | ||
</dependency> | ||
|
||
<!-- Spring minimum libraries --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- Optional: test dependencies --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-test-spring-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring.boot-version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.11.0</version> | ||
<configuration> | ||
<release>11</release> | ||
<source>11</source> | ||
<target>11</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
...t/src/main/java/io/github/project/openubl/quickstart/xbuilder/springboot/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.project.openubl.quickstart.xbuilder.springboot; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.ComponentScan; | ||
|
||
@ComponentScan | ||
@ComponentScan("io.github.project.openubl.spring.xsender.runtime") | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
...ain/java/io/github/project/openubl/quickstart/xbuilder/springboot/XBuilderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package io.github.project.openubl.quickstart.xbuilder.springboot; | ||
|
||
import io.github.project.openubl.xbuilder.content.catalogs.Catalog6; | ||
import io.github.project.openubl.xbuilder.content.models.common.Cliente; | ||
import io.github.project.openubl.xbuilder.content.models.common.Proveedor; | ||
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle; | ||
import io.github.project.openubl.xbuilder.content.models.standard.general.Invoice; | ||
import io.github.project.openubl.xbuilder.enricher.ContentEnricher; | ||
import io.github.project.openubl.xbuilder.enricher.config.DateProvider; | ||
import io.github.project.openubl.xbuilder.enricher.config.Defaults; | ||
import io.github.project.openubl.xbuilder.renderer.TemplateProducer; | ||
import io.github.project.openubl.xbuilder.signature.CertificateDetails; | ||
import io.github.project.openubl.xbuilder.signature.CertificateDetailsFactory; | ||
import io.github.project.openubl.xbuilder.signature.XMLSigner; | ||
import io.github.project.openubl.xbuilder.signature.XmlSignatureHelper; | ||
import io.quarkus.qute.Template; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.w3c.dom.Document; | ||
|
||
import java.io.InputStream; | ||
import java.math.BigDecimal; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.PrivateKey; | ||
import java.security.cert.X509Certificate; | ||
import java.time.LocalDate; | ||
|
||
@RestController | ||
public class XBuilderController { | ||
|
||
Defaults defaults = Defaults.builder() | ||
.icbTasa(new BigDecimal("0.2")) | ||
.igvTasa(new BigDecimal("0.18")) | ||
.build(); | ||
|
||
DateProvider dateProvider = LocalDate::now; | ||
|
||
@RequestMapping( | ||
method = RequestMethod.POST, | ||
value = "/api/create-xml", | ||
produces = "text/plain" | ||
) | ||
public String createXML(@RequestBody String clientName) throws Exception { | ||
Invoice invoice = createInvoice(clientName); | ||
|
||
ContentEnricher enricher = new ContentEnricher(defaults, dateProvider); | ||
enricher.enrich(invoice); | ||
|
||
Template template = TemplateProducer.getInstance().getInvoice(); | ||
String xml = template.data(invoice).render(); | ||
|
||
// Sign XML | ||
InputStream ksInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("LLAMA-PE-CERTIFICADO-DEMO-12345678912.pfx"); | ||
CertificateDetails certificate = CertificateDetailsFactory.create(ksInputStream, "password"); | ||
|
||
X509Certificate x509Certificate = certificate.getX509Certificate(); | ||
PrivateKey privateKey = certificate.getPrivateKey(); | ||
Document signedXML = XMLSigner.signXML(xml, "Project OpenUBL", x509Certificate, privateKey); | ||
|
||
// Return | ||
byte[] bytesFromDocument = XmlSignatureHelper.getBytesFromDocument(signedXML); | ||
return new String(bytesFromDocument, StandardCharsets.ISO_8859_1); | ||
} | ||
|
||
private Invoice createInvoice(String clientName) { | ||
return Invoice.builder() | ||
.serie("F001") | ||
.numero(1) | ||
.proveedor(Proveedor.builder() | ||
.ruc("12345678912") | ||
.razonSocial("Softgreen S.A.C.") | ||
.build() | ||
) | ||
.cliente(Cliente.builder() | ||
.nombre(clientName) | ||
.numeroDocumentoIdentidad("12121212121") | ||
.tipoDocumentoIdentidad(Catalog6.RUC.toString()) | ||
.build() | ||
) | ||
.detalle(DocumentoVentaDetalle.builder() | ||
.descripcion("Item1") | ||
.cantidad(new BigDecimal("10")) | ||
.precio(new BigDecimal("100")) | ||
.unidadMedida("KGM") | ||
.build() | ||
) | ||
.detalle(DocumentoVentaDetalle.builder() | ||
.descripcion("Item2") | ||
.cantidad(new BigDecimal("10")) | ||
.precio(new BigDecimal("100")) | ||
.unidadMedida("KGM") | ||
.build() | ||
) | ||
.build(); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...main/java/io/github/project/openubl/quickstart/xbuilder/springboot/XSenderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.github.project.openubl.quickstart.xbuilder.springboot; | ||
|
||
import io.github.project.openubl.xsender.Constants; | ||
import io.github.project.openubl.xsender.camel.utils.CamelData; | ||
import io.github.project.openubl.xsender.camel.utils.CamelUtils; | ||
import io.github.project.openubl.xsender.company.CompanyCredentials; | ||
import io.github.project.openubl.xsender.company.CompanyURLs; | ||
import io.github.project.openubl.xsender.files.BillServiceFileAnalyzer; | ||
import io.github.project.openubl.xsender.files.BillServiceXMLFileAnalyzer; | ||
import io.github.project.openubl.xsender.files.ZipFile; | ||
import io.github.project.openubl.xsender.models.SunatResponse; | ||
import io.github.project.openubl.xsender.sunat.BillServiceDestination; | ||
import org.apache.camel.CamelContext; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
public class XSenderController { | ||
|
||
@Autowired | ||
private CamelContext camelContext; | ||
|
||
CompanyURLs companyURLs = CompanyURLs.builder() | ||
.invoice("https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService") | ||
.perceptionRetention("https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService") | ||
.despatch("https://api-cpe.sunat.gob.pe/v1/contribuyente/gem") | ||
.build(); | ||
|
||
CompanyCredentials credentials = CompanyCredentials.builder() | ||
.username("12345678959MODDATOS") | ||
.password("MODDATOS") | ||
.token("accessTokenParaGuiasDeRemision") | ||
.build(); | ||
|
||
@PostMapping("/api/file/upload") | ||
public String uploadFile(@RequestParam("file") MultipartFile file) throws Exception { | ||
byte[] bytes = file.getBytes(); | ||
|
||
BillServiceFileAnalyzer fileAnalyzer = new BillServiceXMLFileAnalyzer(bytes, companyURLs); | ||
|
||
// Archivo ZIP | ||
ZipFile zipFile = fileAnalyzer.getZipFile(); | ||
|
||
// Configuración para enviar xml y Configuración para consultar ticket | ||
BillServiceDestination fileDestination = fileAnalyzer.getSendFileDestination(); | ||
BillServiceDestination ticketDestination = fileAnalyzer.getVerifyTicketDestination(); | ||
|
||
// Send file | ||
CamelData camelData = CamelUtils.getBillServiceCamelData(zipFile, fileDestination, credentials); | ||
|
||
SunatResponse sendFileSunatResponse = camelContext.createProducerTemplate() | ||
.requestBodyAndHeaders( | ||
Constants.XSENDER_BILL_SERVICE_URI, | ||
camelData.getBody(), | ||
camelData.getHeaders(), | ||
SunatResponse.class | ||
); | ||
|
||
return fileAnalyzer.getXmlContent().getDocumentType() + " " + sendFileSunatResponse.getStatus(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
examples/springbot/src/main/resources/CERTIFICADO CLAVE PRIVADA.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEogIBAAKCAQEAt1IT3CtWuVOP03CFd3jSl4wTOXm8TRPhOyDNsPQU5A+eJWJ5 | ||
7v5HY/AE9aLaBQxl/UV0Qr/yMyHUgj1ZOyRsYuC4e8XzPiVpHqPjZonARi3bT+ry | ||
/1f4lBmDrLZdsJLGG9xnFoCv2XEC3FtCln1AUXMGmChJziNnmhpvtQwB6SPIKZSt | ||
eVU1sEUDdC91MdYwZxEojYzfW5m1sd/owL/slRb3qegH2YPjLWx2dOZRWU3L5TOv | ||
50dSzZOsP6B1kDesJpB7iKkUJRoq3icmxQE1AjComIPKuoPKwwZUuzeUkkgoTbBN | ||
Lpc2kMDu1M2X3m3lF8Ca7qwhvK5qzKfU+YWAnwIDAQABAoIBAFCX2PtWYk4fmn+O | ||
XF7l00+k2V7PUiVgtAhWp5c/9188Ln6pCIo1aBVblBKZgdfuV3g9bJtb35LzMIYB | ||
ipUhsjTWLsTbhdCwicJassKFlO5FgsFjvWjcuAAEJ4tqsU3LeSUOhJO0B5tEv8k4 | ||
pdGbRweH1kJWk/v4PLfXH30sxjpELcEwyGjFUuKGKVFliwuLXVKlBijgrq2M+GCG | ||
1A7vO9O0JR3yGq4r8ERzJI0zNy62RzjLPF2bes0168ovcJ3Kidt2gYVVf+2kGTvc | ||
skBWdIVWFgVYtNKNoy+5Y8qPMH+7QmuDA0gMt6mXdRJHL6p0Yy+yZLCZqeDoGjgU | ||
WvsrjeECgYEA6xxwS4w3qp2H8Fn1WmLOJo1EOieqRCvJLc/srHbmYxKOqEdzp/Lt | ||
uheZ1XpzsgLSPIaD3JnEj+8a7n7J0B6ZKkyoPBUTLLilm/qPe/+C7WKWaidhXVXJ | ||
q9Dmoyo9zLBSKqm0QJBCNEvZ7DT4RtyFL0Y0HWntIeBcrXAdfBss4NUCgYEAx5us | ||
axT6CoYPGqQZgorg3WgxAcA0WpbiyBdpFVsOycbpwWqQlqGLDNOvyjzyUSGMrGo3 | ||
ObAsW6cOpKkapXfq2hTCbHupecm/4QYoDOPo7hAHwCuy/ODHJhzo5OM53n8EggFW | ||
XnomzvadKyAY9/+0fH2WZxns3EwKs5YO2fTtdaMCgYAWhaTkN8xlVa3eAmAUhn6F | ||
BudQQth2q1McRly/sKwlNXPg/uc/YXAQcY5U+uP2W3rUPXaIPVqtBxSnYBHpE+VM | ||
PgenqcUqdY23wWrZUAK0xsrt5FPZYwxsnxhY7QT6hLF6UMNpo+gTpmh7zh8yepFv | ||
k+QOJUWIBzwZiTHp35iO+QKBgHnzelvR7RIQ5Zl5OLyw7MFYrthK/bF7DgMBioop | ||
n9dXV+l7mertt26WxofgxIsc3D1ah3MPV4qHfkLLriP6J9olZMOyqdBmmnx4rm9x | ||
rxYDZTjbefdVvVZjw0ZULT7qi26CMqp2Js+7jDqU2axq5XJJqGJFTJkrPD6MJ3ay | ||
VYHRAoGAGG+rgP44tjwu0qmmUDfdp1tlMzUwVmM3pvjw1+RKYQprt+K3cUlBliPf | ||
VKMs9aQ0J6VrjrkNHTL85VzeOK6QYnsKZuski3GD0hA3XVE3u4SuMCb3Rmt6eLVr | ||
f9UGabwN9n5il3ZV7+qCmvpYGZzQ1A8+jZgbFWW3bp4BuIiwbbg= | ||
-----END RSA PRIVATE KEY----- |
Oops, something went wrong.