From ce13b24eff7e964d80649cc647f2db697fd06e76 Mon Sep 17 00:00:00 2001
From: Carlos Esteban Feria Vila
<2582866+carlosthe19916@users.noreply.github.com>
Date: Fri, 6 Nov 2020 16:44:56 +0100
Subject: [PATCH] add xsender jee
---
pom.xml | 8 +-
xbuilder-jee-vanilla/README.md | 9 ++
xbuilder-jee-vanilla/pom.xml | 5 -
.../{ => xbuilder}/jee/UBLResource.java | 4 +-
.../{ => xbuilder}/jee/UBLService.java | 2 +-
.../jee/config/UBLConfigSingleton.java | 2 +-
.../jee/config/UBLDefaults.java | 2 +-
xbuilder-quickstart/README.md | 1 +
xsender-jee-vanilla/README.md | 9 ++
xsender-jee-vanilla/pom.xml | 105 ++++++++++++++++++
.../quickstart/xsender/UBLResource.java | 77 +++++++++++++
.../quickstart/xsender/UBLService.java | 44 ++++++++
.../src/main/webapp/WEB-INF/beans.xml | 26 +++++
.../src/main/webapp/WEB-INF/web.xml | 30 +++++
.../src/main/webapp/css/styles.css | 19 ++++
.../src/main/webapp/index.html | 39 +++++++
xsender-quickstart/README.md | 1 +
17 files changed, 372 insertions(+), 11 deletions(-)
create mode 100644 xbuilder-jee-vanilla/README.md
rename xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/{ => xbuilder}/jee/UBLResource.java (92%)
rename xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/{ => xbuilder}/jee/UBLService.java (97%)
rename xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/{ => xbuilder}/jee/config/UBLConfigSingleton.java (96%)
rename xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/{ => xbuilder}/jee/config/UBLDefaults.java (97%)
create mode 100644 xbuilder-quickstart/README.md
create mode 100644 xsender-jee-vanilla/README.md
create mode 100644 xsender-jee-vanilla/pom.xml
create mode 100644 xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLResource.java
create mode 100644 xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLService.java
create mode 100644 xsender-jee-vanilla/src/main/webapp/WEB-INF/beans.xml
create mode 100644 xsender-jee-vanilla/src/main/webapp/WEB-INF/web.xml
create mode 100644 xsender-jee-vanilla/src/main/webapp/css/styles.css
create mode 100644 xsender-jee-vanilla/src/main/webapp/index.html
create mode 100644 xsender-quickstart/README.md
diff --git a/pom.xml b/pom.xml
index 5058da1..d7ce68a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,9 +37,14 @@
2.22.2
+
1.1.0.Final
3.0.1.Final
+
+ 21.0.0.Final
+ 2.0.2.Final
+
${basedir}
@@ -76,8 +81,9 @@
- xbuilder-quickstart
xbuilder-jee-vanilla
+ xbuilder-quickstart
+ xsender-jee-vanilla
xsender-quickstart
diff --git a/xbuilder-jee-vanilla/README.md b/xbuilder-jee-vanilla/README.md
new file mode 100644
index 0000000..4f8872f
--- /dev/null
+++ b/xbuilder-jee-vanilla/README.md
@@ -0,0 +1,9 @@
+Steps:
+- Init Wildfly
+- Deploy your app
+
+```shell
+mvn wildfly:deploy -f xbuilder-jee-vanilla/
+```
+
+- Open [http://localhost:8080/xbuilder-jee-vanilla](http://localhost:8080/xbuilder-jee-vanilla)
diff --git a/xbuilder-jee-vanilla/pom.xml b/xbuilder-jee-vanilla/pom.xml
index d35fe1f..1391a5a 100644
--- a/xbuilder-jee-vanilla/pom.xml
+++ b/xbuilder-jee-vanilla/pom.xml
@@ -32,11 +32,6 @@
XBuilder JEE vanilla
war
-
- 21.0.0.Final
- 2.0.2.Final
-
-
diff --git a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/UBLResource.java b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/UBLResource.java
similarity index 92%
rename from xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/UBLResource.java
rename to xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/UBLResource.java
index 99be848..4220a2b 100644
--- a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/UBLResource.java
+++ b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/UBLResource.java
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.github.project.openubl.quickstart.jee;
+package io.github.project.openubl.quickstart.xbuilder.jee;
-import io.github.project.openubl.quickstart.jee.config.UBLConfigSingleton;
+import io.github.project.openubl.quickstart.xbuilder.jee.config.UBLConfigSingleton;
import io.github.project.openubl.xmlbuilderlib.clock.SystemClock;
import io.github.project.openubl.xmlbuilderlib.config.Config;
import io.github.project.openubl.xmlbuilderlib.facade.DocumentManager;
diff --git a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/UBLService.java b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/UBLService.java
similarity index 97%
rename from xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/UBLService.java
rename to xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/UBLService.java
index 90f36af..b40070a 100644
--- a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/UBLService.java
+++ b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/UBLService.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.github.project.openubl.quickstart.jee;
+package io.github.project.openubl.quickstart.xbuilder.jee;
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog6;
import io.github.project.openubl.xmlbuilderlib.models.input.common.ClienteInputModel;
diff --git a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/config/UBLConfigSingleton.java b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/config/UBLConfigSingleton.java
similarity index 96%
rename from xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/config/UBLConfigSingleton.java
rename to xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/config/UBLConfigSingleton.java
index 3987a62..a447394 100644
--- a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/config/UBLConfigSingleton.java
+++ b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/config/UBLConfigSingleton.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.github.project.openubl.quickstart.jee.config;
+package io.github.project.openubl.quickstart.xbuilder.jee.config;
import io.github.project.openubl.xmlbuilderlib.clock.SystemClock;
import io.github.project.openubl.xmlbuilderlib.config.Config;
diff --git a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/config/UBLDefaults.java b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/config/UBLDefaults.java
similarity index 97%
rename from xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/config/UBLDefaults.java
rename to xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/config/UBLDefaults.java
index 0b3a482..6fbe3f6 100644
--- a/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/jee/config/UBLDefaults.java
+++ b/xbuilder-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xbuilder/jee/config/UBLDefaults.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.github.project.openubl.quickstart.jee.config;
+package io.github.project.openubl.quickstart.xbuilder.jee.config;
import io.github.project.openubl.xmlbuilderlib.config.Config;
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog10;
diff --git a/xbuilder-quickstart/README.md b/xbuilder-quickstart/README.md
new file mode 100644
index 0000000..ba3e633
--- /dev/null
+++ b/xbuilder-quickstart/README.md
@@ -0,0 +1 @@
+Execute Main.java
diff --git a/xsender-jee-vanilla/README.md b/xsender-jee-vanilla/README.md
new file mode 100644
index 0000000..abde981
--- /dev/null
+++ b/xsender-jee-vanilla/README.md
@@ -0,0 +1,9 @@
+Steps:
+- Init Wildfly
+- Deploy your app
+
+```shell
+mvn wildfly:deploy -f xsender-jee-vanilla/
+```
+
+- Open [http://localhost:8080/xsender-jee-vanilla](http://localhost:8080/xsender-jee-vanilla)
diff --git a/xsender-jee-vanilla/pom.xml b/xsender-jee-vanilla/pom.xml
new file mode 100644
index 0000000..28b4106
--- /dev/null
+++ b/xsender-jee-vanilla/pom.xml
@@ -0,0 +1,105 @@
+
+
+
+ 4.0.0
+
+ io.github.project-openubl
+ openubl-quickstarts
+ 3.0.2-SNAPSHOT
+ ../pom.xml
+
+
+ xsender-jee-vanilla
+ XSender JEE vanilla
+ war
+
+
+
+
+
+ org.wildfly.bom
+ wildfly-jakartaee8-with-tools
+ ${version.server.bom}
+ pom
+ import
+
+
+
+
+
+
+ io.github.project-openubl
+ xsender
+ ${xsender.version}
+
+
+
+
+ jakarta.enterprise
+ jakarta.enterprise.cdi-api
+ provided
+
+
+
+
+ org.jboss.spec.javax.annotation
+ jboss-annotations-api_1.3_spec
+ provided
+
+
+
+
+ org.jboss.spec.javax.ws.rs
+ jboss-jaxrs-api_2.1_spec
+ provided
+
+
+
+ org.jboss.resteasy
+ resteasy-jaxrs
+ provided
+
+
+ org.jboss.resteasy
+ resteasy-multipart-provider
+ provided
+
+
+
+ commons-io
+ commons-io
+ 2.6
+
+
+
+
+ ${project.artifactId}
+
+
+ org.wildfly.plugins
+ wildfly-maven-plugin
+ ${version.wildfly.maven.plugin}
+
+
+
+
diff --git a/xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLResource.java b/xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLResource.java
new file mode 100644
index 0000000..8817759
--- /dev/null
+++ b/xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLResource.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * Licensed under the Eclipse Public License - v 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.project.openubl.quickstart.xsender;
+
+import io.github.project.openubl.xmlsenderws.webservices.exceptions.InvalidXMLFileException;
+import io.github.project.openubl.xmlsenderws.webservices.exceptions.UnsupportedDocumentTypeException;
+import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceModel;
+import org.apache.commons.io.IOUtils;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
+
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+@Path("/file")
+public class UBLResource {
+
+ @Inject
+ UBLService ublService;
+
+ @POST
+ @Path("/upload")
+ @Consumes("multipart/form-data")
+ @Produces("text/plain")
+ public Response uploadFile(MultipartFormDataInput input) {
+ Map> uploadForm = input.getFormDataMap();
+ List inputParts = uploadForm.get("file");
+
+ for (InputPart inputPart : inputParts) {
+ try {
+
+ MultivaluedMap header = inputPart.getHeaders();
+
+ //convert the uploaded file to inputstream
+ InputStream inputStream = inputPart.getBody(InputStream.class, null);
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+
+ SmartBillServiceModel result = ublService.sendToSUNAT(bytes);
+ String message = result.getXmlContentModel().getDocumentType() + " " + result.getBillServiceModel().getStatus();
+
+ return Response.status(200)
+ .entity(message).build();
+ } catch (IOException | InvalidXMLFileException | UnsupportedDocumentTypeException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ return Response.serverError().build();
+ }
+
+}
diff --git a/xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLService.java b/xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLService.java
new file mode 100644
index 0000000..9fbab77
--- /dev/null
+++ b/xsender-jee-vanilla/src/main/java/io/github/project/openubl/quickstart/xsender/UBLService.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * Licensed under the Eclipse Public License - v 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.project.openubl.quickstart.xsender;
+
+import io.github.project.openubl.xmlsenderws.webservices.exceptions.InvalidXMLFileException;
+import io.github.project.openubl.xmlsenderws.webservices.exceptions.UnsupportedDocumentTypeException;
+import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceConfig;
+import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceManager;
+import io.github.project.openubl.xmlsenderws.webservices.managers.smart.SmartBillServiceModel;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class UBLService {
+ private final String username = "12345678912MODDATOS";
+ private final String password = "MODDATOS";
+
+ @PostConstruct
+ private void init() {
+ SmartBillServiceConfig.getInstance()
+ .withInvoiceAndNoteDeliveryURL("https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService")
+ .withPerceptionAndRetentionDeliveryURL("https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService")
+ .withDespatchAdviceDeliveryURL("https://e-beta.sunat.gob.pe/ol-ti-itemision-guia-gem-beta/billService");
+ }
+
+ public SmartBillServiceModel sendToSUNAT(byte[] file) throws InvalidXMLFileException, UnsupportedDocumentTypeException {
+ return SmartBillServiceManager.send(file, username, password);
+ }
+}
diff --git a/xsender-jee-vanilla/src/main/webapp/WEB-INF/beans.xml b/xsender-jee-vanilla/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..1a721d8
--- /dev/null
+++ b/xsender-jee-vanilla/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
diff --git a/xsender-jee-vanilla/src/main/webapp/WEB-INF/web.xml b/xsender-jee-vanilla/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..8fae5ec
--- /dev/null
+++ b/xsender-jee-vanilla/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,30 @@
+
+
+
+
+ javax.ws.rs.core.Application
+ /api/*
+
+
diff --git a/xsender-jee-vanilla/src/main/webapp/css/styles.css b/xsender-jee-vanilla/src/main/webapp/css/styles.css
new file mode 100644
index 0000000..9974ea9
--- /dev/null
+++ b/xsender-jee-vanilla/src/main/webapp/css/styles.css
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * Licensed under the Eclipse Public License - v 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+.invalid {
+ color: red;
+}
diff --git a/xsender-jee-vanilla/src/main/webapp/index.html b/xsender-jee-vanilla/src/main/webapp/index.html
new file mode 100644
index 0000000..84ccc68
--- /dev/null
+++ b/xsender-jee-vanilla/src/main/webapp/index.html
@@ -0,0 +1,39 @@
+
+
+
+
+ HTML5 + REST Hello World
+
+
+
+XBuilder + REST create xml
+
+
+
+
+
diff --git a/xsender-quickstart/README.md b/xsender-quickstart/README.md
new file mode 100644
index 0000000..ba3e633
--- /dev/null
+++ b/xsender-quickstart/README.md
@@ -0,0 +1 @@
+Execute Main.java