/** * Creates an OkHttp Response.Body containing the supplied information. */ private static ResponseBody createOkBody(final URLConnection urlConnection) throws IOException { if (!urlConnection.getDoInput()) { return null; } final BufferedSource body = Okio.buffer(Okio.source(urlConnection.getInputStream())); return new ResponseBody() { @Override public MediaType contentType() { String contentTypeHeader = urlConnection.getContentType(); return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader); } @Override public long contentLength() { String s = urlConnection.getHeaderField("Content-Length"); return stringToLong(s); } @Override public BufferedSource source() { return body; } }; }
@Override public boolean getDoInput() { return _conn.getDoInput(); }
public boolean getDoInput() { return connection.getDoInput(); }
public boolean getDoInput() { return delegateConnection.getDoInput(); }
public boolean getDoInput() { return connection.getDoInput(); }
/** * Tests whether the application can read the resource at the * specified {@link URL}. * * @return <CODE>true</CODE> if and only if the specified * {@link URL} points to a resource that exists <EM>and</EM> can be * read by the application; <CODE>false</CODE> otherwise. * * @param url URL to check if we can read from it. */ public boolean canRead(URL url) { try { final URLConnection urlConnection = url.openConnection(); return urlConnection.getDoInput(); } catch (Exception e) { return false; } }
/** * Creates an OkHttp Response.Body containing the supplied information. */ private static ResponseBody createOkBody(final URLConnection urlConnection) throws IOException { if (!urlConnection.getDoInput()) { return null; } final BufferedSource body = Okio.buffer(Okio.source(urlConnection.getInputStream())); return new ResponseBody() { @Override public MediaType contentType() { String contentTypeHeader = urlConnection.getContentType(); return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader); } @Override public long contentLength() { String s = urlConnection.getHeaderField("Content-Length"); return stringToLong(s); } @Override public BufferedSource source() { return body; } }; }
if (urlConnection.getDoInput()) { InputStream inputStream = null; try {
/** * Should be called when a <code>Connection</code> is used to do a POST (write to it's outputstream) * without reading it's inputstream (the response). Calling this will make sure the POST request is sent. * If no data was written to the connection nothing is done. */ public void close() { if (m_connection.getDoOutput()) { try { m_connection.getOutputStream().close(); } catch (IOException e) { // not much we can do } try { m_connection.getContent(); } catch (IOException e) { // not much we can do } } if (m_connection.getDoInput()) { try { m_connection.getInputStream().close(); } catch (IOException e) { // not much we can do } } } }
void serviceRequest(final PipeResponse response) throws IOException { if (!response.getURLConnection().getDoInput()) { try { Definition def = EndpointReferenceUtils.getWSDLDefinition(bus.getWSDLManager(), reference); Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>(); headers.put("Content-Type", Arrays.asList(new String[] {"text/xml"})); OutputStream out = response.setResponse(headers); bus.getWSDLManager().getWSDLFactory().newWSDLWriter().writeWSDL(def, out); out.flush(); out.close(); return; } catch (WSDLException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } } HTTPServerInputStreamContext ctx = new HTTPServerInputStreamContext(this) { public void initContext() throws IOException { super.initContext(); inStream = response.getRequestInputStream(); origInputStream = inStream; } }; ctx.put(PIPE_RESPONSE, response); ctx.initContext(); callback.dispatch(ctx, this); }
public void testUrlConnectionForEventData() throws IOException { final String eventData = "blahblahblah"; final URLConnection urlConnection = connectionProcessor.urlConnectionForEventData(eventData); assertEquals(30000, urlConnection.getConnectTimeout()); assertEquals(30000, urlConnection.getReadTimeout()); assertFalse(urlConnection.getUseCaches()); assertTrue(urlConnection.getDoInput()); assertFalse(urlConnection.getDoOutput()); assertEquals(new URL(connectionProcessor.getServerURL() + "/i?" + eventData + "&checksum=" + sha1Hash(eventData + null)), urlConnection.getURL()); }