@Override
    public void end() {
        try {
            IOUtils.closeQuietly(outputStream);
            if (isError) {
                return;
            } else if (!connected) {
                throw new IOException("Not connected."); //$NON-NLS-1$
            }
            outputStream = null;
            // Process the response, convert to an ApiResponse object, and return it
            response = GatewayThreadContext.getApiResponse();

            // Add headers
            for (Entry<String, List<String>> headerEntry : connection.getHeaderFields().entrySet()) {
                String headerName = headerEntry.getKey();
                List<String> headerValues = headerEntry.getValue();

                if (headerName != null && !connectorConfig.getSuppressedResponseHeaders().contains(headerName)) {
                    response.getHeaders().add(headerName, headerValues);
                }
            }

            response.setCode(connection.getResponseCode());
            response.setMessage(connection.getResponseMessage());
            responseHandler.handle(AsyncResultImpl.<IApiConnectionResponse> create(this));
        } catch (Exception e) {
            handleConnectionError(e);
        }
    }
@see io.apiman.gateway.engine.io.IWriteStream#end()
gateway/platforms/servlet/src/main/java/io/apiman/gateway/platforms/servlet/connectors/HttpApiConnection.java