Skip to content

Commit d18af7c

Browse files
committed
Removed xml mapper and changed to JAXB unmarshalling for deserialization
Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>
1 parent 84e8cf4 commit d18af7c

File tree

12 files changed

+125
-99
lines changed

12 files changed

+125
-99
lines changed

peru-identity-dataprovider-plugin/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
```
3434
- When the authentication is completed through KBI, then the `sub` field of the claim contains the value of `nuConsultaDni` which is used to fetch the identity data from the resource url.
3535
36-
2. For referring the table creation and template insertion, see the sql scripts under db_scripts/mosip_certify/ddl folder of inji_certify: [db_scripts](https://github.com/peru-id/inji-certify/tree/master/db_scripts/mosip_certify/ddl)
36+
2. For referring the table creation and template insertion, see the sql scripts under db_scripts/mosip_certify/ddl folder of inji_certify: [db_scripts](https://github.com/peru-id/inji-certify/tree/peru-0.10.x/db_scripts/mosip_certify/ddl)
3737
3838
3. inji-config changes:
39-
- Refer to the properties file in [inji-config](https://github.com/peru-id/inji-config) that corresponds to the postgres plugin implementation.
39+
- Refer to the properties file in [inji-config](https://github.com/peru-id/inji-config) that corresponds to the peru-id data provider plugin implementation.
4040
[Certify Reniec Properties](https://github.com/peru-id/inji-config/blob/peru-0.5.x/certify-reniec-identity.properties)
4141
- The value for the property `mosip.certify.integration.data-provider-plugin` must be set to `PeruIdentityDataProviderPlugin`
4242
- Refer to the below properties for setting the `nuDniUsuario`, `nuRucUsuario`, `password` and `endpointUri` values:
@@ -71,7 +71,7 @@
7171
3. Deserialization of SOAP response:
7272
- Refer to the `response` directory.
7373
- Root class is `ResponseEnvelope`.
74-
- The response xml is then deserialized into `ResponseEnvelope` object using a XmlMapper.
74+
- The response xml is then deserialized into `ResponseEnvelope` object using a JAXBContext unmarshalling.
7575
- The `ResponseReturn` class contains the response parameters as response code, response message and the identity details as the `DatosPersona` object.
7676
7777
4. PeruIdentityDataProviderPlugin

peru-identity-dataprovider-plugin/pom.xml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<packaging>jar</packaging>
99

1010
<name>peru-identity-dataprovider-plugin</name>
11-
<url>https://github.com/mosip/digital-credential-plugins</url>
11+
<url>https://github.com/peru-id/digital-credential-plugins</url>
1212

1313
<licenses>
1414
<license>
@@ -17,17 +17,17 @@
1717
</license>
1818
</licenses>
1919
<scm>
20-
<connection>scm:git:git://github.com/mosip/digital-credential-plugins.git</connection>
21-
<developerConnection>scm:git:ssh://github.com:mosip/digital-credential-plugins.git</developerConnection>
22-
<url>https://github.com/mosip/digital-credential-plugins</url>
20+
<connection>scm:git:git://github.com/peru-id/digital-credential-plugins.git</connection>
21+
<developerConnection>scm:git:ssh://github.com:peru-id/digital-credential-plugins.git</developerConnection>
22+
<url>https://github.com/peru-id/digital-credential-plugins</url>
2323
<tag>HEAD</tag>
2424
</scm>
2525
<developers>
2626
<developer>
27-
<name>MOSIP</name>
27+
<name>Mosip</name>
2828
<email>mosip.emailnotifier@gmail.com</email>
2929
<organization>io.mosip</organization>
30-
<organizationUrl>https://www.mosip.io</organizationUrl>
30+
<organizationUrl>https://github.com/peru-id/digital-credential-plugins</organizationUrl>
3131
</developer>
3232
</developers>
3333

@@ -59,11 +59,6 @@
5959
<artifactId>slf4j-api</artifactId>
6060
<version>2.0.12</version>
6161
</dependency>
62-
<dependency>
63-
<groupId>com.fasterxml.jackson.dataformat</groupId>
64-
<artifactId>jackson-dataformat-xml</artifactId>
65-
<version>2.15.4</version>
66-
</dependency>
6762
<dependency>
6863
<groupId>org.mockito</groupId>
6964
<artifactId>mockito-core</artifactId>
@@ -102,15 +97,6 @@
10297
<enabled>false</enabled>
10398
</snapshots>
10499
</repository>
105-
<repository>
106-
<id>danubetech</id>
107-
<name>DanubetechCentral</name>
108-
<layout>default</layout>
109-
<url>https://repo.danubetech.com/repository/maven-releases/</url>
110-
<snapshots>
111-
<enabled>false</enabled>
112-
</snapshots>
113-
</repository>
114100
</repositories>
115101

116102
<distributionManagement>

peru-identity-dataprovider-plugin/postman-collections/consulta-datos.postman_collection_mosip.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"header": [],
1818
"body": {
1919
"mode": "raw",
20-
"raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:end=\"http://endpoint.wsconsultadni.reniec.gob.pe/\">\r\n <soapenv:Header/>\r\n <soapenv:Body>\r\n <end:consultar>\r\n <arg0>\r\n <!--Optional:-->\r\n <nuDniConsulta>42424242</nuDniConsulta>\r\n <!--Optional:-->\r\n <nuDniUsuario>42424242</nuDniUsuario>\r\n <!--Optional:-->\r\n <nuRucUsuario>20295613620</nuRucUsuario>\r\n <!--Optional:-->\r\n <password>42424242</password>\r\n </arg0>\r\n </end:consultar>\r\n </soapenv:Body>\r\n</soapenv:Envelope>",
20+
"raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:end=\"http://endpoint.wsconsultadni.reniec.gob.pe/\">\r\n <soapenv:Header/>\r\n <soapenv:Body>\r\n <end:consultar>\r\n <arg0>\r\n <!--Optional:-->\r\n <nuDniConsulta>12345678</nuDniConsulta>\r\n <!--Optional:-->\r\n <nuDniUsuario>12345678</nuDniUsuario>\r\n <!--Optional:-->\r\n <nuRucUsuario>12345678901</nuRucUsuario>\r\n <!--Optional:-->\r\n <password>12345678</password>\r\n </arg0>\r\n </end:consultar>\r\n </soapenv:Body>\r\n</soapenv:Envelope>",
2121
"options": {
2222
"raw": {
2323
"language": "xml"
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package io.mosip.certify.peruiddataprovider.integration.dto.response;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
5-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
3+
import jakarta.xml.bind.annotation.XmlAccessType;
4+
import jakarta.xml.bind.annotation.XmlAccessorType;
5+
import jakarta.xml.bind.annotation.XmlElement;
6+
import jakarta.xml.bind.annotation.XmlRootElement;
67

7-
@JacksonXmlRootElement(localName = "consultarResponse", namespace = "http://endpoint.wsconsultadni.reniec.gob.pe/")
8-
@JsonIgnoreProperties(ignoreUnknown = true)
8+
@XmlAccessorType(XmlAccessType.FIELD)
9+
@XmlRootElement(name = "consultar", namespace = "http://endpoint.wsconsultadni.reniec.gob.pe/")
910
public class ConsultarResponse {
10-
@JacksonXmlProperty(localName = "return")
11+
@XmlElement(name = "return")
1112
private ResponseReturn responseReturn;
1213

13-
public ResponseReturn getResponseReturn() { return responseReturn; }
14-
public void setResponseReturn(ResponseReturn responseReturn) { this.responseReturn = responseReturn; }
14+
public ResponseReturn getResponseReturn() {
15+
return responseReturn;
16+
}
17+
18+
public void setResponseReturn(ResponseReturn responseReturn) {
19+
this.responseReturn = responseReturn;
20+
}
1521
}

peru-identity-dataprovider-plugin/src/main/java/io/mosip/certify/peruiddataprovider/integration/dto/response/DatosPersona.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
package io.mosip.certify.peruiddataprovider.integration.dto.response;
33

4-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
6-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
4+
import jakarta.xml.bind.annotation.XmlAccessType;
5+
import jakarta.xml.bind.annotation.XmlAccessorType;
6+
import jakarta.xml.bind.annotation.XmlElement;
77

88

99
/**
@@ -33,37 +33,28 @@
3333
*
3434
*
3535
*/
36-
@JacksonXmlRootElement(localName = "datosPersona")
37-
@JsonIgnoreProperties(ignoreUnknown = true)
36+
@XmlAccessorType(XmlAccessType.FIELD)
3837
public class DatosPersona {
39-
@JacksonXmlProperty
38+
@XmlElement
4039
protected String dni;
41-
@JacksonXmlProperty
40+
@XmlElement
4241
protected String prenombres;
43-
@JacksonXmlProperty
42+
@XmlElement
4443
protected String primerApellido;
45-
@JacksonXmlProperty
44+
@XmlElement
4645
protected String apellidoCasada;
47-
@JacksonXmlProperty
46+
@XmlElement
4847
protected String segundoApellido;
49-
@JacksonXmlProperty
48+
@XmlElement
5049
protected String fechaNacimiento;
51-
@JacksonXmlProperty
50+
@XmlElement
5251
protected String genero;
53-
@JacksonXmlProperty
52+
@XmlElement
5453
protected String estadoCivil;
55-
@JacksonXmlProperty
54+
@XmlElement
5655
protected String restriccion;
57-
@JacksonXmlProperty
58-
protected String foto;
59-
60-
public String getFoto() {
61-
return foto;
62-
}
63-
64-
public void setFoto(String foto) {
65-
this.foto = foto;
66-
}
56+
@XmlElement
57+
protected String foto;
6758

6859
/**
6960
* Gets the value of the dni property.
@@ -281,4 +272,11 @@ public void setRestriccion(String value) {
281272
this.restriccion = value;
282273
}
283274

275+
public String getFoto() {
276+
return foto;
277+
}
278+
279+
public void setFoto(String foto) {
280+
this.foto = foto;
281+
}
284282
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package io.mosip.certify.peruiddataprovider.integration.dto.response;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
5-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
3+
import jakarta.xml.bind.annotation.XmlAccessType;
4+
import jakarta.xml.bind.annotation.XmlAccessorType;
5+
import jakarta.xml.bind.annotation.XmlElement;
6+
import jakarta.xml.bind.annotation.XmlRootElement;
67

7-
@JacksonXmlRootElement(localName = "Body")
8-
@JsonIgnoreProperties(ignoreUnknown = true)
8+
@XmlAccessorType(XmlAccessType.FIELD)
9+
@XmlRootElement(name = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
910
public class ResponseBody {
10-
@JacksonXmlProperty(localName = "consultarResponse", namespace = "http://endpoint.wsconsultadni.reniec.gob.pe/")
11+
@XmlElement(name = "consultarResponse", namespace = "http://endpoint.wsconsultadni.reniec.gob.pe/")
1112
private ConsultarResponse consultarResponse;
1213

13-
public ConsultarResponse getConsultarResponse() { return consultarResponse; }
14-
public void setConsultarResponse(ConsultarResponse consultarResponse) { this.consultarResponse = consultarResponse; }
15-
}
14+
public ConsultarResponse getConsultarResponse() {
15+
return consultarResponse;
16+
}
17+
18+
public void setConsultarResponse(ConsultarResponse consultarResponse) {
19+
this.consultarResponse = consultarResponse;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package io.mosip.certify.peruiddataprovider.integration.dto.response;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
5-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
6-
import io.mosip.certify.peruiddataprovider.integration.dto.response.ResponseBody;
3+
import jakarta.xml.bind.annotation.XmlAccessType;
4+
import jakarta.xml.bind.annotation.XmlAccessorType;
5+
import jakarta.xml.bind.annotation.XmlElement;
6+
import jakarta.xml.bind.annotation.XmlRootElement;
77

8-
@JacksonXmlRootElement(localName = "Envelope", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
9-
@JsonIgnoreProperties(ignoreUnknown = true)
8+
@XmlAccessorType(XmlAccessType.FIELD)
9+
@XmlRootElement(name = "Envelope", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
1010
public class ResponseEnvelope {
11+
@XmlElement(name = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
12+
private ResponseBody responseBody;
1113

12-
@JacksonXmlProperty(localName = "Body")
13-
private ResponseBody body;
14-
15-
public ResponseBody getBody() { return body; }
16-
public void setBody(ResponseBody body) { this.body = body; }
17-
}
14+
public ResponseBody getResponseBody() { return responseBody; }
15+
public void setResponseBody(ResponseBody value) { this.responseBody = value; }
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
package io.mosip.certify.peruiddataprovider.integration.dto.response;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
5-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
6-
import io.mosip.certify.peruiddataprovider.integration.dto.response.DatosPersona;
3+
import jakarta.xml.bind.annotation.XmlAccessType;
4+
import jakarta.xml.bind.annotation.XmlAccessorType;
5+
import jakarta.xml.bind.annotation.XmlElement;
76

8-
@JacksonXmlRootElement(localName = "return")
9-
@JsonIgnoreProperties(ignoreUnknown = true)
7+
@XmlAccessorType(XmlAccessType.FIELD)
108
public class ResponseReturn {
11-
@JacksonXmlProperty(localName = "coResultado")
9+
@XmlElement(name = "coResultado")
1210
private String coResultado;
1311

14-
@JacksonXmlProperty(localName = "deResultado")
12+
@XmlElement(name = "deResultado")
1513
private String deResultado;
1614

17-
@JacksonXmlProperty(localName = "datosPersona")
15+
@XmlElement(name = "datosPersona")
1816
private DatosPersona datosPersona;
1917

18+
public String getCoResultado() {
19+
return coResultado;
20+
}
21+
22+
public void setCoResultado(String coResultado) {
23+
this.coResultado = coResultado;
24+
}
25+
26+
public String getDeResultado() {
27+
return deResultado;
28+
}
29+
30+
public void setDeResultado(String deResultado) {
31+
this.deResultado = deResultado;
32+
}
33+
2034
public DatosPersona getDatosPersona() {
2135
return datosPersona;
2236
}
2337

2438
public void setDatosPersona(DatosPersona datosPersona) {
2539
this.datosPersona = datosPersona;
2640
}
27-
28-
public String getCoResultado() { return coResultado; }
29-
public void setCoResultado(String coResultado) { this.coResultado = coResultado; }
30-
31-
public String getDeResultado() { return deResultado; }
32-
public void setDeResultado(String deResultado) { this.deResultado = deResultado; }
3341
}

peru-identity-dataprovider-plugin/src/main/java/io/mosip/certify/peruiddataprovider/integration/service/ConsultaDniService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package io.mosip.certify.peruiddataprovider.integration.service;
22

3-
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
43
import io.mosip.certify.peruiddataprovider.integration.dto.request.ConsultaArg;
54
import io.mosip.certify.peruiddataprovider.integration.dto.response.ResponseEnvelope;
65
import io.mosip.certify.peruiddataprovider.integration.dto.response.ResponseReturn;
76
import io.mosip.certify.util.SoapUtil;
7+
import jakarta.xml.bind.JAXBContext;
8+
import jakarta.xml.bind.Unmarshaller;
89
import lombok.extern.slf4j.Slf4j;
910
import org.springframework.stereotype.Service;
1011

12+
import java.io.StringReader;
13+
1114
@Service
1215
@Slf4j
1316
public class ConsultaDniService {
@@ -20,11 +23,10 @@ public ResponseReturn getConsultarResponse(ConsultaArg consultaArg, String endpo
2023
String soapResponse = SoapUtil.sendSOAPRequest(endpointUri, soapRequest);
2124

2225
try {
23-
XmlMapper xmlMapper = new XmlMapper();
24-
ResponseEnvelope responseEnvelope = xmlMapper.readValue(soapResponse, ResponseEnvelope.class);
26+
ResponseEnvelope responseEnvelope = SoapUtil.getResponseEnvelope(soapResponse);
2527

26-
if(responseEnvelope != null && responseEnvelope.getBody() != null && responseEnvelope.getBody().getConsultarResponse() != null) {
27-
return responseEnvelope.getBody().getConsultarResponse().getResponseReturn();
28+
if(responseEnvelope != null && responseEnvelope.getResponseBody() != null && responseEnvelope.getResponseBody().getConsultarResponse() != null) {
29+
return responseEnvelope.getResponseBody().getConsultarResponse().getResponseReturn();
2830
}
2931

3032
} catch (Exception e) {

peru-identity-dataprovider-plugin/src/main/java/io/mosip/certify/peruiddataprovider/integration/service/PeruIdentityDataProviderPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public JSONObject fetchData(Map<String, Object> identityDetails) throws DataProv
4545
arg.setPassword(password);
4646
JSONObject jsonObject = new JSONObject();
4747
ResponseReturn responseReturn = consultaDniService.getConsultarResponse(arg, endpointUri);
48-
log.info("co result: " + responseReturn.getCoResultado());
49-
log.info("de result: " + responseReturn.getDeResultado());
5048
if(!responseReturn.getCoResultado().equals("0000")) {
5149
throw new Exception(responseReturn.getDeResultado());
5250
}

0 commit comments

Comments
 (0)