358.8. HTTP/2 예
이 샘플에서는 HTTP/2 프로토콜을 지원하고 http://localhost:7766/foo/bar 에서 HTTP 서비스를 노출하도록 camel-undertow 구성 요소를 구성합니다.
이 샘플의 디렉터리 구조는 다음과 같습니다.
├── pom.xml ├── README.md └── src └── main └── resources └── META-INF └── spring └── camel-context.xml
├── pom.xml
├── README.md
└── src
└── main
└── resources
└── META-INF
└── spring
└── camel-context.xml
다음 파일은 HTTP/2 프로토콜을 지원하도록 camel-undertow 구성 요소를 구성하는 데 중요합니다.
- 1
- POM.xml: 다음 속성 및 종속 항목을 포함합니다.
<properties> <camel.version>2.23.1</camel.version> </properties> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-undertow</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-http-common</artifactId> <version>${camel.version}</version> </dependency> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-maven-plugin</artifactId> <version>${camel.version}</version> <configuration> <fileApplicationContextUri>src/main/resources/META-INF/spring/camel-context.xml</fileApplicationContextUri> </configuration> </plugin>
<properties> <camel.version>2.23.1</camel.version> </properties> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-undertow</artifactId> <version>${camel.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-http-common</artifactId> <version>${camel.version}</version> </dependency> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-maven-plugin</artifactId> <version>${camel.version}</version> <configuration> <fileApplicationContextUri>src/main/resources/META-INF/spring/camel-context.xml</fileApplicationContextUri> </configuration> </plugin>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 2
- Camel-context.xml: 다음과 같이 camel-undertow 구성 요소를 구성합니다.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/spring"> <route id="cbr-route" trace="true"> <from id="_from1" uri="undertow:http://localhost:7766/foo/bar"/> <setBody id="_setBody1"> <constant>Sending Response</constant> </setBody> <log id="_log5" message="Headers ${in.headers}"/> <log id="_log5" message="Done processing ${body}"/> </route> </camelContext> <bean class="org.apache.camel.component.undertow.UndertowComponent" id="undertow"> <property name="hostOptions" ref="undertowHostOptions"/> </bean> <bean class="org.apache.camel.component.undertow.UndertowHostOptions" id="undertowHostOptions"> <property name="http2Enabled" value="true"/> </bean> </beans>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/spring"> <route id="cbr-route" trace="true"> <from id="_from1" uri="undertow:http://localhost:7766/foo/bar"/> <setBody id="_setBody1"> <constant>Sending Response</constant> </setBody> <log id="_log5" message="Headers ${in.headers}"/> <log id="_log5" message="Done processing ${body}"/> </route> </camelContext> <bean class="org.apache.camel.component.undertow.UndertowComponent" id="undertow"> <property name="hostOptions" ref="undertowHostOptions"/> </bean> <bean class="org.apache.camel.component.undertow.UndertowHostOptions" id="undertowHostOptions"> <property name="http2Enabled" value="true"/> </bean> </beans>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
참고
기본적으로 false
로 설정된 http2Enabled
속성은 Cryostat HostOptions 클래스에 대해
로 설정됩니다. 그런 다음 이 클래스를 camel 경로에서 사용되는 Cryostat true
Component
라고 합니다.
이 예제에서는 pom.xml
파일에 camel-maven-plugin
을 사용하여 Maven 명령 mvn camel:run
.http://localhost:7766/foo/bar
다음과 같이 curl 명령을 사용하여 이 예제를 테스트할 수 있습니다.
curl -v --http2 http://localhost:7766/foo/bar GET /foo/bar HTTP/1.1 Host: localhost:7766 User-Agent: curl/7.53.1 Accept: */* Connection: Upgrade, HTTP2-Settings Upgrade: h2c HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
$ curl -v --http2 http://localhost:7766/foo/bar
* Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 7766 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 7766 (#0)
> GET /foo/bar HTTP/1.1
> Host: localhost:7766
> User-Agent: curl/7.53.1
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
>
< HTTP/1.1 101 Switching Protocols
< Connection: Upgrade
< Upgrade: h2c
< Date: Sun, 10 Dec 2017 08:43:58 GMT
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< accept: */*
< http2-settings: AAMAAABkAARAAAAAAAIAAAAA
< breadcrumbid: ID-dhcppc1-1512886066149-0-25
< content-length: 16
< user-agent: curl/7.53.1
< date: Sun, 10 Dec 2017 08:43:58 GMT
<
* Connection #0 to host localhost left intact
Sending Response