@Override public String getParameter(String name) { if(parent.parameters().containsKey(name)) { return parent.parameters().get(name).get(0); } else { return null; } }
@Override public Enumeration<String> getParameterNames() { return Collections.enumeration(parent.parameters().keySet()); }
private static void setProperties(com.yahoo.jdisc.http.HttpRequest clientRequest, Map<String, String> properties) { if (properties == null) return; for (Map.Entry<String, String> entry : properties.entrySet()) { clientRequest.parameters().put(entry.getKey(), wrap(entry.getValue())); } }
private void setParameters( com.yahoo.jdisc.http.HttpRequest request) { for (Map.Entry<String, String> entry : properties.entrySet()) { request.parameters().put(entry.getKey(), wrap(entry.getValue())); } }
/** * Wrap a JDisc HTTP request in a synchronous API. The properties from the * JDisc request will be copied into the HTTP request. The mappings in * propertyOverrides will mask the settings in the JDisc request. The * content of propertyOverrides will be copied, so it is safe to re-use and * changes in propertyOverrides after constructing the HttpRequest instance * will obviously not be reflected by the request. The same applies for * JDisc parameters. * * @param jdiscHttpRequest * the JDisc request * @param requestData * the associated input stream, e.g. with POST request * @param propertyOverrides * properties which should not have the same settings as in the * parent JDisc request, may be null */ public HttpRequest(com.yahoo.jdisc.http.HttpRequest jdiscHttpRequest, InputStream requestData, Map<String, String> propertyOverrides) { parentRequest = jdiscHttpRequest; this.requestData = requestData; properties = copyProperties(jdiscHttpRequest.parameters(), propertyOverrides); }
@SuppressWarnings("try") @Override public void close(final CompletionHandler completionHandler) { try (final ResourceReference ref = requestReference) { final byte[] requestContentBytes = accumulatedRequestContent.toByteArray(); final String content = new String(requestContentBytes, contentCharset); completionHandler.completed(); final Map<String, List<String>> parameterMap = parseFormParameters(content); mergeParameters(parameterMap, request.parameters()); final ContentChannel contentChannel = delegateHandler.handleRequest(request, responseHandler); if (contentChannel != null) { if (!removeBody) { final ByteBuffer byteBuffer = ByteBuffer.wrap(requestContentBytes); contentChannel.write(byteBuffer, NOOP_COMPLETION_HANDLER); } contentChannel.close(NOOP_COMPLETION_HANDLER); } } }