Skip to content

Instantly share code, notes, and snippets.

@robmadden
robmadden / onmessage.java
Last active December 28, 2015 21:59
ActivemMQ Java onMessage
@Override public void onMessage(Message msg) {
if (msg instanceof BytesMessage) {
BytesMessage bMsg = (BytesMessage) msg;
StringBuilder buffer = new StringBuilder();
try {
for (int i = 0; i < (int)bMsg.getBodyLength(); i++) {
buffer.append((char) bMsg.readByte());
}
} catch (JMSException e) {
@robmadden
robmadden / activemq_client
Created November 20, 2013 18:43
ActiveMQ Client
SERVER1 = 'X.X.X.X' SERVER2 = 'X.X.X.X' PORT = XXXXX client = PublishClient(SERVER1, ACTIVEMQ_PORT)
ip_dest = '' activemq_ip = SERVER1
try: response = client.connect(USER, PASSWORD) activemq_ip = SERVER1 except Exception as e: client = PublishClient(SERVER2, PORT)
try: response = client.connect(USER, PASSWORD) activemq_ip = SERVER2 except Exception as e: if (mq_params['count'] == 0):
print "Could not connect to activemq." time.sleep(3) mq_params['count'] += 1 self.send(mq_params)
@robmadden
robmadden / CustomSSLSocketFactory
Created September 19, 2013 14:18
Custom SSL Socket Factory
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import org.apache.http.conn.ssl.SSLSocketFactory;
@robmadden
robmadden / LoopjCertExample
Last active December 23, 2015 10:49
Loopj cert example
AsyncHttpClient client = new AsyncHttpClient();
if (MainActivity.DEVELOPER_MODE) {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
final SSLSocketFactory sf = CustomSSLSocketFactory.getSSLSocketFactory(context);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
client.setSSLSocketFactory(sf);
} catch (final Exception e) {
@robmadden
robmadden / NukeSSLCerts
Created September 19, 2013 14:15
Nuke SSL Certs
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;