InputStream inputStream = response.getResponseStream(); try { IOUtils.copy(inputStream, buff); response.dispose();
public Response(HTTPResponse httpResponse) throws ServiceException, IOException { if (httpResponse.getResponseStream() == null) { throw new NullPointerException( "An inputStream is required for " + getClass().getName()); } if (httpResponse.getContentType() == null) { // should missing content type be fatal? Or could we make an assumption? // in case of exception, we have to dispose the response, as it might // be using a deflate input stream, which holds onto native resources httpResponse.getResponseStream().close(); httpResponse.dispose(); throw new NullPointerException("Content type is required for " + getClass().getName()); } this.httpResponse = httpResponse; /* * Intercept XML ServiceExceptions and throw them */ if (httpResponse.getContentType().toLowerCase().equals("application/vnd.ogc.se_xml")) { try { throw parseException(httpResponse.getResponseStream()); } finally { dispose(); } } }
/** * @throws IOException * @throws ServiceException */ public WFSResponse(WFSRequest originatingRequest, final HTTPResponse httpResponse) throws ServiceException, IOException { super(httpResponse); this.request = originatingRequest; String charset = httpResponse.getResponseHeader("Charset"); if (charset == null) { this.charset = Charset.forName("UTF-8"); } else { try { this.charset = Charset.forName(charset); } catch (Exception e) { // TODO log this.charset = Charset.forName("UTF-8"); } } this.contentType = httpResponse.getContentType(); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("WFS response: charset=" + charset + ", contentType=" + contentType); } }
@Override public void dispose() { delegate.dispose(); }
@Override public WFSResponse createResponse(HTTPResponse response) throws IOException { final String contentType = response.getContentType(); if (contentType == null) { Logging.getLogger(WFSRequest.class) .warning( this.getOperation() + " request returned null content type for URL " + getFinalURL()); } WFSResponseFactory responseFactory; try { responseFactory = WFSExtensions.findResponseFactory(this, contentType); } catch (FactoryNotFoundException fnf) { Loggers.MODULE.log(Level.WARNING, fnf.getMessage()); try { if (contentType != null && contentType.startsWith("text")) { byte buff[] = new byte[1024]; response.getResponseStream().read(buff); Loggers.MODULE.info("Failed response snippet: " + new String(buff)); } throw fnf; } catch (Exception ignore) { throw fnf; } } WFSResponse wfsResponse = responseFactory.createResponse(this, response); return wfsResponse; }
new PushbackInputStream(response.getResponseStream(), buffSize); byte[] buff = new byte[buffSize]; int readCount = 0; String charset = response.getResponseHeader("Charset"); try { Charset.forName(charset);
@Override public InputStream getResponseStream() throws IOException { return delegate.getResponseStream(); }
@Override public String getContentType() { return delegate.getContentType(); }
@Override public String getResponseHeader(String headerName) { return delegate.getResponseHeader(headerName); }
@Override public String getResponseCharset() { return delegate.getResponseCharset(); } }
public void dispose() { httpResponse.dispose(); }
public Response(HTTPResponse httpResponse) throws ServiceException, IOException { if( httpResponse.getResponseStream() == null ){ throw new NullPointerException("An inputStream is required for "+getClass().getName()); } if( httpResponse.getContentType() == null ){ // should missing content type be fatal? Or could we make an assumption? throw new NullPointerException("Content type is required for "+getClass().getName()); } this.httpResponse = httpResponse; /* * Intercept XML ServiceExceptions and throw them */ if (httpResponse.getContentType().toLowerCase().equals("application/vnd.ogc.se_xml")) { try { throw parseException(httpResponse.getResponseStream()); } finally { dispose(); } } }
new PushbackInputStream(response.getResponseStream(), buffSize); byte[] buff = new byte[buffSize]; int readCount = 0; String charset = response.getResponseHeader("Charset"); try { Charset.forName(charset);
/** * Returns the InputStream that contains the response from the server. The contents of this * stream vary according to the type of request that was made, and whether it was successful or * not. * * <p><B>NOTE:</B> Note that clients using this code are responsible for closing the InputStream * when they are finished with it. * * @return the input stream containing the response from the server */ public InputStream getInputStream() { try { return httpResponse.getResponseStream(); } catch (IOException e) { throw new RuntimeException(e); } }
public String getContentType() { return httpResponse.getContentType(); }
InputStream inputStream = response.getResponseStream(); try { IOUtils.copy(inputStream, buff); response.dispose();
throw new IOException(e); } finally { response.dispose();
@Override public WFSResponse createResponse(HTTPResponse response) throws IOException { final String contentType = response.getContentType(); if (contentType == null) { Logging.getLogger(WFSRequest.class) .warning( this.getOperation() + " request returned null content type for URL " + getFinalURL()); } WFSResponseFactory responseFactory; try { responseFactory = WFSExtensions.findResponseFactory(this, contentType); } catch (FactoryNotFoundException fnf) { Loggers.MODULE.log(Level.WARNING, fnf.getMessage()); try { if (contentType != null && contentType.startsWith("text")) { byte buff[] = new byte[1024]; response.getResponseStream().read(buff); Loggers.MODULE.info("Failed response snippet: " + new String(buff)); } throw fnf; } catch (Exception ignore) { throw fnf; } } WFSResponse wfsResponse = responseFactory.createResponse(this, response); return wfsResponse; }
public LoggingHTTPResponse(HTTPResponse delegate, String charsetName) throws IOException { super(delegate); ByteArrayOutputStream output = new ByteArrayOutputStream(); LoggingHTTPClient.copy(delegate.getResponseStream(), output); LOGGER.finest("Response: \n" + output.toString(charsetName)); input = new ByteArrayInputStream(output.toByteArray()); }
/** * @throws IOException * @throws ServiceException */ public WFSResponse(WFSRequest originatingRequest, final HTTPResponse httpResponse) throws ServiceException, IOException { super(httpResponse); this.request = originatingRequest; String charset = httpResponse.getResponseHeader("Charset"); if (charset == null) { this.charset = Charset.forName("UTF-8"); } else { try { this.charset = Charset.forName(charset); } catch (Exception e) { // TODO log this.charset = Charset.forName("UTF-8"); } } this.contentType = httpResponse.getContentType(); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("WFS response: charset=" + charset + ", contentType=" + contentType); } }