use of com.helger.as2lib.client.AS2ClientSettings in project as2-lib by phax.
the class MainSendToMendelsonTestServer method main.
public static void main(final String[] args) throws Exception {
Proxy aHttpProxy = null;
if (false)
aHttpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.2.3.4", 8080));
IHTTPOutgoingDumperFactory aOutgoingDumperFactory = null;
if (false)
aOutgoingDumperFactory = x -> new HTTPOutgoingDumperStreamBased(System.out);
if (false)
HTTPHelper.setHTTPIncomingDumperFactory(() -> new HTTPIncomingDumperStreamBased(new NonClosingOutputStream(System.out)));
// Start client configuration
final AS2ClientSettings aSettings = new AS2ClientSettings();
aSettings.setKeyStore(EKeyStoreType.PKCS12, new File("src/test/resources/mendelson/key3.pfx"), "test");
// Fixed sender
aSettings.setSenderData("mycompanyAS2", "phax.as2-lib@github.com", "key3");
// Fixed receiver - key alias must be "mendelsontestAS2"
aSettings.setReceiverData("mendelsontestAS2", "mendelsontestAS2", true ? "https://testas2.mendelson-e-c.com:8444/as2/HttpReceiver" : "http://testas2.mendelson-e-c.com:8080/as2/HttpReceiver");
final X509Certificate aReceiverCertificate = AS2KeyStoreHelper.readX509Certificate("src/test/resources/mendelson/key4.cer");
aSettings.setReceiverCertificate(aReceiverCertificate);
// AS2 stuff
aSettings.setPartnershipName(aSettings.getSenderAS2ID() + "_" + aSettings.getReceiverAS2ID());
// When a signed message is used, the algorithm for MIC and message must be
// identical
final ECryptoAlgorithmSign eSignAlgo = ECryptoAlgorithmSign.DIGEST_SHA_512;
// CBC works, GCM is not supported
final ECryptoAlgorithmCrypt eCryptAlgo = ECryptoAlgorithmCrypt.CRYPT_AES128_CBC;
final ECompressionType eCompress = ECompressionType.ZLIB;
final boolean bCompressBeforeSigning = AS2ClientSettings.DEFAULT_COMPRESS_BEFORE_SIGNING;
aSettings.setMDNOptions(new DispositionOptions().setMICAlg(eSignAlgo).setMICAlgImportance(DispositionOptions.IMPORTANCE_REQUIRED).setProtocol(DispositionOptions.PROTOCOL_PKCS7_SIGNATURE).setProtocolImportance(DispositionOptions.IMPORTANCE_REQUIRED));
aSettings.setEncryptAndSign(eCryptAlgo, eSignAlgo);
aSettings.setCompress(eCompress, bCompressBeforeSigning);
aSettings.setMessageIDFormat("github-phax-as2-lib-$date.uuuuMMdd-HHmmssZ$-$rand.1234$@$msg.sender.as2_id$_$msg.receiver.as2_id$");
aSettings.setRetryCount(1);
aSettings.setConnectTimeoutMS(10_000);
aSettings.setReadTimeoutMS(10_000);
aSettings.setHttpOutgoingDumperFactory(aOutgoingDumperFactory);
// Build client request
final AS2ClientRequest aRequest = new AS2ClientRequest("AS2 test message from as2-lib");
aRequest.setData(new DataHandler(new FileDataSource(new File("src/test/resources/mendelson/testcontent.attachment"))));
aRequest.setContentType(CMimeType.TEXT_PLAIN.getAsString());
if (false)
aRequest.setContentTransferEncoding(EContentTransferEncoding.BASE64);
// Send message
final AS2ClientResponse aResponse = new AS2Client().setHttpProxy(aHttpProxy).sendSynchronous(aSettings, aRequest);
if (aResponse.hasException())
LOGGER.info(aResponse.getAsString());
LOGGER.info("Done");
}
use of com.helger.as2lib.client.AS2ClientSettings in project as2-server by phax.
the class MainTestClient method main.
public static void main(final String[] args) {
final boolean DO_ENCRYPT = true;
final boolean DO_SIGN = true;
final AS2ClientSettings aSettings = new AS2ClientSettings();
aSettings.setKeyStore(EKeyStoreType.PKCS12, ClassPathResource.getAsFile("config/certs.p12"), "test");
aSettings.setSenderData("OpenAS2A", "email@example.org", "OpenAS2A_alias");
aSettings.setReceiverData("OpenAS2B", "OpenAS2B_alias", "http://localhost:10080/HttpReceiver");
aSettings.setPartnershipName("Partnership name");
aSettings.setEncryptAndSign(DO_ENCRYPT ? ECryptoAlgorithmCrypt.CRYPT_3DES : null, DO_SIGN ? ECryptoAlgorithmSign.DIGEST_SHA_1 : null);
// Use the default MDN options
// Use the default message ID format
final AS2ClientRequest aRequest = new AS2ClientRequest("Test message");
aRequest.setData(new File("src/test/resources/dummy.txt"), SystemHelper.getSystemCharset());
new AS2Client().sendSynchronous(aSettings, aRequest);
}
use of com.helger.as2lib.client.AS2ClientSettings in project as2-lib by phax.
the class MainTestClient method main.
public static void main(final String[] args) {
final boolean DO_ENCRYPT = true;
final boolean DO_SIGN = true;
final AS2ClientSettings aSettings = new AS2ClientSettings();
aSettings.setKeyStore(EKeyStoreType.PKCS12, ClassPathResource.getAsFile("config/certs.p12"), "test");
aSettings.setSenderData("OpenAS2A", "email@example.org", "OpenAS2A_alias");
aSettings.setReceiverData("OpenAS2B", "OpenAS2B_alias", "http://localhost:10080/HttpReceiver");
aSettings.setPartnershipName("Partnership name");
aSettings.setEncryptAndSign(DO_ENCRYPT ? ECryptoAlgorithmCrypt.CRYPT_3DES : null, DO_SIGN ? ECryptoAlgorithmSign.DIGEST_SHA_1 : null);
// Use the default MDN options
// Use the default message ID format
final AS2ClientRequest aRequest = new AS2ClientRequest("Test message");
aRequest.setData(new File("src/test/resources/dummy.txt"), SystemHelper.getSystemCharset());
new AS2Client().sendSynchronous(aSettings, aRequest);
}
use of com.helger.as2lib.client.AS2ClientSettings in project as2-lib by phax.
the class MainIssue45 method main.
public static void main(final String[] args) throws Exception {
// Enable or disable debug mode
if (false)
GlobalDebug.setDebugModeDirect(false);
Proxy aHttpProxy = null;
if (true)
aHttpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("172.30.9.6", 8080));
// Start client configuration
final AS2ClientSettings aSettings = new AS2ClientSettings();
aSettings.setKeyStore(EKeyStoreType.PKCS12, new File("src/test/resources/mendelson/key3.pfx"), "test");
// Fixed sender
aSettings.setSenderData("mycompanyAS2", "phax.as2-lib@github.com", "key3");
// Fixed receiver - key alias must be "mendelsontestAS2"
aSettings.setReceiverData("mendelsontestAS2", "mendelsontestAS2", "http://testas2.mendelson-e-c.com:8080/as2/HttpReceiver");
final X509Certificate aReceiverCertificate = AS2KeyStoreHelper.readX509Certificate("src/test/resources/mendelson/key4.cer");
aSettings.setReceiverCertificate(aReceiverCertificate);
// AS2 stuff
aSettings.setPartnershipName(aSettings.getSenderAS2ID() + "_" + aSettings.getReceiverAS2ID());
// When a signed message is used, the algorithm for MIC and message must be
// identical
final ECryptoAlgorithmSign eSignAlgo = null;
final ECryptoAlgorithmCrypt eCryptAlgo = null;
final boolean bCompress = false;
aSettings.setEncryptAndSign(eCryptAlgo, eSignAlgo);
aSettings.setCompress(ECompressionType.ZLIB, bCompress);
aSettings.setMessageIDFormat("github-phax-as2-lib-$date.ddMMuuuuHHmmssZ$-$rand.1234$@$msg.sender.as2_id$_$msg.receiver.as2_id$");
aSettings.setRetryCount(1);
aSettings.setConnectTimeoutMS(10_000);
aSettings.setReadTimeoutMS(10_000);
// Build client request
final AS2ClientRequest aRequest = new AS2ClientRequest("AS2 test message from as2-lib");
aRequest.setData(new File("src/test/resources/mendelson/testcontent.attachment"), Charset.defaultCharset());
aRequest.setContentType(CMimeType.TEXT_PLAIN.getAsString());
// Send message
final AS2ClientResponse aResponse = new AS2Client().setHttpProxy(aHttpProxy).sendSynchronous(aSettings, aRequest);
if (aResponse.hasException())
LOGGER.info(aResponse.getAsString());
LOGGER.info("Done");
}
use of com.helger.as2lib.client.AS2ClientSettings in project as2-lib by phax.
the class MainSendToLocalhost8080 method main.
public static void main(final String[] args) throws Exception {
Proxy aHttpProxy = null;
if (false)
aHttpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.2.3.4", 8080));
IHTTPOutgoingDumperFactory aOutgoingDumperFactory = null;
if (false)
aOutgoingDumperFactory = x -> new HTTPOutgoingDumperStreamBased(System.out);
if (false)
HTTPHelper.setHTTPIncomingDumperFactory(() -> new HTTPIncomingDumperStreamBased(new NonClosingOutputStream(System.out)));
// Start client configuration
final AS2ClientSettings aSettings = new AS2ClientSettings();
aSettings.setKeyStore(EKeyStoreType.PKCS12, new File("src/test/resources/localhost/certs.p12"), "test");
// Fixed sender
aSettings.setSenderData("mycompanyAS2", "phax.as2-lib@github.com", "openas2a_alias");
// Fixed receiver - key alias must be "openas2b_alias"
aSettings.setReceiverData("openas2b_alias", "openas2b_alias", "http://localhost:8080/as2");
final X509Certificate aReceiverCertificate = AS2KeyStoreHelper.readX509Certificate("src/test/resources/mendelson/key4.cer");
aSettings.setReceiverCertificate(aReceiverCertificate);
// AS2 stuff
aSettings.setPartnershipName(aSettings.getSenderAS2ID() + "_" + aSettings.getReceiverAS2ID());
// When a signed message is used, the algorithm for MIC and message must be
// identical
final ECryptoAlgorithmSign eSignAlgo = ECryptoAlgorithmSign.DIGEST_SHA_256;
final ECryptoAlgorithmCrypt eCryptAlgo = ECryptoAlgorithmCrypt.CRYPT_AES128_GCM;
final ECompressionType eCompress = ECompressionType.ZLIB;
final boolean bCompressBeforeSigning = AS2ClientSettings.DEFAULT_COMPRESS_BEFORE_SIGNING;
aSettings.setMDNOptions(new DispositionOptions().setMICAlg(eSignAlgo).setMICAlgImportance(DispositionOptions.IMPORTANCE_REQUIRED).setProtocol(DispositionOptions.PROTOCOL_PKCS7_SIGNATURE).setProtocolImportance(DispositionOptions.IMPORTANCE_REQUIRED));
aSettings.setEncryptAndSign(eCryptAlgo, eSignAlgo);
aSettings.setCompress(eCompress, bCompressBeforeSigning);
aSettings.setMessageIDFormat("github-phax-as2-lib-$date.uuuuMMdd-HHmmssZ$-$rand.1234$@$msg.sender.as2_id$_$msg.receiver.as2_id$");
aSettings.setRetryCount(1);
aSettings.setConnectTimeoutMS(10_000);
aSettings.setReadTimeoutMS(10_000);
aSettings.setHttpOutgoingDumperFactory(aOutgoingDumperFactory);
// Build client request
final AS2ClientRequest aRequest = new AS2ClientRequest("AS2 test message from as2-lib");
aRequest.setData(new DataHandler(new FileDataSource(new File("src/test/resources/mendelson/testcontent.attachment"))));
aRequest.setContentType(CMimeType.TEXT_PLAIN.getAsString());
if (false)
aRequest.setContentTransferEncoding(EContentTransferEncoding.BASE64);
// Send message
final AS2ClientResponse aResponse = new AS2Client().setHttpProxy(aHttpProxy).sendSynchronous(aSettings, aRequest);
if (aResponse.hasException())
LOGGER.info(aResponse.getAsString());
LOGGER.info("Done");
}
Aggregations