検索

357.8. HTTP/2 の例

download PDF

このサンプルでは、camel-undertow コンポーネントを設定して HTTP/2 プロトコルをサポートし、http://localhost:7766/foo/bar で HTTP サービスを公開します。

このサンプルのディレクトリー構造は次のとおりです。

├── pom.xml 1
├── README.md
└── src
    └── main
        └── resources
            └── META-INF
                └── spring
                    └── camel-context.xml 2

次のファイルは、camel-undertow コンポーネントを設定して HTTP/2 プロトコルをサポートするために重要です。

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>
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>
注記

デフォルトで false に設定されている http2Enabled プロパティーは、UndertowHostOptions クラスでは true に設定されます。このクラスは、camel ルートで使用される UndertowComponent に参照されます。

この例では、pom.xml ファイルで camel-maven-plugin を使用することにより、Maven コマンド mvn camel:run を実行するときに http://localhost:7766/foo/bar で HTTP サービスを公開できます。

次のように curl コマンドを使用して、この例をテストできます。

$ 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
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.