Skip to content

Commit 0fda533

Browse files
Enhance Fault error code detection (#49)
1 parent d30d1cc commit 0fda533

File tree

4 files changed

+198
-4
lines changed

4 files changed

+198
-4
lines changed

core/src/main/java/io/github/project/openubl/xsender/camel/routes/SunatErrorResponseProcessor.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@
2626

2727
import javax.xml.namespace.QName;
2828
import java.util.Collections;
29+
import java.util.regex.Pattern;
2930

3031
public class SunatErrorResponseProcessor implements Processor {
32+
private static Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");
33+
34+
public boolean isNumeric(String strNum) {
35+
if (strNum == null) {
36+
return false;
37+
}
38+
return pattern.matcher(strNum).matches();
39+
}
3140

3241
@Override
3342
public void process(Exchange exchange) throws Exception {
@@ -36,10 +45,18 @@ public void process(Exchange exchange) throws Exception {
3645

3746
QName qName = fault.getFaultCode();
3847
String localPart = qName.getLocalPart();
39-
String errorCode = localPart
48+
49+
int errorCodeInt;
50+
String errorCodeString = localPart
4051
.replaceAll("Client.", "")
4152
.replaceAll("Server.", "");
42-
int errorCodeInt = Integer.parseInt(errorCode);
53+
if (isNumeric(errorCodeString)) {
54+
errorCodeInt = Integer.parseInt(errorCodeString);
55+
} else if (isNumeric(message)) {
56+
errorCodeInt = Integer.parseInt(message);
57+
} else {
58+
throw new IllegalStateException("Could not extract sunat error code", fault);
59+
}
4360

4461
Metadata metadata = Metadata.builder()
4562
.notes(Collections.emptyList())

core/src/test/java/io/github/project/openubl/xsender/camel/CxfTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.hamcrest.CoreMatchers;
3636
import org.junit.jupiter.api.AfterAll;
3737
import org.junit.jupiter.api.BeforeAll;
38+
import org.junit.jupiter.api.Disabled;
3839
import org.junit.jupiter.api.Test;
3940

4041
import java.io.IOException;
@@ -55,7 +56,7 @@ public class CxfTest {
5556
CompanyURLs companyURLs = CompanyURLs
5657
.builder()
5758
.invoice("https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService")
58-
.despatch("https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService")
59+
.despatch("https://e-beta.sunat.gob.pe/ol-ti-itemision-guia-gem-beta/billService")
5960
.perceptionRetention("https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService")
6061
.build();
6162

@@ -173,6 +174,29 @@ public void billService_sendBill_retention() throws Exception {
173174
assertEquals("El Comprobante numero R001-00000001 ha sido aceptado", sunatResponse.getMetadata().getDescription());
174175
}
175176

177+
@Test
178+
public void billService_sendBill_guiaRemision() throws Exception {
179+
InputStream xmlFileIS = Thread
180+
.currentThread()
181+
.getContextClassLoader()
182+
.getResourceAsStream("ubl/20494637074-T001-00007394.xml");
183+
BillServiceFileAnalyzer fileAnalyzer = new BillServiceXMLFileAnalyzer(xmlFileIS, companyURLs);
184+
185+
ZipFile zipFile = fileAnalyzer.getZipFile();
186+
BillServiceDestination destination = fileAnalyzer.getSendFileDestination();
187+
CamelData camelData = getBillServiceCamelData(zipFile, destination, credentials);
188+
189+
SunatResponse sunatResponse = camelContext
190+
.createProducerTemplate()
191+
.requestBodyAndHeaders(Constants.XSENDER_BILL_SERVICE_URI, camelData.getBody(), camelData.getHeaders(), SunatResponse.class);
192+
193+
assertNotNull(sunatResponse);
194+
assertEquals(Status.EXCEPCION, sunatResponse.getStatus());
195+
assertEquals(1085, sunatResponse.getMetadata().getResponseCode()); // Debe enviar las guias de remisión por el nuevo sistema de recepción de guias electronicas
196+
}
197+
198+
// TODO verify when GET STATUS get back to work
199+
@Disabled
176200
@Test
177201
public void billService_getStatus() throws Exception {
178202
InputStream xmlFileIS = Thread
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?><DespatchAdvice xmlns="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
2+
<ext:UBLExtensions>
3+
<ext:UBLExtension>
4+
<ext:ExtensionContent><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="PROJECT-OPENUBL"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>0foeDunivtTPD7730tmzX+HK7Vo=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>DAXH8YvHOEMz9rPrQsa3ds3/8WWaEOOab49TwabJmLKl0hlXpenSZwiDZoVCJkQnfCu/W/OWu6s6&#13;
5+
1nwpn3OBXccVPhY2R14sl2LANsPJF97j83ECK/YUH3kq9aGulpbhcCunOVdeZqQYfWD8e7uNUaj3&#13;
6+
Rz3bFj3Pn5S0js8EgIy21P7GLy76gjNYRsAZo2UVDKQw8o8TaUCcKmlIHa8K3pGXiGuEEI8qjV3w&#13;
7+
lEhc77Ggq+gpcXQ5HiUE/QoAW/Qvs5jm3PkogMM/NdOulDBgcLB1sTvPrOIsFjx9cEcyzMsQNKUV&#13;
8+
xqbJWUONEkvIHrdEBVJMFdjBE9KmEehNBQ8p+Q==</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIE+DCCA+CgAwIBAgIJALURz7AYmJ5+MA0GCSqGSIb3DQEBBQUAMIIBDTEbMBkGCgmSJomT8ixk&#13;
9+
ARkWC0xMQU1BLlBFIFNBMQswC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&#13;
22+
RmXWyv6jK06dcAjVhGUpmGBxLm/ld5f+p9GlshB2rFyWhUBBf++g3xCwtPpyFmv+ARltScOzYcPb&#13;
23+
zr9fODbtHDwHDLschuGEpg8rZOwVqekyGxNW0LeDGnq6YtvcW5qVrtEELvqcNkL0D73lAgMBAAGj&#13;
24+
VzBVMB0GA1UdDgQWBBTe18LHVKkeRrWs3Bxp1ikK50l96jAfBgNVHSMEGDAWgBTe18LHVKkeRrWs&#13;
25+
3Bxp1ikK50l96jATBgNVHSUEDDAKBggrBgEFBQcDATANBgkqhkiG9w0BAQUFAAOCAQEASBWcP4Ai&#13;
26+
qUUZSG2/Z3RU3BgvOVV3if8xYAaZT99n5PsvyBiZ3Gh6VpAW9ezoe25ZNSqGMmGfq+R4mEuiqK4h&#13;
27+
6jDJp0fN47IwRhWjttB9dwpxIDEkWW7zPdueGx+BY8EuyfNDWR/C7GPfu6azSHiapzeKC57AAZ8x&#13;
28+
o8kDdhXxDy8hTqNGolkqnc6QutW8cYPeonqyhi2THN163lZ3Cx5OV8vGFQ3ou2msF0klY9qXopI9&#13;
29+
i8wQjEeOG6bCvVxdID9ZjTbuGbO9pAN9hH7hZ41XEG/CspSWbFf1/Wbnlfusne9v9NgRj0MM+LAH&#13;
30+
M7AO5/7j1XwRq4x+U9TSVPgpoU9l5Q==</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></ext:ExtensionContent>
31+
</ext:UBLExtension>
32+
</ext:UBLExtensions>
33+
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
34+
<cbc:CustomizationID>1.0</cbc:CustomizationID>
35+
<cbc:ID>T001-00007394</cbc:ID>
36+
<cbc:IssueDate>2022-12-15</cbc:IssueDate>
37+
<cbc:DespatchAdviceTypeCode>09</cbc:DespatchAdviceTypeCode>
38+
<cbc:Note>observacion</cbc:Note>
39+
<cac:Signature>
40+
<cbc:ID>12345678912</cbc:ID>
41+
<cac:SignatoryParty>
42+
<cac:PartyIdentification>
43+
<cbc:ID>12345678912</cbc:ID>
44+
</cac:PartyIdentification>
45+
<cac:PartyName>
46+
<cbc:Name>Softgreen S.A.C</cbc:Name>
47+
</cac:PartyName>
48+
</cac:SignatoryParty>
49+
<cac:DigitalSignatureAttachment>
50+
<cac:ExternalReference>
51+
<cbc:URI>#PROJECT-OPENUBL-SIGN</cbc:URI>
52+
</cac:ExternalReference>
53+
</cac:DigitalSignatureAttachment>
54+
</cac:Signature>
55+
<cac:DespatchSupplierParty>
56+
<cbc:CustomerAssignedAccountID schemeID="6">12345678912</cbc:CustomerAssignedAccountID>
57+
<cac:Party>
58+
<cac:PostalAddress>
59+
<cbc:ID>0000</cbc:ID>
60+
<cbc:StreetName>AV.BUENA VISTA 123</cbc:StreetName>
61+
<cbc:CitySubdivisionName>-</cbc:CitySubdivisionName>
62+
<cbc:CityName>HUAMANGA</cbc:CityName>
63+
<cbc:CountrySubentity>AYACUCHO</cbc:CountrySubentity>
64+
<cbc:District>AYACUCHO</cbc:District>
65+
<cac:Country>
66+
<cbc:IdentificationCode>PE</cbc:IdentificationCode>
67+
</cac:Country>
68+
</cac:PostalAddress>
69+
<cac:PartyLegalEntity>
70+
<cbc:RegistrationName>Softgreen S.A.C</cbc:RegistrationName>
71+
</cac:PartyLegalEntity>
72+
</cac:Party>
73+
</cac:DespatchSupplierParty>
74+
<cac:DeliveryCustomerParty>
75+
<cbc:CustomerAssignedAccountID schemeID="6">12345678912</cbc:CustomerAssignedAccountID>
76+
<cac:Party>
77+
<cac:PartyLegalEntity>
78+
<cbc:RegistrationName>Softgreen S.A.C</cbc:RegistrationName>
79+
</cac:PartyLegalEntity>
80+
</cac:Party>
81+
</cac:DeliveryCustomerParty>
82+
<cac:Shipment>
83+
<cbc:ID>1</cbc:ID>
84+
<cbc:HandlingCode>13</cbc:HandlingCode>
85+
<cbc:Information>TRASLADO A OBRA</cbc:Information>
86+
<cbc:GrossWeightMeasure unitCode="KGM">26.000</cbc:GrossWeightMeasure>
87+
<cbc:SplitConsignmentIndicator>false</cbc:SplitConsignmentIndicator>
88+
<cac:ShipmentStage>
89+
<cbc:TransportModeCode>02</cbc:TransportModeCode>
90+
<cac:TransitPeriod>
91+
<cbc:StartDate>2022-12-15</cbc:StartDate>
92+
</cac:TransitPeriod>
93+
<cac:CarrierParty>
94+
<cac:PartyIdentification>
95+
<cbc:ID schemeID="6">12345678912</cbc:ID>
96+
</cac:PartyIdentification>
97+
<cac:PartyName>
98+
<cbc:Name>Softgreen S.A.C</cbc:Name>
99+
</cac:PartyName>
100+
</cac:CarrierParty>
101+
<cac:TransportMeans>
102+
<cac:RoadTransport>
103+
<cbc:LicensePlateID>BBA-803</cbc:LicensePlateID>
104+
</cac:RoadTransport>
105+
</cac:TransportMeans>
106+
<cac:DriverPerson>
107+
<cbc:ID schemeID="1">71988046</cbc:ID>
108+
</cac:DriverPerson>
109+
</cac:ShipmentStage>
110+
<cac:Delivery>
111+
<cac:DeliveryAddress>
112+
<cbc:ID>080910</cbc:ID>
113+
<cbc:StreetName>AV. AVIACION</cbc:StreetName>
114+
<cac:Country>
115+
<cbc:IdentificationCode>PE</cbc:IdentificationCode>
116+
</cac:Country>
117+
</cac:DeliveryAddress>
118+
</cac:Delivery>
119+
<cac:OriginAddress>
120+
<cbc:ID>080910</cbc:ID>
121+
<cbc:StreetName>S/N CENTRO POB. PICHARI</cbc:StreetName>
122+
<cac:Country>
123+
<cbc:IdentificationCode>PE</cbc:IdentificationCode>
124+
</cac:Country>
125+
</cac:OriginAddress>
126+
</cac:Shipment>
127+
<cac:DespatchLine>
128+
<cbc:ID>1</cbc:ID>
129+
<cbc:DeliveredQuantity unitCode="NIU">3</cbc:DeliveredQuantity>
130+
<cac:OrderLineReference>
131+
<cbc:LineID>1</cbc:LineID>
132+
</cac:OrderLineReference>
133+
<cac:Item>
134+
<cbc:Name>ESPATULA DE 3""</cbc:Name>
135+
<cac:SellersItemIdentification>
136+
<cbc:ID>3121190200070403</cbc:ID>
137+
</cac:SellersItemIdentification>
138+
</cac:Item>
139+
</cac:DespatchLine>
140+
<cac:DespatchLine>
141+
<cbc:ID>2</cbc:ID>
142+
<cbc:DeliveredQuantity unitCode="BG">1</cbc:DeliveredQuantity>
143+
<cac:OrderLineReference>
144+
<cbc:LineID>1</cbc:LineID>
145+
</cac:OrderLineReference>
146+
<cac:Item>
147+
<cbc:Name>TEMPLE PATO BLANCO X 25 KG</cbc:Name>
148+
<cac:SellersItemIdentification>
149+
<cbc:ID>250811</cbc:ID>
150+
</cac:SellersItemIdentification>
151+
</cac:Item>
152+
</cac:DespatchLine>
153+
</DespatchAdvice>

quarkus-extension/integration-tests/src/main/java/io/github/project/openubl/quarkus/xsender/it/QuarkusXSenderResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class QuarkusXSenderResource {
5050
CompanyURLs companyURLs = CompanyURLs
5151
.builder()
5252
.invoice("https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService")
53-
.despatch("https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService")
53+
.despatch("https://e-beta.sunat.gob.pe/ol-ti-itemision-guia-gem-beta/billService")
5454
.perceptionRetention("https://e-beta.sunat.gob.pe/ol-ti-itemision-guia-gem-beta/billService")
5555
.build();
5656

0 commit comments

Comments
 (0)