1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.impl.nio.conn;
29
30 import java.net.InetAddress;
31
32 import org.apache.http.HttpException;
33 import org.apache.http.HttpHost;
34 import org.apache.http.HttpRequest;
35 import org.apache.http.client.protocol.ClientContext;
36 import org.apache.http.conn.params.ConnRouteParams;
37 import org.apache.http.conn.routing.HttpRoute;
38 import org.apache.http.conn.routing.HttpRoutePlanner;
39 import org.apache.http.nio.conn.scheme.AsyncScheme;
40 import org.apache.http.nio.conn.scheme.AsyncSchemeRegistry;
41 import org.apache.http.nio.conn.scheme.LayeringStrategy;
42 import org.apache.http.protocol.HttpContext;
43
44 @Deprecated
45 public class DefaultHttpAsyncRoutePlanner implements HttpRoutePlanner {
46
47 private final AsyncSchemeRegistry schemeRegistry;
48
49 public DefaultHttpAsyncRoutePlanner(final AsyncSchemeRegistry schemeRegistry) {
50 super();
51 this.schemeRegistry = schemeRegistry;
52 }
53
54 private AsyncSchemeRegistry getSchemeRegistry(final HttpContext context) {
55 AsyncSchemeRegistry reg = (AsyncSchemeRegistry) context.getAttribute(
56 ClientContext.SCHEME_REGISTRY);
57 if (reg == null) {
58 reg = this.schemeRegistry;
59 }
60 return reg;
61 }
62
63 @Override
64 public HttpRoute determineRoute(
65 final HttpHost target,
66 final HttpRequest request,
67 final HttpContext context) throws HttpException {
68 if (request == null) {
69 throw new IllegalStateException("Request may not be null");
70 }
71 HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
72 if (route != null) {
73 return route;
74 }
75 if (target == null) {
76 throw new IllegalStateException("Target host may be null");
77 }
78 final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
79 final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams());
80 final AsyncScheme scheme;
81 try {
82 final AsyncSchemeRegistry registry = getSchemeRegistry(context);
83 scheme = registry.getScheme(target);
84 } catch (final IllegalStateException ex) {
85 throw new HttpException(ex.getMessage());
86 }
87 final LayeringStrategy layeringStrategy = scheme.getLayeringStrategy();
88 final boolean secure = layeringStrategy != null && layeringStrategy.isSecure();
89 if (proxy == null) {
90 route = new HttpRoute(target, local, secure);
91 } else {
92 route = new HttpRoute(target, local, proxy, secure);
93 }
94 return route;
95 }
96
97 }