For each different mapping of data between a Service Component Architecture (SCA) message and an HTTP protocol message, a data handler or an HTTP data binding must be configured. Data handlers provide a binding-neutral interface that allows reuse across transport bindings and represent the recommended approach; data bindings are specific to a particular transport binding. HTTP-specific data binding classes are supplied; you can also write custom data handlers or data bindings.
<xsd:schema elementFormDefault="qualified"
targetNamespace="http://com.ibm.websphere.http.data.bindings/schema"
xmlns:tns="http://com.ibm.websphere.http.data.bindings/schema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="HTTPBaseBody">
<xsd:sequence/>
</xsd:complexType>
<xsd:complexType name="HTTPBytesBody">
<xsd:complexContent>
<xsd:extension base="tns:HTTPBaseBody">
<xsd:sequence>
<xsd:element name="value" type="xsd:hexBinary"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
HTTPStreamDataBinding is the principal interface for handling custom HTTP messages. The interface is designed to allow handling of large payloads. However, in order for such implementation to work, this data binding must return the control information and headers before writing the message into the stream.
The methods and their order of execution, listed below, must be implemented by the custom data binding.
The convertFromNativeData(...) binding will not be invoked by the HTTP binding unless isBusinessException() returns true. If isBusinessException() returns false, convertFromNativeData(...) will not be invoked until the message data needs to be read or modified later in the SCA process.
You must invoke setDataObject(...) in convertFromNativeData(...) to set the value of dataObject, which is converted from native data to the private property "pDataObject".
public void setDataObject(DataObject dataObject)
throws DataBindingException {
pDataObject = dataObject;
}
public void setControlParameters(HTTPControl arg0) {
this.pCtrl = arg0;
}
public void setHeaders(HTTPHeaders arg0) {
this.pHeaders = arg0;
}
/*
* Add http header "IsBusinessException" in pHeaders.
* Two steps:
* 1.Remove all the header with name IsBusinessException (case-insensitive) first.
* This is to make sure only one header is present.
* 2.Add the new header "IsBusinessException"
*/
public void setBusinessException(boolean isBusinessException) {
//remove all the header with name IsBusinessException (case-insensitive) first.
//This is to make sure only one header is present.
//add the new header "IsBusinessException", code example:
HTTPHeader header=HeadersFactory.eINSTANCE.createHTTPHeader();
header.setName("IsBusinessException");
header.setValue(Boolean.toString(isBusinessException));
this.pHeaders.getHeader().add(header);
}
public HTTPControl getControlParameters() {
return pCtrl;
}
public HTTPHeaders getHeaders() {
return pHeaders;
}
public DataObject getDataObject() throws DataBindingException {
return pDataObject;
}
/*
* Get header "IsBusinessException" from pHeaders, return its boolean value
*/
public boolean isBusinessException() {
String headerValue = getHeaderValue(pHeaders,"IsBusinessException");
boolean result=Boolean.parseBoolean(headerValue);
return result;
}
public void convertToNativeData() throws DataBindingException {
DataObject dataObject = getDataObject();
this.nativeData=realConvertWorkFromSDOToNativeData(dataObject);
}
public void convertFromNativeData(HTTPInputStream arg0){
//Customer-developed method to
//Read data from HTTPInputStream
//Convert it to DataObject
DataObject dataobject=realConvertWorkFromNativeDataToSDO(arg0);
setDataObject(dataobject);
}
public void write(HTTPOutputStream output) throws IOException {
if (nativeData != null)
output.write(nativeData);
}