Skip to content

Instantly share code, notes, and snippets.

Created June 28, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/dde7433be2bb354df48764853dac9dbb to your computer and use it in GitHub Desktop.
Save anonymous/dde7433be2bb354df48764853dac9dbb to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jpk;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.client.ClientConfig;
/**
*
* @author NikczemnyPan
*/
public class UploadPlikow {
public static void main(String[] args) {
SSLContext ctx = null;
String xmlXades = null;
Path sciezkaDoXadesa = Paths.get("./", "transakcje", "2016-06-28", "JPK_VAT_InitUpload.xml.XAdES");
try {
KeyStore trustStore;
trustStore = KeyStore.getInstance("JKS");
trustStore.load(UploadPlikow.class.getResourceAsStream("/keystore.jks"), "testkeystore".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory
.getInstance("SunX509");
tmf.init(trustStore);
ctx = SSLContext.getInstance("SSL");
ctx.init(null, tmf.getTrustManagers(), null);
xmlXades = IOUtils.toString(new FileInputStream(sciezkaDoXadesa.toFile()), "UTF-8");
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (CertificateException ex) {
ex.printStackTrace();
}
Client klient = ClientBuilder.newBuilder().sslContext(ctx).build();
WebTarget initUploadTarget = klient.target("https://test-e-dokumenty.mf.gov.pl/api/Storage/InitUploadSigned");
Response post = initUploadTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.xml(xmlXades));
String jsonOdpowiedz = post.readEntity(String.class);
// WebTarget target = klient.target("https://test-e-dokumenty.mf.gov.pl/api/Storage/Status/");
// WebTarget path = target.path("");
//
// Response getRespone = path.request(MediaType.APPLICATION_JSON_TYPE).get();
// System.out.println(getRespone.readEntity(String.class));
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment