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));
}
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);
}
}
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());
}
Aggregations