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 public HttpRoute determineRoute(
64 final HttpHost target,
65 final HttpRequest request,
66 final HttpContext context) throws HttpException {
67 if (request == null) {
68 throw new IllegalStateException("Request may not be null");
69 }
70 HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
71 if (route != null) {
72 return route;
73 }
74 if (target == null) {
75 throw new IllegalStateException("Target host may be null");
76 }
77 final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
78 final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams());
79 AsyncScheme scheme;
80 try {
81 final AsyncSchemeRegistry registry = getSchemeRegistry(context);
82 scheme = registry.getScheme(target);
83 } catch (final IllegalStateException ex) {
84 throw new HttpException(ex.getMessage());
85 }
86 final LayeringStrategy layeringStrategy = scheme.getLayeringStrategy();
87 final boolean secure = layeringStrategy != null && layeringStrategy.isSecure();
88 if (proxy == null) {
89 route = new HttpRoute(target, local, secure);
90 } else {
91 route = new HttpRoute(target, local, proxy, secure);
92 }
93 return route;
94 }
95
96 }