Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
add xsender jee
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Nov 6, 2020
1 parent 08c512d commit ce13b24
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 11 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@

<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>

<!--xbuilder and xsender-->
<xbuilder.version>1.1.0.Final</xbuilder.version>
<xsender.version>3.0.1.Final</xsender.version>

<!--wildfly-->
<version.server.bom>21.0.0.Final</version.server.bom>
<version.wildfly.maven.plugin>2.0.2.Final</version.wildfly.maven.plugin>

<license.dir>${basedir}</license.dir>
</properties>

Expand Down Expand Up @@ -76,8 +81,9 @@
</dependencies>

<modules>
<module>xbuilder-quickstart</module>
<module>xbuilder-jee-vanilla</module>
<module>xbuilder-quickstart</module>
<module>xsender-jee-vanilla</module>
<module>xsender-quickstart</module>
</modules>

Expand Down
9 changes: 9 additions & 0 deletions xbuilder-jee-vanilla/README.md
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions xbuilder-jee-vanilla/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
<name>XBuilder JEE vanilla</name>
<packaging>war</packaging>

<properties>
<version.server.bom>21.0.0.Final</version.server.bom>
<version.wildfly.maven.plugin>2.0.2.Final</version.wildfly.maven.plugin>
</properties>

<dependencyManagement>
<dependencies>
<!-- importing the jakartaee8-with-tools BOM adds specs and other useful artifacts as managed dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions xbuilder-quickstart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Execute Main.java
9 changes: 9 additions & 0 deletions xsender-jee-vanilla/README.md
Original file line number Diff line number Diff line change
@@ -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)
105 changes: 105 additions & 0 deletions xsender-jee-vanilla/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0"?>
<!--
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.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.project-openubl</groupId>
<artifactId>openubl-quickstarts</artifactId>
<version>3.0.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>xsender-jee-vanilla</artifactId>
<name>XSender JEE vanilla</name>
<packaging>war</packaging>

<dependencyManagement>
<dependencies>
<!-- importing the jakartaee8-with-tools BOM adds specs and other useful artifacts as managed dependencies -->
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-jakartaee8-with-tools</artifactId>
<version>${version.server.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.github.project-openubl</groupId>
<artifactId>xsender</artifactId>
<version>${xsender.version}</version>
</dependency>

<!-- Import the CDI API, we use provided scope as the API is included in JBoss EAP -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Import the Common Annotations API (JSR-250), we use provided
scope as the API is included in JBoss EAP -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.3_spec</artifactId>
<scope>provided</scope>
</dependency>

<!-- Import the JAX-RS API, we use provided scope as the API is included in JBoss EAP. -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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<String, List<InputPart>> uploadForm = input.getFormDataMap();
List<InputPart> inputParts = uploadForm.get("file");

for (InputPart inputPart : inputParts) {
try {

MultivaluedMap<String, String> 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();
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
26 changes: 26 additions & 0 deletions xsender-jee-vanilla/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<!-- Marker file indicating CDI should be enabled -->
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
30 changes: 30 additions & 0 deletions xsender-jee-vanilla/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
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.
-->
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<!-- One of the ways of activating REST Services is adding these lines.
The server is responsible for adding the corresponding servlet automatically.
The class org.jboss.as.quickstarts.html5rest.HelloWorld class has the
annotation @Path("/") to receive the REST invocation -->
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
Loading

0 comments on commit ce13b24

Please sign in to comment.