Search in sources :

Example 1 with IMessage

use of com.helger.as2lib.message.IMessage 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());
}
Also used : AS2SenderModule(com.helger.as2lib.processor.sender.AS2SenderModule) StringMap(com.helger.commons.collection.attr.StringMap) DispositionOptions(com.helger.as2lib.disposition.DispositionOptions) IMessage(com.helger.as2lib.message.IMessage) CertificateFactory(com.helger.as2lib.cert.CertificateFactory) AS2Session(com.helger.as2lib.session.AS2Session) AS2Message(com.helger.as2lib.message.AS2Message) Partnership(com.helger.as2lib.partner.Partnership) CHttpHeader(com.helger.commons.http.CHttpHeader) CAS2Header(com.helger.as2lib.util.CAS2Header) Header(javax.mail.Header) IMessageMDN(com.helger.as2lib.message.IMessageMDN) MimeBodyPart(javax.mail.internet.MimeBodyPart) SelfFillingPartnershipFactory(com.helger.as2lib.partner.SelfFillingPartnershipFactory)

Aggregations

CertificateFactory (com.helger.as2lib.cert.CertificateFactory)1 DispositionOptions (com.helger.as2lib.disposition.DispositionOptions)1 AS2Message (com.helger.as2lib.message.AS2Message)1 IMessage (com.helger.as2lib.message.IMessage)1 IMessageMDN (com.helger.as2lib.message.IMessageMDN)1 Partnership (com.helger.as2lib.partner.Partnership)1 SelfFillingPartnershipFactory (com.helger.as2lib.partner.SelfFillingPartnershipFactory)1 AS2SenderModule (com.helger.as2lib.processor.sender.AS2SenderModule)1 AS2Session (com.helger.as2lib.session.AS2Session)1 CAS2Header (com.helger.as2lib.util.CAS2Header)1 StringMap (com.helger.commons.collection.attr.StringMap)1 CHttpHeader (com.helger.commons.http.CHttpHeader)1 Header (javax.mail.Header)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1