Entering content frame

Object documentation HTTPTransport Interface Locate the document in its SAP Library structure

Definition

Using an instance of the HTTPTransport interface enables client protocol implementations to gain control of the underlying transport. This interface is bound in the context for HTTP transport. For bindings that use transports other than HTTP transport, it is possible for a different interface to be bound in the context.

Use

To get a control interface for the current transport use:

Object transportInterface = context.getProperty(ClientTransportBinding.TRANSPORT_INTERFACE);

The object received provides an interface for transport control. Currently, only the HTTP transport is supported. In your code, assume that other interfaces are possible in the future and do not consider direct typecast of the object.

Structure

The HTTPTransport interface contains the following methods:

·        public String[] getHeader(String headerName) – returns an array of header values for a particular header name

·        public void setHeader(String headerName, String headerValue) – adds header values to the HTTP request

·        public String getEndpoint() – returns the Endpoint URL

·        public void setEndpoint(String endpoint) – sets a new Endpoint

·        public Enumeration listHeaders() – returns headers available

·        public void setHeader(String headerName, String[] headerValues) – sets an array of values to a header

Example

 

public boolean handleRequest(AbstractMessage message, PropertyContext context)

throws ClientProtocolException {

    Object transportInterface = context.getProperty(ClientTransportBinding.TRANSPORT_INTERFACE); 

    if (transportInterface instanceof HTTPTransportInterface) {   

       // HTTP Transport is used   

       HTTPTransportInterface http = (HTTPTransportInterface) transportInterface;   

       // Example of getting or setting the endpoint  

       String endpoint = http.getEndpoint();   

       System.out.println("Endpoint is:"+endpoint); 

        try {   

          http.setEndpoint(endpoint);    

       }catch (Exception e) {    

        throw new ClientProtocolException("Cannot set transport Endpoint to ["+endpoint+"]");  

       }

     }

    }

 

Leaving content frame