Search in sources :

Example 1 with StringMap

use of com.helger.commons.collection.attr.StringMap in project ph-css by phax.

the class CSSURLHelperTest method testGetAsCSSURL.

@Test
public void testGetAsCSSURL() {
    for (final String sURL : new String[] { "a.gif", "\"a.gif\"", "b\\a.gif", "\\b\\a\\c.gif", "'a.gif'", "'a\".gif'", "\"a'.gif\"", "a().gif", "a\\(\\).gif" }) {
        final String sEscaped = CSSURLHelper.getAsCSSURL(sURL, false);
        assertEquals(sURL, CSSParseHelper.trimUrl(sEscaped));
    }
    assertEquals("url(a.gif)", CSSURLHelper.getAsCSSURL("a.gif", false));
    // By default: single quotes
    assertEquals("url('a.gif')", CSSURLHelper.getAsCSSURL("a.gif", true));
    // Force single quotes
    assertEquals("url('\"a.gif\"')", CSSURLHelper.getAsCSSURL("\"a.gif\"", true));
    // auto-quote
    assertEquals("url('\"a.gif\"')", CSSURLHelper.getAsCSSURL("\"a.gif\"", false));
    // auto-quote
    assertEquals("url('b\\\\a.gif')", CSSURLHelper.getAsCSSURL("b\\a.gif", false));
    // Force double quotes
    assertEquals("url(\"'a.gif'\")", CSSURLHelper.getAsCSSURL("'a.gif'", true));
    // auto-quote
    assertEquals("url(\"'a.gif'\")", CSSURLHelper.getAsCSSURL("'a.gif'", false));
    // Containing char to be escaped
    assertEquals("url('\\'a\".gif\\'')", CSSURLHelper.getAsCSSURL("'a\".gif'", true));
    // auto-quote
    assertEquals("url('\\'a\".gif\\'')", CSSURLHelper.getAsCSSURL("'a\".gif'", false));
    // Containing char to be escaped
    assertEquals("url('\"a\\'.gif\"')", CSSURLHelper.getAsCSSURL("\"a'.gif\"", true));
    // auto-quote
    assertEquals("url('\"a\\'.gif\"')", CSSURLHelper.getAsCSSURL("\"a'.gif\"", false));
    // Escaped brackets
    assertEquals("url('a().gif')", CSSURLHelper.getAsCSSURL("a().gif", false));
    final SimpleURL aURL = new SimpleURL("a.gif", new StringMap("x", "y"));
    assertEquals("url(a.gif?x=y)", CSSURLHelper.getAsCSSURL(aURL, false));
    assertEquals("url('a.gif?x=y')", CSSURLHelper.getAsCSSURL(aURL, true));
    assertEquals("url()", CSSURLHelper.getAsCSSURL(new SimpleURL(), false));
    assertEquals("url('')", CSSURLHelper.getAsCSSURL(new SimpleURL(), true));
    // SimpleURL -> CSS URL -> String -> SimpleURL
    assertEquals(aURL, new SimpleURL(CSSURLHelper.getURLValue(CSSURLHelper.getAsCSSURL(aURL, true))));
    // empty URL!
    assertEquals("url()", CSSURLHelper.getAsCSSURL("", false));
    assertEquals("url('')", CSSURLHelper.getAsCSSURL("", true));
}
Also used : StringMap(com.helger.commons.collection.attr.StringMap) SimpleURL(com.helger.commons.url.SimpleURL) Test(org.junit.Test)

Example 2 with StringMap

use of com.helger.commons.collection.attr.StringMap in project as2-server by phax.

the class SocketCommandProcessor method initDynamicComponent.

@Override
public void initDynamicComponent(@Nonnull final IAS2Session aSession, @Nullable final IStringMap aParams) throws OpenAS2Exception {
    final StringMap aParameters = aParams == null ? new StringMap() : new StringMap(aParams);
    final String sPort = aParameters.getAsString(ATTR_PORTID);
    try {
        final int nPort = Integer.parseInt(sPort);
        final SSLServerSocketFactory aSSLServerSocketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
        m_aSSLServerSocket = (SSLServerSocket) aSSLServerSocketFactory.createServerSocket(nPort);
        final String[] aEnabledCipherSuites = getEnabledAnonymousCipherSuites(m_aSSLServerSocket.getEnabledCipherSuites(), m_aSSLServerSocket.getSupportedCipherSuites());
        m_aSSLServerSocket.setEnabledCipherSuites(aEnabledCipherSuites);
    } catch (final IOException e) {
        throw new OpenAS2Exception(e);
    } catch (final NumberFormatException e) {
        throw new OpenAS2Exception("Error converting portid parameter '" + sPort + "': " + e);
    }
    m_sUserID = aParameters.getAsString(ATTR_USERID);
    if (StringHelper.hasNoText(m_sUserID))
        throw new OpenAS2Exception("missing 'userid' parameter");
    m_sPassword = aParameters.getAsString(ATTR_PASSWORD);
    if (StringHelper.hasNoText(m_sPassword))
        throw new OpenAS2Exception("missing 'password' parameter");
    try {
        m_aParser = new SocketCommandParser();
    } catch (final Exception e) {
        throw new OpenAS2Exception(e);
    }
}
Also used : StringMap(com.helger.commons.collection.attr.StringMap) IStringMap(com.helger.commons.collection.attr.IStringMap) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) IOException(java.io.IOException) IOException(java.io.IOException) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception)

Example 3 with StringMap

use of com.helger.commons.collection.attr.StringMap 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

StringMap (com.helger.commons.collection.attr.StringMap)3 CertificateFactory (com.helger.as2lib.cert.CertificateFactory)1 DispositionOptions (com.helger.as2lib.disposition.DispositionOptions)1 OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)1 WrappedOpenAS2Exception (com.helger.as2lib.exception.WrappedOpenAS2Exception)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 IStringMap (com.helger.commons.collection.attr.IStringMap)1 CHttpHeader (com.helger.commons.http.CHttpHeader)1 SimpleURL (com.helger.commons.url.SimpleURL)1 IOException (java.io.IOException)1 Header (javax.mail.Header)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)1