/** * @return the thread-local api response */ public static final ApiResponse getApiResponse() { ApiResponse response = apiResponse.get(); if (response == null) { response = new ApiResponse(); apiResponse.set(response); } response.setCode(0); response.getHeaders().clear(); response.setMessage(null); response.getAttributes().clear(); return response; }
/** * @return the thread-local api response */ public static final ApiResponse getApiResponse() { ApiResponse response = apiResponse.get(); if (response == null) { response = new ApiResponse(); apiResponse.set(response); } response.setCode(0); response.getHeaders().clear(); response.setMessage(null); response.getAttributes().clear(); return response; }
/** * @see io.apiman.gateway.engine.io.IWriteStream#end() */ @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() */ @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); } }
public static ApiResponse buildResponse(HttpClientResponse response, Set<String> suppressHeaders) { ApiResponse apimanResponse = new ApiResponse(); apimanResponse.setCode(response.statusCode()); apimanResponse.setMessage(response.statusMessage() == null ? "" : response.statusMessage()); multimapToMap(apimanResponse.getHeaders(), response.headers(), suppressHeaders); return apimanResponse; }