solo seguito
https://docs.oracle.com/cd/E19509-01/820-3503/ggfgo/index.html https://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html
javac -cp .:/home/ec2-user/velu/*: QuickStart.java
java -cp .:/home/ec2-user/velu/*: QuickStart
[[email protected] velu]$ ls
QuickStart.class commons-codec-1.2.jar input-payload.txt logback-core-1.1.3.jar
QuickStart.java commons-httpclient-3.1.jar httpclient-4.5.jar jdk-8u101-linux-x64.rpm slf4j-api-1.7.12.jar
certificates commons-logging-1.2.jar httpcore-4.4.1.jar logback-classic-1.1.3.jar
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class QuickStart {
public static void main(String[] args) throws Exception {
System.setProperty("javax.net.ssl.keyStore", "/home/user/velu/certificates/myownOut.pkcs12");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
System.setProperty("javax.net.ssl.trustStore", "/home/user/velu/certificates/myTrustStore");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpClientParams params = new HttpClientParams();
params.setConnectionManagerClass(MultiThreadedHttpConnectionManager.class);
HttpClient client = new HttpClient(params);
HttpMethod m = new PostMethod("https://velu.org:443/Services/com/Echo");
m.setRequestHeader("content-type", "application/xml");
//m.setRequestHeader("Accept", "application/xml");
// m.setRequestHeader("SOAPAction", "Echo");
try {
((PostMethod) m).setRequestEntity(new StringRequestEntity(getFileContent(), "application/xml", "UTF-8"));
System.out.println("VELU EXCUTING");
client.executeMethod(m);
if (m.getStatusCode() == 200) {
System.out.println("VELU RECEIVED:" + m.getResponseBodyAsString());
}
} catch (IOException e) {
System.out.println(e.toString());
} finally {
m.releaseConnection();
}
}
public static String getFileContent() {
BufferedReader br = null;
String fileContent = "";
try {
br = new BufferedReader(new FileReader(
"/home/user/velu/input-payload.txt")); // Note that this file format should be proper.
String sCurrentLine = "";
while ((sCurrentLine = br.readLine()) != null) {
fileContent += sCurrentLine;
}
System.out.println(fileContent);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return fileContent;
}
fonte
2016-12-12 16:47:10
cosa serve questo servono? Non riesco a immaginare perché vorresti farlo. – erickson
Sto provando a verificare il contenuto del modulo nel mio server interno prima di inviare nuovamente la richiesta del client al server di hp. Questo credo che impedirebbe qualsiasi manomissione del pagamento basata su browser e il mio server potrebbe fare tutti i controlli previsti invece di avere il sito Web di hp farlo. Per fare ciò tuttavia ho bisogno di ottenere il certificato del server usando il codice java per eseguire l'handshake. Non voglio scaricare manualmente il certificato ogni volta e metterlo nel mio keystore. Voglio che il codice faccia automaticamente quella parte .. – Rohit
Non dovresti aver bisogno del certificato del server nel tuo keystore. Se il server è configurato correttamente, tutto ciò che serve è la "radice" della catena di certificati del server. – erickson