use of javax.net.ssl.SSLHandshakeException in project java-apns by notnoop.
the class ApnsConnectionImpl method sendMessage.
private synchronized void sendMessage(ApnsNotification m, boolean fromBuffer) throws NetworkIOException {
logger.debug("sendMessage {} fromBuffer: {}", m, fromBuffer);
if (delegate instanceof StartSendingApnsDelegate) {
((StartSendingApnsDelegate) delegate).startSending(m, fromBuffer);
}
int attempts = 0;
while (true) {
try {
attempts++;
Socket socket = getOrCreateSocket(fromBuffer);
socket.getOutputStream().write(m.marshall());
socket.getOutputStream().flush();
cacheNotification(m);
delegate.messageSent(m, fromBuffer);
//logger.debug("Message \"{}\" sent", m);
attempts = 0;
break;
} catch (SSLHandshakeException e) {
// No use retrying this, it's dead Jim
throw new NetworkIOException(e);
} catch (IOException e) {
Utilities.close(socket);
if (attempts >= RETRIES) {
logger.error("Couldn't send message after " + RETRIES + " retries." + m, e);
delegate.messageSendFailed(m, e);
Utilities.wrapAndThrowAsRuntimeException(e);
}
if (attempts != 1) {
logger.info("Failed to send message " + m + "... trying again after delay", e);
Utilities.sleep(DELAY_IN_MS);
}
}
}
}
use of javax.net.ssl.SSLHandshakeException in project robovm by robovm.
the class URLConnectionTest method testConnectViaHttpProxyToHttpsUsingBadProxyAndHttpResponseCache.
/**
* Tolerate bad https proxy response when using HttpResponseCache. http://b/6754912
*/
public void testConnectViaHttpProxyToHttpsUsingBadProxyAndHttpResponseCache() throws Exception {
ProxyConfig proxyConfig = ProxyConfig.PROXY_SYSTEM_PROPERTY;
TestSSLContext testSSLContext = TestSSLContext.create();
initResponseCache();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
MockResponse badProxyResponse = new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders().setBody(// Key to reproducing b/6754912
"bogus proxy connect response content");
// We enqueue the bad response twice because the connection will
// be retried with TLS_MODE_COMPATIBLE after the first connection
// fails.
server.enqueue(badProxyResponse);
server.enqueue(badProxyResponse);
server.play();
URL url = new URL("https://android.com/foo");
HttpsURLConnection connection = (HttpsURLConnection) proxyConfig.connect(server, url);
connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
try {
connection.connect();
fail();
} catch (SSLHandshakeException expected) {
// Thrown when the connect causes SSLSocket.startHandshake() to throw
// when it sees the "bogus proxy connect response content"
// instead of a ServerHello handshake message.
}
RecordedRequest connect = server.takeRequest();
assertEquals("Connect line failure on proxy", "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertContains(connect.getHeaders(), "Host: android.com");
}
use of javax.net.ssl.SSLHandshakeException in project robovm by robovm.
the class HandshakeIODataStream method append.
private void append(byte[] src, int from, int length) {
if (read_pos == read_pos_end) {
// start reading state after writing
if (write_pos_beg != write_pos) {
// but inbound handshake data has been received.
throw new AlertException(AlertProtocol.UNEXPECTED_MESSAGE, new SSLHandshakeException("Handshake message has been received before " + "the last oubound message had been sent."));
}
if (read_pos < write_pos) {
read_pos = write_pos;
read_pos_end = read_pos;
}
}
if (read_pos_end + length > buff_size) {
enlargeBuffer(read_pos_end + length - buff_size);
}
System.arraycopy(src, from, buffer, read_pos_end, length);
read_pos_end += length;
}
use of javax.net.ssl.SSLHandshakeException in project robovm by robovm.
the class HandshakeIODataStream method check.
// checks if the data can be written in the buffer
private void check(int length) {
// 2. all written data was demanded by getData methods
if (write_pos == write_pos_beg) {
// just started to write after the reading
if (read_pos != read_pos_end) {
// all the inbound handshake data had been read
throw new AlertException(AlertProtocol.INTERNAL_ERROR, new SSLHandshakeException("Data was not fully read: " + read_pos + " " + read_pos_end));
}
// set up the write positions
if (write_pos_beg < read_pos_end) {
write_pos_beg = read_pos_end;
write_pos = write_pos_beg;
}
}
// if there is not enought free space in the buffer - enlarge it:
if (write_pos + length >= buff_size) {
enlargeBuffer(length);
}
}
use of javax.net.ssl.SSLHandshakeException in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_setUseClientMode.
private void test_SSLSocket_setUseClientMode(final boolean clientClientMode, final boolean serverClientMode) throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<IOException> future = executor.submit(new Callable<IOException>() {
@Override
public IOException call() throws Exception {
try {
if (!serverClientMode) {
server.setSoTimeout(1 * 1000);
}
server.setUseClientMode(serverClientMode);
server.startHandshake();
return null;
} catch (SSLHandshakeException e) {
return e;
} catch (SocketTimeoutException e) {
return e;
}
}
});
executor.shutdown();
if (!clientClientMode) {
client.setSoTimeout(1 * 1000);
}
client.setUseClientMode(clientClientMode);
client.startHandshake();
IOException ioe = future.get();
if (ioe != null) {
throw ioe;
}
client.close();
server.close();
c.close();
}
Aggregations