이 콘텐츠는 선택한 언어로 제공되지 않습니다.

48.3. ghttp


ghttp Component

The ghttp component contributes to the Camel Components for Google App Engine (GAE). It provides connectivity to the GAE URL fetch service but can also be used to receive messages from servlets (the only way to receive HTTP requests on GAE). This is achieved by extending the Servlet component. As a consequence, ghttp URI formats and options sets differ on the consumer-side (from) and producer-side (to).

URI format

Expand
Format Context Comment
ghttp:///path[?options]
Copy to Clipboard Toggle word wrap
Consumer See also Servlet component
ghttp://hostname[:port][/path][?options]
ghttps://hostname[:port][/path][?options]
Copy to Clipboard Toggle word wrap
Producer See also Http component

Options

Expand
Name Default Value Context Description
bridgeEndpoint true Producer If set to true the Exchange.HTTP_URI header will be ignored. To override the default endpoint URI with the Exchange.HTTP_URI header set this option to false.
throwExceptionOnFailure true Producer Throw a org.apache.camel.component.gae.http if the response code is >= 400. To disable throwing an exception set this option to false.
inboundBindingRef reference to GHttpBinding Consumer Reference to an InboundBinding<GHttpEndpoint, HttpServletRequest, HttpServletResponse> in the Registry for customizing the binding of an Exchange to the Servlet API. The referenced binding is used as post-processor to org.apache.camel.component.http.HttpBinding.
outboundBindingRef reference to GHttpBinding Producer Reference to an OutboundBinding<GHttpEndpoint, HTTPRequest, HTTPResponse> in the Registry for customizing the binding of an Exchange to the URLFetchService.
On the consumer-side, all options of the Servlet component are supported.

Message headers

On the producer side, the following headers of the Http component are supported.
Expand
Name Type Description
Exchange.CONTENT_TYPE String The HTTP content type. Is set on both the in and out message to provide a content type, such as text/html.
Exchange.CONTENT_ENCODING String The HTTP content encoding. Is set on both the in and out message to provide a content encoding, such as gzip.
Exchange.HTTP_METHOD String The HTTP method to execute. One of GET, POST, PUT and DELETE. If not set, POST will be used if the message body is not null, GET otherwise.
Exchange.HTTP_QUERY String Overrides the query part of the endpoint URI or the the query part of Exchange.HTTP_URI (if defined). The query string must be in decoded form.
Exchange.HTTP_URI String Overrides the default endpoint URI if the bridgeEndpoint option is set to false. The URI string must be in decoded form.
Exchange.RESPONSE_CODE int The HTTP response code from URL fetch service responses.
On the consumer-side all headers of the Servlet component component are supported.

Message body

On the producer side the in message body is converted to a byte[]. The out message body is made available as InputStream. If the reponse size exceeds 1 megabyte a ResponseTooLargeException is thrown by the URL fetch service (see quotas and limits).

Receiving messages

For receiving messages via the ghttp component, a CamelHttpTransportServlet must be configured and mapped in the application's web.xml (see the section called “The web.xml”). For example, to handle requests targeted at http://<appname>.appspot.com/camel/* or http://localhost/camel/* (when using a local development server) the following servlet mapping must be defined:
web.xml
    ...
    <servlet>
        <servlet-name>CamelServlet</servlet-name>
        <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
        ...
    </servlet>
    ...
    <servlet-mapping>
        <servlet-name>CamelServlet</servlet-name>
        <url-pattern>/camel/*</url-pattern>
    </servlet-mapping>
    ...
Copy to Clipboard Toggle word wrap
Endpoint URI path definitions are relative to this servlet mapping e.g. the route
from("ghttp:///greeting").transform().constant("Hello")
Copy to Clipboard Toggle word wrap
processes requests targeted at http://<appname>.appspot.com/camel/greeting. In this example, the request body is ignored and the response body is set to Hello. Requests targeted at http://<appname>.appspot.com/camel/greeting/* are not processed by default. This requires setting the option matchOnUriPrefix to true.
from("ghttp:///greeting?matchOnUriPrefix=true").transform().constant("Hello")
Copy to Clipboard Toggle word wrap

Sending messages

For sending resquests to external HTTP services the ghttp component uses the URL fetch service. For example, the Apache Camel homepage can the retrieved with the following endpoint definition on the producer-side.
from(...)
...
.to("ghttp://camel.apache.org")
...
Copy to Clipboard Toggle word wrap
The HTTP method used depends on the Exchange.HTTP_METHOD message header or on the presence of an in-message body (GET if null, POST otherwise). Retrieving the Camel homepage via a GAE application is as simple as
from("ghttp:///home")
.to("ghttp://camel.apache.org")
Copy to Clipboard Toggle word wrap
Sending a GET request to http://<appname>.appspot.com/camel/home returns the Camel homepage. HTTPS-based communication with external services can be enabled with the ghttps scheme.
from(...)
...
.to("ghttps://svn.apache.org/repos/asf/camel/trunk/")
...
Copy to Clipboard Toggle word wrap

Dependencies

Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-gae</artifactId>
    <version>${camel-version}</version>
</dependency>
Copy to Clipboard Toggle word wrap
where ${camel-version} must be replaced by the actual version of Apache Camel (2.1.0 or higher).
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat