init
This commit is contained in:
parent
6d40bfb243
commit
9017787ea2
38
.classpath
Normal file
38
.classpath
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dp</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
36
pom.xml
Normal file
36
pom.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<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>
|
||||
<groupId>pi</groupId>
|
||||
<artifactId>dp</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>PIDP</name>
|
||||
<description>INTEGRAZIONE CON DPR&DI da Zucchetti Infinity</description>
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
</properties>
|
||||
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
|
||||
<dependencies>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.12</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
134
src/main/java/pidp/client/ApiClient.java
Normal file
134
src/main/java/pidp/client/ApiClient.java
Normal file
@ -0,0 +1,134 @@
|
||||
package pidp.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import pidp.utils.HMAC;
|
||||
|
||||
public class ApiClient {
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private String appId;
|
||||
|
||||
private String apiKey;
|
||||
|
||||
private int responseStatusCode;
|
||||
|
||||
private String responseBody;
|
||||
|
||||
private HttpPost post;
|
||||
|
||||
public void postJson(String jsonData) throws Exception {
|
||||
|
||||
String nonce, timestamp, entityHash, urlEncoded;
|
||||
|
||||
URI uri = URI.create(getPostUrl().toLowerCase());
|
||||
urlEncoded = URLEncoder.encode(getPostUrl(), "UTF8").toLowerCase();// per signature, lower case!
|
||||
|
||||
// nonce
|
||||
nonce = RandomStringUtils.randomAlphanumeric(32);
|
||||
|
||||
// timestamp
|
||||
timestamp = String.valueOf(new Timestamp(System.currentTimeMillis()).toInstant().getEpochSecond());
|
||||
|
||||
// hash della request
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
entityHash = Base64.getEncoder().encodeToString(md.digest(jsonData.getBytes()));
|
||||
|
||||
String signatureRawData = getAppId() + "POST" + urlEncoded + timestamp + nonce + entityHash;
|
||||
|
||||
byte[] signature = signatureRawData.getBytes("UTF-8");
|
||||
byte[] secretKeyByteArray = Base64.getDecoder().decode(getApiKey());
|
||||
|
||||
// hmac
|
||||
byte[] signatureBytes = HMAC.calcHmacSha256(secretKeyByteArray, signature);
|
||||
|
||||
// headers
|
||||
StringEntity entity = new StringEntity(jsonData,"utf-8");//IMPORTANTE SPECIFICARE UTF-8, la libreria setta latin1 di default!
|
||||
post = new HttpPost(uri);
|
||||
post.setEntity(entity);
|
||||
post.setHeader("Accept", "application/json");
|
||||
post.setHeader("Content-type", "application/json");
|
||||
post.setHeader("Authorization", "amx " + getAppId() + ":" + Base64.getEncoder().encodeToString(signatureBytes)
|
||||
+ ":" + nonce + ":" + timestamp);
|
||||
|
||||
// richiesta
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = client.execute(post);
|
||||
|
||||
// risposta
|
||||
setResponseBody(EntityUtils.toString(response.getEntity()));
|
||||
setResponseStatusCode(response.getStatusLine().getStatusCode());
|
||||
|
||||
// if (responseStatusCode > 200) {
|
||||
// System.err.println("entityHash::: " + entityHash);
|
||||
// System.err.println("SIGRAWDATA: " + signatureRawData);
|
||||
// System.err.println("SIGBYTES IN BASE64: " + Base64.getEncoder().encodeToString(signatureBytes));
|
||||
// for (Header header : Arrays.asList(post.getAllHeaders())) {
|
||||
// System.err.println("Headers.. name,value:" + header.getName() + "," + header.getValue());
|
||||
// }
|
||||
// System.err.println("REQUEST BODY: " + jsonData);
|
||||
// System.err.println("RESPONSE STATUS LINE: " + response.getStatusLine());
|
||||
// System.err.println("RESPONSE BODY: " + getResponseBody());
|
||||
// }
|
||||
|
||||
client.close();
|
||||
}
|
||||
|
||||
public String getPostUrl() {
|
||||
return postUrl;
|
||||
}
|
||||
|
||||
public void setPostUrl(String postUrl) {
|
||||
this.postUrl = postUrl;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public int getResponseStatusCode() {
|
||||
return responseStatusCode;
|
||||
}
|
||||
|
||||
private void setResponseStatusCode(int responseStatusCode) {
|
||||
this.responseStatusCode = responseStatusCode;
|
||||
}
|
||||
|
||||
public String getPostString() {
|
||||
return "__M:" + post.getMethod() + "__BODY:" + post.getEntity().toString() + "__URI:" + post.getURI()
|
||||
+ "__HEADERS:" + post.getAllHeaders();
|
||||
}
|
||||
|
||||
public String getResponseBody() {
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
public void setResponseBody(String responseBody) {
|
||||
this.responseBody = responseBody;
|
||||
}
|
||||
}
|
||||
20
src/main/java/pidp/ents/Allegato.java
Normal file
20
src/main/java/pidp/ents/Allegato.java
Normal file
@ -0,0 +1,20 @@
|
||||
package pidp.ents;
|
||||
|
||||
public class Allegato {
|
||||
|
||||
private String NomeFile;
|
||||
private String ContenutoBase64;
|
||||
public String getNomeFile() {
|
||||
return NomeFile;
|
||||
}
|
||||
public void setNomeFile(String nomeFile) {
|
||||
NomeFile = nomeFile;
|
||||
}
|
||||
public String getContenutoBase64() {
|
||||
return ContenutoBase64;
|
||||
}
|
||||
public void setContenutoBase64(String contenutoBase64) {
|
||||
ContenutoBase64 = contenutoBase64;
|
||||
}
|
||||
|
||||
}
|
||||
199
src/main/java/pidp/ents/Documento.java
Normal file
199
src/main/java/pidp/ents/Documento.java
Normal file
@ -0,0 +1,199 @@
|
||||
package pidp.ents;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Documento {
|
||||
|
||||
private String CodiceAziendaMittente;
|
||||
private int Operazione;
|
||||
private String CodiceUnivocoDocumentoInterno;
|
||||
private String CodiceUnivocoDocumentoEsterno;
|
||||
private String Descrizione;
|
||||
private String DataDocumento;//LA STRINGA HA FORMATO COME OffsetDateTime.now().toString()
|
||||
private String DataRegistrazione;//OffsetDateTime.now().toString()
|
||||
private String DataUltimaModifica;//OffsetDateTime.now().toString()
|
||||
private String FornitoreCodiceUnivocoInterno;
|
||||
private String FornitorePartitaIva;
|
||||
private String FornitoreCodiceFiscale;
|
||||
private String FornitoreDenominazione;
|
||||
private String PeriodoValiditaInizio;
|
||||
private String PeriodoValiditaFine;
|
||||
private double Importo;
|
||||
private String CodiceCommessa;
|
||||
private String NomeCommessa;
|
||||
|
||||
private List<Allegato> Allegati = new ArrayList<Allegato>();
|
||||
|
||||
public void addAllegato(Allegato a) {
|
||||
|
||||
this.Allegati.add(a);
|
||||
}
|
||||
|
||||
public String getCodiceAziendaMittente() {
|
||||
return CodiceAziendaMittente;
|
||||
}
|
||||
|
||||
public void setCodiceAziendaMittente(String codiceAziendaMittente) {
|
||||
CodiceAziendaMittente = codiceAziendaMittente;
|
||||
}
|
||||
|
||||
public int getOperazione() {
|
||||
return Operazione;
|
||||
}
|
||||
|
||||
public void setOperazione(int operazione) {
|
||||
Operazione = operazione;
|
||||
}
|
||||
|
||||
public String getCodiceUnivocoDocumentoInterno() {
|
||||
return CodiceUnivocoDocumentoInterno;
|
||||
}
|
||||
|
||||
public void setCodiceUnivocoDocumentoInterno(String codiceUnivocoDocumentoInterno) {
|
||||
CodiceUnivocoDocumentoInterno = codiceUnivocoDocumentoInterno;
|
||||
}
|
||||
|
||||
public String getCodiceUnivocoDocumentoEsterno() {
|
||||
return CodiceUnivocoDocumentoEsterno;
|
||||
}
|
||||
|
||||
public void setCodiceUnivocoDocumentoEsterno(String codiceUnivocoDocumentoEsterno) {
|
||||
CodiceUnivocoDocumentoEsterno = codiceUnivocoDocumentoEsterno;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return Descrizione;
|
||||
}
|
||||
|
||||
public void setDescrizione(String descrizione) {
|
||||
Descrizione = descrizione;
|
||||
}
|
||||
|
||||
public String getDataDocumento() {
|
||||
return DataDocumento;
|
||||
}
|
||||
|
||||
public void setDataDocumento(String dataDocumento) {
|
||||
DataDocumento = dataDocumento;
|
||||
}
|
||||
|
||||
public void setDataDocumento(java.sql.Timestamp in) {
|
||||
DataDocumento = OffsetDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()).toString();
|
||||
}
|
||||
|
||||
public void setDataDocumento(java.sql.Date in) {
|
||||
setDataDocumento(new java.sql.Timestamp(in.getTime()));
|
||||
}
|
||||
|
||||
public String getDataRegistrazione() {
|
||||
return DataRegistrazione;
|
||||
}
|
||||
|
||||
public void setDataRegistrazione(String dataRegistrazione) {
|
||||
DataRegistrazione = dataRegistrazione;
|
||||
}
|
||||
|
||||
public void setDataRegistrazione(java.sql.Timestamp in) {
|
||||
DataRegistrazione = OffsetDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()).toString();
|
||||
}
|
||||
|
||||
public void setDataRegistrazione(java.sql.Date in) {
|
||||
setDataRegistrazione(new java.sql.Timestamp(in.getTime()));
|
||||
}
|
||||
|
||||
public String getDataUltimaModifica() {
|
||||
return DataUltimaModifica;
|
||||
}
|
||||
|
||||
public void setDataUltimaModifica(String dataUltimaModifica) {
|
||||
DataUltimaModifica = dataUltimaModifica;
|
||||
}
|
||||
|
||||
public void setDataUltimaModifica(java.sql.Timestamp in) {
|
||||
DataUltimaModifica = OffsetDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()).toString();
|
||||
}
|
||||
|
||||
public String getFornitoreCodiceUnivocoInterno() {
|
||||
return FornitoreCodiceUnivocoInterno;
|
||||
}
|
||||
|
||||
public void setFornitoreCodiceUnivocoInterno(String fornitoreCodiceUnivocoInterno) {
|
||||
FornitoreCodiceUnivocoInterno = fornitoreCodiceUnivocoInterno;
|
||||
}
|
||||
|
||||
public String getFornitorePartitaIva() {
|
||||
return FornitorePartitaIva;
|
||||
}
|
||||
|
||||
public void setFornitorePartitaIva(String fornitorePartitaIva) {
|
||||
FornitorePartitaIva = fornitorePartitaIva;
|
||||
}
|
||||
|
||||
public String getFornitoreCodiceFiscale() {
|
||||
return FornitoreCodiceFiscale;
|
||||
}
|
||||
|
||||
public void setFornitoreCodiceFiscale(String fornitoreCodiceFiscale) {
|
||||
FornitoreCodiceFiscale = fornitoreCodiceFiscale;
|
||||
}
|
||||
|
||||
public String getFornitoreDenominazione() {
|
||||
return FornitoreDenominazione;
|
||||
}
|
||||
|
||||
public void setFornitoreDenominazione(String fornitoreDenominazione) {
|
||||
FornitoreDenominazione = fornitoreDenominazione;
|
||||
}
|
||||
|
||||
public String getPeriodoValiditaInizio() {
|
||||
return PeriodoValiditaInizio;
|
||||
}
|
||||
|
||||
public void setPeriodoValiditaInizio(String periodoValiditaInizio) {
|
||||
PeriodoValiditaInizio = periodoValiditaInizio;
|
||||
}
|
||||
|
||||
public String getPeriodoValiditaFine() {
|
||||
return PeriodoValiditaFine;
|
||||
}
|
||||
|
||||
public void setPeriodoValiditaFine(String periodoValiditaFine) {
|
||||
PeriodoValiditaFine = periodoValiditaFine;
|
||||
}
|
||||
|
||||
public double getImporto() {
|
||||
return Importo;
|
||||
}
|
||||
|
||||
public void setImporto(double importo) {
|
||||
Importo = importo;
|
||||
}
|
||||
|
||||
public String getCodiceCommessa() {
|
||||
return CodiceCommessa;
|
||||
}
|
||||
|
||||
public void setCodiceCommessa(String codiceCommessa) {
|
||||
CodiceCommessa = codiceCommessa;
|
||||
}
|
||||
|
||||
public String getNomeCommessa() {
|
||||
return NomeCommessa;
|
||||
}
|
||||
|
||||
public void setNomeCommessa(String nomeCommessa) {
|
||||
NomeCommessa = nomeCommessa;
|
||||
}
|
||||
|
||||
public List<Allegato> getAllegati() {
|
||||
return Allegati;
|
||||
}
|
||||
|
||||
public void setAllegati(List<Allegato> allegati) {
|
||||
Allegati = allegati;
|
||||
}
|
||||
|
||||
}
|
||||
64
src/main/java/pidp/ents/Soggetto.java
Normal file
64
src/main/java/pidp/ents/Soggetto.java
Normal file
@ -0,0 +1,64 @@
|
||||
package pidp.ents;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
public class Soggetto {
|
||||
|
||||
private String CodiceAziendaMittente;
|
||||
private int Operazione;
|
||||
private String CodiceUnivocoFornitoreInterno;
|
||||
private String PartitaIva;
|
||||
private String CodiceFiscale;
|
||||
private String Denominazione;
|
||||
private String DataUltimaModifica;
|
||||
|
||||
public String getCodiceAziendaMittente() {
|
||||
return CodiceAziendaMittente;
|
||||
}
|
||||
public void setCodiceAziendaMittente(String codiceAziendaMittente) {
|
||||
CodiceAziendaMittente = codiceAziendaMittente;
|
||||
}
|
||||
public int getOperazione() {
|
||||
return Operazione;
|
||||
}
|
||||
public void setOperazione(int operazione) {
|
||||
Operazione = operazione;
|
||||
}
|
||||
public String getCodiceUnivocoFornitoreInterno() {
|
||||
return CodiceUnivocoFornitoreInterno;
|
||||
}
|
||||
public void setCodiceUnivocoFornitoreInterno(String codiceUnivocoFornitoreInterno) {
|
||||
CodiceUnivocoFornitoreInterno = codiceUnivocoFornitoreInterno;
|
||||
}
|
||||
public String getPartitaIva() {
|
||||
return PartitaIva;
|
||||
}
|
||||
public void setPartitaIva(String partitaIva) {
|
||||
PartitaIva = partitaIva;
|
||||
}
|
||||
public String getCodiceFiscale() {
|
||||
return CodiceFiscale;
|
||||
}
|
||||
public void setCodiceFiscale(String codiceFiscale) {
|
||||
CodiceFiscale = codiceFiscale;
|
||||
}
|
||||
public String getDenominazione() {
|
||||
return Denominazione;
|
||||
}
|
||||
public void setDenominazione(String denominazione) {
|
||||
Denominazione = denominazione;
|
||||
}
|
||||
public String getDataUltimaModifica() {
|
||||
return DataUltimaModifica;
|
||||
}
|
||||
public void setDataUltimaModifica(String dataUltimaModifica) {
|
||||
DataUltimaModifica = dataUltimaModifica;
|
||||
}
|
||||
public void setDataUltimaModifica(java.sql.Timestamp in) {
|
||||
DataUltimaModifica = OffsetDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()).toString();// OffsetDateTime.ofInstant().toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
src/main/java/pidp/utils/FileUtils.java
Normal file
17
src/main/java/pidp/utils/FileUtils.java
Normal file
@ -0,0 +1,17 @@
|
||||
package pidp.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static String pathToBase64(String pathin) throws IOException {
|
||||
|
||||
byte[] inFileBytes = Files.readAllBytes(Paths.get(pathin));
|
||||
String encoded = java.util.Base64.getEncoder().encodeToString(inFileBytes);
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
}
|
||||
20
src/main/java/pidp/utils/HMAC.java
Normal file
20
src/main/java/pidp/utils/HMAC.java
Normal file
@ -0,0 +1,20 @@
|
||||
package pidp.utils;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class HMAC {
|
||||
|
||||
static public byte[] calcHmacSha256(byte[] secretKey, byte[] message) {
|
||||
byte[] hmacSha256 = null;
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey, "HmacSHA256");
|
||||
mac.init(secretKeySpec);
|
||||
hmacSha256 = mac.doFinal(message);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to calculate hmac-sha256", e);
|
||||
}
|
||||
return hmacSha256;
|
||||
}
|
||||
}
|
||||
84
src/test/java/pidp/test/Test.java
Normal file
84
src/test/java/pidp/test/Test.java
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user