@Override public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse) { try { final HttpHeaders headers = httpResponse.headers(); manager.put(uri, Maps.asMap(headers.names(), headers::getAll)); return delegate.handleResponse(httpResponse); } catch (IOException e) { LOG.error("Error while processing Cookies from header", e); throw new RuntimeException(e); } }
@Override public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse, TrafficCop trafficCop) { try { final HttpHeaders headers = httpResponse.headers(); manager.put(uri, Maps.asMap(headers.names(), new Function<String, List<String>>() { @Override public List<String> apply(String input) { return headers.getAll(input); } })); } catch (IOException e) { log.error(e, "Error while processing Cookies from header"); } finally { return delegate.handleResponse(httpResponse, trafficCop); } }
@Override public Set<String> keySet() { return httpHeaders.names(); }
@Override public int size() { return httpHeaders.names().size(); }
@Override public boolean containsValue(Object value) { return value instanceof List && httpHeaders.names().stream().map(httpHeaders::getAll).anyMatch(value::equals); }
@Override public Set<Entry<String, List<String>>> entrySet() { return httpHeaders.names().stream() .map(k -> new AbstractMap.SimpleImmutableEntry<>(k, httpHeaders.getAll(k))).collect(Collectors.toSet()); } }
@Override public Collection<List<String>> values() { return httpHeaders.names().stream().map(k -> Collections.unmodifiableList(httpHeaders.getAll(k))).collect(Collectors.toList()); }
protected static Map<String, Http.Header> getHeaders(HttpRequest nettyRequest) { Map<String, Http.Header> headers = new HashMap<>(16); for (String key : nettyRequest.headers().names()) { Http.Header hd = new Http.Header(); hd.name = key.toLowerCase(); hd.values = new ArrayList<>(); for (String next : nettyRequest.headers().getAll(key)) { hd.values.add(next); } headers.put(hd.name, hd); } return headers; }
@Override public void populateCamelHeaders(HttpResponse response, Map<String, Object> headers, Exchange exchange, NettyHttpConfiguration configuration) throws Exception { LOG.trace("populateCamelHeaders: {}", response); headers.put(Exchange.HTTP_RESPONSE_CODE, response.getStatus().getCode()); headers.put(Exchange.HTTP_RESPONSE_TEXT, response.getStatus().getReasonPhrase()); for (String name : response.headers().names()) { // mapping the content-type if (name.toLowerCase().equals("content-type")) { name = Exchange.CONTENT_TYPE; } // add the headers one by one, and use the header filter strategy List<String> values = response.headers().getAll(name); Iterator<?> it = ObjectHelper.createIterator(values); while (it.hasNext()) { Object extracted = it.next(); LOG.trace("HTTP-header: {}", extracted); if (headerFilterStrategy != null && !headerFilterStrategy.applyFilterToExternalHeaders(name, extracted, exchange)) { NettyHttpHelper.appendHeader(headers, name, extracted); } } } }
for (String name : request.headers().names()) {
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { org.jboss.netty.handler.codec.http.HttpRequest nettyRequest = (org.jboss.netty.handler.codec.http.HttpRequest) e.getMessage(); // convert request to our internal request Map<String,List<String>> headers = new HashMap<String,List<String>>(); for (String headerName : nettyRequest.headers().names()) { headers.put(headerName,nettyRequest.headers().getAll(headerName)); } // see if we have a body byte[] content = null; if(nettyRequest.getContent().hasArray() && nettyRequest.getContent().array().length > 0) { content = nettyRequest.getContent().array(); } else if(nettyRequest.getContent().readableBytes() > 0) { // netty content not backed by array, need to copy content = new byte[nettyRequest.getContent().readableBytes()]; nettyRequest.getContent().readBytes(content); } HttpRequest request = new HttpRequest(nettyRequest.getMethod().getName(),new URI(nettyRequest.getUri()).getPath(),headers,content); // create a temp actor to handle the response ActorRef replyActor = actorSystem.tempActorOf(HttpServiceResponseHandler.class, new HttpServiceResponseHandler.State(ctx.getChannel())); // put the actor in the attachment to propagate disconnects ctx.setAttachment(replyActor); // async handling if(!httpService.doDispatch(request,replyActor)) { // send 404 ctx.getChannel().write(new DefaultHttpResponse(HttpVersion.HTTP_1_1,HttpResponseStatus.NOT_FOUND)).addListener(ChannelFutureListener.CLOSE); actorSystem.stop(replyActor); } }