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