List of usage examples for javax.net.ssl SSLSocket getInputStream
public InputStream getInputStream() throws IOException
From source file:org.kuali.mobility.push.dao.PushDaoImpl.java
@SuppressWarnings("unchecked") private boolean sendPushToIOS(Push push, Device device, SSLSocket socket) { String payload = preparePayload(push); LOG.info("Push: " + push); LOG.info("Device: " + device); String token = device.getRegId(); try {/*from w ww. ja v a 2 s. c o m*/ char[] t = token.toCharArray(); byte[] b = Hex.decodeHex(t); ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Command Byte. baos.write(0); // Device ID Length baos.write(0); baos.write(32); // Device ID baos.write(b); // Payload Length baos.write(0); baos.write(payload.length()); // Payload baos.write(payload.getBytes()); LOG.info("Payload: Final size: " + baos.size()); if (socket != null) { OutputStream out = socket.getOutputStream(); InputStream in = socket.getInputStream(); out.write(baos.toByteArray()); out.flush(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } return true; }
From source file:com.isecpartners.gizmo.HttpRequest.java
public boolean fetchResponse(boolean cached) { this.cached = cached; OutputStream out = null;//from w ww.ja va 2 s. c o m BufferedReader strBr = null; try { if (cached) { strBr = new BufferedReader(new StringReader(this.interrimContents.toString())); } removeLine("PROXY-CONNECTION", workingContents); updateContentLength(); if (mk_header(workingContents).contains("CONNECT") && !this.connect_protocol_handled) { handle_connect_protocol(); if (!GizmoView.getView().config().terminateSSL()) { this.passthroughssl = true; return false; } } if (isSSL || this.sock instanceof SSLSocket) { SSLSocket sslSock = (SSLSocket) this.sock; SSLSocket sslOut = null; if (workingContents == null) { return false; } if (workingContents.indexOf("\r\n") == -1) { return false; } if (!this.override_host) host = rewriteMethodLine(workingContents); if (!user_defined_port) { port = 443; } if (outboundSock == null || (!(outboundSock instanceof SSLSocket))) { SSLSocketFactory sslsocketfactory = sloppySSL(); sslOut = (SSLSocket) sslsocketfactory.createSocket(host, port); } else { sslOut = (SSLSocket) outboundSock; } sslOut.getOutputStream().write(workingContents.toString().getBytes()); this.resp = HttpResponse.create(sslOut.getInputStream()); if (resp == null) { return false; } } else { //if (!this.override_host) host = rewriteMethodLine(workingContents); outboundSock = new Socket(host, port); outboundSock.getOutputStream().write(workingContents.toString().getBytes()); this.resp = HttpResponse.create(outboundSock.getInputStream()); if (resp == null) { return false; } } this.addContents(workingContents.toString()); this.header = workingContents.substring(0, this.workingContents.indexOf("\r\n")); this.url = getUrlPath(header); this.version = getVersion(this.header); } catch (SocketException e) { Logger.getLogger(HttpRequest.class.getName()).log(Level.SEVERE, null, e); return false; } catch (javax.net.ssl.SSLHandshakeException e) { try { GizmoView.getView().setStatus("couldn't connect with ssl.. cert issues?"); sock.close(); } catch (IOException ex) { Logger.getLogger(HttpRequest.class.getName()).log(Level.SEVERE, null, ex); } return false; } catch (IOException ex) { Logger.getLogger(HttpRequest.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (FailedRequestException e) { GizmoView.getView().setStatus("malformed server response"); } catch (Exception e) { try { Logger.getLogger(HttpRequest.class.getName()).log(Level.SEVERE, null, e); GizmoView.getView().setStatus("couldn't connect"); this.sock.close(); return false; } catch (IOException ex) { Logger.getLogger(HttpRequest.class.getName()).log(Level.SEVERE, null, ex); } } this.wakeupAndSend(); resp.setRequest(this); return true; }