1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.http; |
19 |
|
|
20 |
|
import java.net.URI; |
21 |
|
import java.net.URISyntaxException; |
22 |
|
|
23 |
|
import javax.servlet.http.HttpServletRequest; |
24 |
|
import javax.servlet.http.HttpServletResponse; |
25 |
|
|
26 |
|
import org.apache.camel.Consumer; |
27 |
|
import org.apache.camel.Processor; |
28 |
|
import org.apache.camel.Producer; |
29 |
|
import org.apache.camel.RuntimeCamelException; |
30 |
|
import org.apache.camel.impl.DefaultEndpoint; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
2 |
public class HttpEndpoint extends DefaultEndpoint<HttpExchange> { |
38 |
|
|
39 |
|
private HttpBinding binding; |
40 |
|
private HttpComponent component; |
41 |
|
private URI httpUri; |
42 |
|
|
43 |
|
protected HttpEndpoint(String uri, HttpComponent component) throws URISyntaxException { |
44 |
2 |
super(uri, component); |
45 |
2 |
this.component = component; |
46 |
2 |
this.httpUri = new URI(uri); |
47 |
2 |
} |
48 |
|
|
49 |
|
public HttpProducer createProducer() throws Exception { |
50 |
1 |
return new HttpProducer(this); |
51 |
|
} |
52 |
|
|
53 |
|
public Consumer<HttpExchange> createConsumer(Processor processor) throws Exception { |
54 |
2 |
return new HttpConsumer(this, processor); |
55 |
|
} |
56 |
|
|
57 |
|
public HttpExchange createExchange() { |
58 |
1 |
return new HttpExchange(this); |
59 |
|
} |
60 |
|
|
61 |
|
public HttpExchange createExchange(HttpServletRequest request, HttpServletResponse response) { |
62 |
0 |
return new HttpExchange(this, request, response); |
63 |
|
} |
64 |
|
|
65 |
|
public HttpBinding getBinding() { |
66 |
4 |
if (binding == null) { |
67 |
2 |
binding = new HttpBinding(); |
68 |
|
} |
69 |
4 |
return binding; |
70 |
|
} |
71 |
|
|
72 |
|
public void setBinding(HttpBinding binding) { |
73 |
0 |
this.binding = binding; |
74 |
0 |
} |
75 |
|
|
76 |
|
public boolean isSingleton() { |
77 |
2 |
return true; |
78 |
|
} |
79 |
|
|
80 |
|
public void connect(HttpConsumer consumer) throws Exception { |
81 |
2 |
component.connect(consumer); |
82 |
2 |
} |
83 |
|
|
84 |
|
public void disconnect(HttpConsumer consumer) throws Exception { |
85 |
2 |
component.disconnect(consumer); |
86 |
2 |
} |
87 |
|
|
88 |
|
public String getPath() { |
89 |
4 |
return httpUri.getPath(); |
90 |
|
} |
91 |
|
|
92 |
|
public int getPort() { |
93 |
6 |
if( httpUri.getPort() == -1 ) { |
94 |
0 |
if( "https".equals(getProtocol() ) ) { |
95 |
0 |
return 443; |
96 |
|
} else { |
97 |
0 |
return 80; |
98 |
|
} |
99 |
|
} |
100 |
6 |
return httpUri.getPort(); |
101 |
|
} |
102 |
|
|
103 |
|
public String getProtocol() { |
104 |
6 |
return httpUri.getScheme(); |
105 |
|
} |
106 |
|
} |