HTTP reference

更新时间:
复制 MD 格式

Introduction

Core HTTP types are used by connector nodes that use the HTTP protocol. These types include HttpRequest, HttpResponse, HttpHeader, and HttpCookie.

HttpRequest

Introduction

The engine uses this data structure to describe an HTTP request.

  • When a connector node, such as an HTTP node, accesses a peer system, the engine automatically creates an HttpRequest object from the node's configuration.

  • The output message payload from an integration flow's entry node, such as an HTTP API Listener node, contains an HttpRequest object for subsequent nodes to use.

Coordinate: com.alibaba.bwif.script.core.protocol.http.HttpRequest

Construction

The integration flow engine creates this object. You cannot create it in a script.

Method list

Method

Description

String getPath()

Gets the full URI of the request, excluding the domain, protocol, and query string. For example, for http://abc.com/a/b/c?q1=1, this method returns /a/b/c.

String getHttpMethod()

Gets the HTTP method of the request, such as GET or POST.

Entity getBody()

Gets the request body object. The body object is an Entity type. The content-type from the HTTP request is used as the Entity's Multipurpose Internet Mail Extensions (MIME) type.

String getParam(String key)

Gets the value of a specified parameter by its key. If the key is duplicated, the first value is returned. This method supports path parameters and query parameters.

List getHeaders()

Gets all header information. Returns a list of com.alibaba.bwif.script.core.protocol.http.HttpHeader objects. For more information, see HttpHeader.

String getHeader(String key)

Gets the value for a specified key. If the header contains duplicate keys, the first value is returned. The value is always converted to a String. For example, if the header['Content-Length'] is 2, this method returns "2".

String getPathParam(String key)

Gets the value of a specified path parameter by its key. The value is always a String. If the key is duplicated, one value is returned.

Map getPathParamMap()

Returns a map of path parameters as key-value pairs. The value is a String. If a key is duplicated, only one value is included in the map.

String getQueryString()

Gets the entire query string, such as q1=v1&q2=v2.

String getQueryParam(String key)

Gets the value of a query parameter by its key. The first value is returned by default.

HttpResponse

Introduction

This topic describes the data structure of an HTTP response.

  • When a connector node, such as an HTTP node, accesses a peer system, the engine automatically creates an HttpResponse object from the peer's response. Subsequent nodes can then use this object.

  • The last node in an integration flow, such as an HTTP API Reply node, generates the HTTP response content based on the node's configuration and returns it to the original requester.

Path: com.alibaba.bwif.script.core.protocol.http.HttpResponse.

Construction

The integration flow engine creates this object. You cannot create it in a script.

Method list

Method

Description

Entity getBody()

Gets the body content of the HTTP response from the peer system. The type is Entity. The MIME type is determined by the content-type of the HTTP response.

long getBodyLength()

Gets the Content-Length of the HTTP response from the peer system.

int getStatusCode()

Gets the HTTP status code from the peer system's response, such as 200 or 404.

List getHeaders()

Gets all headers from the HTTP response of the peer system. Returns a List<HttpHeader> of com.alibaba.bwif.script.core.protocol.http.HttpHeader objects. For more information, see HttpHeader.

If the headers include cookie information, it is still returned as a header type.

List getCookies()

Gets all cookie information from the headers of the HTTP response from the peer system. Returns a List<HttpCookie> of com.alibaba.bwif.script.core.protocol.http.HttpCookie objects. For more information, see HttpCookie.

HttpHeader

Introduction

The HttpHeader class is used with the HttpRequest and HttpResponse classes to describe the key-value structure of a header.

The coordinate is com.alibaba.bwif.script.core.protocol.http.HttpHeader.

Construction

The engine creates this object automatically. You cannot create it in a script.

Method list

Method

Description

String getKey()

Returns the header's key.

String getValue()

Returns the header's value as a String. For example, if the Content-Length header is 2, this method returns "2".

HttpCookie

Introduction

The HttpCookie class is used with the HttpRequest and HttpResponse classes to describe the structure of a cookie.

The coordinate is com.alibaba.bwif.script.core.protocol.http.HttpCookie.

Construction

The engine creates this object automatically. You cannot create it in a script.

Method list

Method

Description

String getName()

Returns the cookie's name.

String getValue()

Returns the cookie's value as a String.