use of com.helger.as2lib.processor.sender.AS2SenderModule in project as2-server by phax.
the class MainTestClient method main2.
/**
* @param args
* Main args
* @throws Exception
* in case of error
*/
public static void main2(final String[] args) throws Exception {
// Received-content-MIC
// original-message-id
final String pidSenderEmail = "email";
final String pidAs2 = "GWTESTFM2i";
final String pidSenderAs2 = "Sender";
// "gwtestfm2i_trusted"; //
final String receiverKey = "rg_trusted";
final String senderKey = "rg";
final String paAs2Url = "http://172.16.148.1:8080/as2/HttpReceiver";
final AS2SenderModule aTestSender = new AS2SenderModule();
final Partnership aPartnership = new Partnership("partnership name");
aPartnership.setSenderAS2ID(pidSenderAs2);
aPartnership.setSenderX509Alias(senderKey);
aPartnership.setSenderEmail(pidSenderEmail);
aPartnership.setReceiverAS2ID(pidAs2);
aPartnership.setReceiverX509Alias(receiverKey);
aPartnership.setAttribute(CPartnershipIDs.PA_AS2_URL, paAs2Url);
if (false)
aPartnership.setAttribute(CPartnershipIDs.PA_AS2_MDN_TO, "http://localhost:10080");
aPartnership.setAttribute(CPartnershipIDs.PA_AS2_MDN_OPTIONS, new DispositionOptions().setProtocolImportance(DispositionOptions.IMPORTANCE_OPTIONAL).setProtocol(DispositionOptions.PROTOCOL_PKCS7_SIGNATURE).setMICAlgImportance(DispositionOptions.IMPORTANCE_OPTIONAL).setMICAlg(ECryptoAlgorithmSign.DIGEST_SHA_1).getAsString());
aPartnership.setAttribute(CPartnershipIDs.PA_ENCRYPT, ECryptoAlgorithmCrypt.CRYPT_3DES.getID());
aPartnership.setAttribute(CPartnershipIDs.PA_SIGN, ECryptoAlgorithmSign.DIGEST_SHA_1.getID());
aPartnership.setAttribute(CPartnershipIDs.PA_PROTOCOL, AS2Message.PROTOCOL_AS2);
aPartnership.setAttribute(CPartnershipIDs.PA_AS2_RECEIPT_DELIVERY_OPTION, null);
s_aLogger.info("ALIAS: " + aPartnership.getSenderX509Alias());
final IMessage aMsg = new AS2Message();
aMsg.setContentType("application/xml");
aMsg.setSubject("some subject");
aMsg.attrs().putIn(CPartnershipIDs.PA_AS2_URL, paAs2Url);
aMsg.attrs().putIn(CPartnershipIDs.PID_AS2, pidAs2);
aMsg.attrs().putIn(CPartnershipIDs.PID_EMAIL, "email");
MimeBodyPart aBodyPart;
// part = new MimeBodyPart(new FileInputStream("/tmp/tst"));
aBodyPart = new MimeBodyPart();
aBodyPart.setText("some text from mme part");
// part.setFileName("/");
aMsg.setData(aBodyPart);
aMsg.setPartnership(aPartnership);
aMsg.setMessageID(aMsg.generateMessageID());
s_aLogger.info("msg id: " + aMsg.getMessageID());
final AS2Session aSession = new AS2Session();
final CertificateFactory aCertFactory = new CertificateFactory();
/*
* filename="%home%/certs.p12" password="test" interval="300"
*/
// String filename =
// "/Users/oleo/samples/parfum.spb.ru/as2/openas2/config/certs.p12";
final String filename = "/Users/oleo/samples/parfum.spb.ru/as2/mendelson/certificates.p12";
// String filename =
// "/Users/oleo/samples/parfum.spb.ru/as2/test/test.p12";
final String password = "test";
// gwtestfm2i
// /Users/oleo/Downloads/portecle-1.5.zip
// /Users/oleo/samples/parfum.spb.ru/as2/test/test.p12
final StringMap aCertFactorySettings = new StringMap();
aCertFactorySettings.putIn(CertificateFactory.ATTR_TYPE, EKeyStoreType.PKCS12.getID());
aCertFactorySettings.putIn(CertificateFactory.ATTR_FILENAME, filename);
aCertFactorySettings.putIn(CertificateFactory.ATTR_PASSWORD, password);
aCertFactory.initDynamicComponent(aSession, aCertFactorySettings);
// logger.info(cf.getCertificate(msg.getMDN(), Partnership.PTYPE_SENDER));
// logger.info(cf.getCertificates());
aSession.setCertificateFactory(aCertFactory);
final SelfFillingPartnershipFactory aPartnershipFactory = new SelfFillingPartnershipFactory();
aSession.setPartnershipFactory(aPartnershipFactory);
aTestSender.initDynamicComponent(aSession, null);
s_aLogger.info("is requesting MDN?: " + aMsg.isRequestingMDN());
s_aLogger.info("is async MDN?: " + aMsg.isRequestingAsynchMDN());
s_aLogger.info("is rule to receive MDN active?: " + aMsg.partnership().getAS2ReceiptDeliveryOption());
aTestSender.handle(IProcessorSenderModule.DO_SEND, aMsg, null);
s_aLogger.info("MDN is " + aMsg.getMDN().toString());
s_aLogger.info("message sent" + aMsg.getLoggingText());
final IMessageMDN reply = aMsg.getMDN();
if (false)
s_aLogger.info("MDN headers:\n" + reply.headers().toString());
final Enumeration<Header> list2 = reply.getData().getAllHeaders();
final StringBuilder aSB2 = new StringBuilder("Mime headers:\n");
while (list2.hasMoreElements()) {
final Header aHeader = list2.nextElement();
aSB2.append(aHeader.getName()).append(" = ").append(aHeader.getValue()).append('\n');
}
// logger.info(sb2);
// logger.info(reply.getData().getRawInputStream().toString());
}
Aggregations