Package com.ibm.di.connector
Class HTTPServerConnector
- java.lang.Object
-
- com.ibm.di.connector.Connector
-
- com.ibm.di.connector.HTTPServerConnector
-
- All Implemented Interfaces:
ConnectorInterface,VersionInfoInterface
public class HTTPServerConnector extends Connector implements ConnectorInterface
This connector provides HTTP server like functionality and ability to receive/handle client requests sent over the HTTP protocol.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTR_NAME_HTTP_AUTH_ENTRYAnEntryattribute name: "auth.entry"static java.lang.StringATTR_NAME_HTTP_BODYAnEntryattribute name: "http.body"static java.lang.StringATTR_NAME_HTTP_CHARACTER_SETAnEntryattribute name: "characterSet"static java.lang.StringATTR_NAME_HTTP_CONNECTIONAnEntryattribute name: "http.connection"static java.lang.StringATTR_NAME_HTTP_CONTENT_TYPEAnEntryattribute name: "http.Content-Type"static java.lang.StringATTR_NAME_HTTP_REMOTE_PASSWORDAnEntryattribute name: "http.remote_pass"static java.lang.StringATTR_NAME_HTTP_REMOTE_USERAnEntryattribute name: "http.remote_user"static java.lang.String[]CONNECTOR_MODESPossible Connector modes.static java.lang.StringHTTP_BAD_REQUESTError String: "400 Bad Request"static java.lang.StringPARAM_SYSTEM_TCP_BACKLOGParameter Name: "com.ibm.di.tcp.backlog"static java.lang.StringPARAM_TCP_BACKLOGParameter Name: "backlog"static java.lang.StringPARAMETER_AUTH_CONNParameter Name: "authConnector"static java.lang.StringPARAMETER_AUTH_REALMParameter Name: "authRealm"static java.lang.StringPARAMETER_CONTENT_TYPEParameter Name: "contentType"static java.lang.StringPARAMETER_HEADERS_AS_PROPSParameter Name: "headersAsProperties"static java.lang.StringPARAMETER_HTTP_BASIC_AUTHParameter Name: "httpAuth"static java.lang.StringPARAMETER_IDLE_CONNECTION_TIMEOUTParameter Name: .static java.lang.StringPARAMETER_REQUIRE_CLIENT_AUTHParameter Name: "needClientAuth"static java.lang.StringPARAMETER_TCP_DATA_AS_PROPSParameter Name: "tcpDataAsProperties"static java.lang.StringPARAMETER_TCP_PORTParameter Name: "tcpPort"static java.lang.StringPARAMETER_USE_CHUNKSParameter Name: "msgChunked"static java.lang.StringPARAMETER_USE_SSLParameter Name: "useSSL"static java.lang.StringVERSION_INFOThe Connector version.-
Fields inherited from class com.ibm.di.connector.Connector
ALL_MODES, myLog, PROPERTY_MESSAGE, PROPERTY_READER, PROPERTY_WRITER
-
-
Constructor Summary
Constructors Constructor Description HTTPServerConnector()Constructs this object, sets the supported modes and initializes the internally usedHTTPParser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConnectorInterfacegetNextClient()This method blocks until a client is connected.EntrygetNextEntry()This method is called when this connector is used in Iterator mode.java.lang.StringgetPassword()Retrieves password.HTTPServerConnectorgetServerConnector()Retrieves server connector.java.lang.StringgetUserName()Retrieves username.java.lang.StringgetVersion()Version information.voidinitialize(java.lang.Object aObject)Parsers all the configuration parameters of this connector and prepares for starting the HTTP Server.booleanisAccepting()Checks whether the connector is waiting for a client connection.booleanisAutoChunking()Returns whether automatic chunking is enabled or not.booleanisChunked()Returns true if response is chunked.booleanisConnectionClosed()Returns true if the client socket is closedbooleanisTerminating()Checks whether a termination request is sent.voidputEntry(Entry aEntry)This method provides chunking capabilities to the HTTP server.voidrejectClientAuthentication()Prints the Forbidden page and closes the connection.voidreplyEntry(Entry aEntry)This method sends the provided entry to the client as an HTTP response.voidsetAutoChunking(boolean enabled)This method lets the user dynamically configure chunked output mode.voidsetProperty(Entry aEntry, java.lang.String aProperty, java.lang.Object aValue, boolean aTcpDataAsProps)This method adds a property to the provided entry if theaTcpDataAsPropsis set to true, if it is set to false then the provided property is added as an attribute.voidsetServerConnector(HTTPServerConnector aServerConnector)Sets the server connector for this connector.voidterminate()Terminate the connector.voidterminateServer()This method tries to terminate the server by setting the termination flag for the connector returned by getServerConnector and immediately connecting to its port (which should fail).-
Methods inherited from class com.ibm.di.connector.Connector
addFindEntry, allModes, clearFindEntries, debug, debugMode, deleteEntry, extractExceptionInformation, findEntry, findEntry, getBoolean, getClassInstance, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getLog, getMaxDuplicateEntries, getModes, getModes, getName, getNextFindEntry, getParam, getParser, getProperty, getPushbackEntry, getRawConnectorConfiguration, getRSInterface, getUI, hasConfigValue, hasParser, initParser, isDeltaSupported, isExceptionFatal, isIOException, logError, logmsg, modEntry, modEntry, pushback, queryOperations, queryReply, querySchema, queryTables, reconnect, reconnect, registerScriptBeans, selectEntries, setConfiguration, setContext, setCurrent, setDebugMode, setLog, setMaxDuplicateEntries, setModes, setModes, setName, setParam, setParser, setProperty, setRSInterface
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.ibm.di.connector.ConnectorInterface
deleteEntry, findEntry, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getMaxDuplicateEntries, getName, getNextFindEntry, getParam, getPushbackEntry, getRawConnectorConfiguration, isDeltaSupported, isExceptionFatal, isIOException, modEntry, modEntry, pushback, queryOperations, queryReply, querySchema, reconnect, registerScriptBeans, selectEntries, setConfiguration, setContext, setCurrent, setLog, setMaxDuplicateEntries, setName, setParam, setRSInterface
-
-
-
-
Field Detail
-
PARAMETER_TCP_PORT
public static final java.lang.String PARAMETER_TCP_PORT
Parameter Name: "tcpPort"- See Also:
- Constant Field Values
-
PARAM_TCP_BACKLOG
public static final java.lang.String PARAM_TCP_BACKLOG
Parameter Name: "backlog"- See Also:
- Constant Field Values
-
PARAM_SYSTEM_TCP_BACKLOG
public static final java.lang.String PARAM_SYSTEM_TCP_BACKLOG
Parameter Name: "com.ibm.di.tcp.backlog"- See Also:
- Constant Field Values
-
PARAMETER_HEADERS_AS_PROPS
public static final java.lang.String PARAMETER_HEADERS_AS_PROPS
Parameter Name: "headersAsProperties"- See Also:
- Constant Field Values
-
PARAMETER_TCP_DATA_AS_PROPS
public static final java.lang.String PARAMETER_TCP_DATA_AS_PROPS
Parameter Name: "tcpDataAsProperties"- See Also:
- Constant Field Values
-
PARAMETER_AUTH_CONN
public static final java.lang.String PARAMETER_AUTH_CONN
Parameter Name: "authConnector"- See Also:
- Constant Field Values
-
PARAMETER_HTTP_BASIC_AUTH
public static final java.lang.String PARAMETER_HTTP_BASIC_AUTH
Parameter Name: "httpAuth"- See Also:
- Constant Field Values
-
PARAMETER_AUTH_REALM
public static final java.lang.String PARAMETER_AUTH_REALM
Parameter Name: "authRealm"- See Also:
- Constant Field Values
-
PARAMETER_USE_SSL
public static final java.lang.String PARAMETER_USE_SSL
Parameter Name: "useSSL"- See Also:
- Constant Field Values
-
PARAMETER_REQUIRE_CLIENT_AUTH
public static final java.lang.String PARAMETER_REQUIRE_CLIENT_AUTH
Parameter Name: "needClientAuth"- See Also:
- Constant Field Values
-
PARAMETER_CONTENT_TYPE
public static final java.lang.String PARAMETER_CONTENT_TYPE
Parameter Name: "contentType"- See Also:
- Constant Field Values
-
PARAMETER_USE_CHUNKS
public static final java.lang.String PARAMETER_USE_CHUNKS
Parameter Name: "msgChunked"- See Also:
- Constant Field Values
-
PARAMETER_IDLE_CONNECTION_TIMEOUT
public static final java.lang.String PARAMETER_IDLE_CONNECTION_TIMEOUT
Parameter Name: . Connection timeout in seconds.- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_REMOTE_USER
public static final java.lang.String ATTR_NAME_HTTP_REMOTE_USER
AnEntryattribute name: "http.remote_user"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_REMOTE_PASSWORD
public static final java.lang.String ATTR_NAME_HTTP_REMOTE_PASSWORD
AnEntryattribute name: "http.remote_pass"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_BODY
public static final java.lang.String ATTR_NAME_HTTP_BODY
AnEntryattribute name: "http.body"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_CONTENT_TYPE
public static final java.lang.String ATTR_NAME_HTTP_CONTENT_TYPE
AnEntryattribute name: "http.Content-Type"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_CHARACTER_SET
public static final java.lang.String ATTR_NAME_HTTP_CHARACTER_SET
AnEntryattribute name: "characterSet"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_CONNECTION
public static final java.lang.String ATTR_NAME_HTTP_CONNECTION
AnEntryattribute name: "http.connection"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_AUTH_ENTRY
public static final java.lang.String ATTR_NAME_HTTP_AUTH_ENTRY
AnEntryattribute name: "auth.entry"- See Also:
- Constant Field Values
-
HTTP_BAD_REQUEST
public static final java.lang.String HTTP_BAD_REQUEST
Error String: "400 Bad Request"- See Also:
- Constant Field Values
-
VERSION_INFO
public static final java.lang.String VERSION_INFO
The Connector version.- See Also:
- Constant Field Values
-
CONNECTOR_MODES
public static final java.lang.String[] CONNECTOR_MODES
Possible Connector modes.
-
-
Constructor Detail
-
HTTPServerConnector
public HTTPServerConnector()
Constructs this object, sets the supported modes and initializes the internally usedHTTPParser.
-
-
Method Detail
-
initialize
public void initialize(java.lang.Object aObject) throws java.lang.ExceptionParsers all the configuration parameters of this connector and prepares for starting the HTTP Server. If aSocketis provided as a parameter then that socket will be used for communication with the client on the other end of the socket.- Specified by:
initializein interfaceConnectorInterface- Overrides:
initializein classConnector- Parameters:
aObject- recognizes only an object of typeSocket- Throws:
java.lang.Exception- if an error occurs.
-
getNextClient
public ConnectorInterface getNextClient() throws java.lang.Exception
This method blocks until a client is connected. After a connection is established a new instance of this object is created, initialized and returned.- Specified by:
getNextClientin interfaceConnectorInterface- Overrides:
getNextClientin classConnector- Returns:
- a new instance of
HTTPServerConnectorresponsible for handling the communication with the new client. - Throws:
java.lang.Exception- if this connector was not initialized properly or other type of error occurs.
-
getServerConnector
public HTTPServerConnector getServerConnector()
Retrieves server connector.- Returns:
- the server connector if this connector is handling an HTTP client
session, or
nullif a connection has not been established yet.
-
setServerConnector
public void setServerConnector(HTTPServerConnector aServerConnector)
Sets the server connector for this connector.- Parameters:
aServerConnector- the server connector that created this instance.
-
isAccepting
public boolean isAccepting()
Checks whether the connector is waiting for a client connection.- Returns:
- true if this connector is currently waiting for a client connection.
-
isTerminating
public boolean isTerminating()
Checks whether a termination request is sent.- Returns:
- true if this connector has the termination flag set.
-
terminateServer
public void terminateServer() throws java.lang.ExceptionThis method tries to terminate the server by setting the termination flag for the connector returned by getServerConnector and immediately connecting to its port (which should fail).- Specified by:
terminateServerin interfaceConnectorInterface- Overrides:
terminateServerin classConnector- Throws:
java.lang.Exception- if an error occurs.
-
terminate
public void terminate() throws java.lang.ExceptionTerminate the connector. This function closes all connection and releases all resources used by the connector. This function also calls the parser's closeParser() method if a parser is active.- Specified by:
terminatein interfaceConnectorInterface- Overrides:
terminatein classConnector- Throws:
java.lang.Exception- if an error occurs.
-
getNextEntry
public Entry getNextEntry() throws java.lang.Exception
This method is called when this connector is used in Iterator mode. This method will block until a client connects on the opened port. If the authentication fails the method returnsnull. If authentication is successful the HTTP request is parsed to anEntryobject and returned.- Specified by:
getNextEntryin interfaceConnectorInterface- Overrides:
getNextEntryin classConnector- Returns:
- the parsed HTTP request as an
Entryobject. - Throws:
java.lang.Exception- if an error occurs.- See Also:
ConnectorInterface.selectEntries()
-
putEntry
public void putEntry(Entry aEntry) throws java.lang.Exception
This method provides chunking capabilities to the HTTP server. This method is used from a scripts and is not directly called by the TDI Server. If the chunking is turned off the usage of this method will turn it on.- Specified by:
putEntryin interfaceConnectorInterface- Overrides:
putEntryin classConnector- Parameters:
aEntry- the entry to send as a chunk.- Throws:
java.lang.Exception- if a communication error is raised.
-
replyEntry
public void replyEntry(Entry aEntry) throws java.lang.Exception
This method sends the provided entry to the client as an HTTP response. If chunking is enabled then the provided entry will be sent as the last chunk.- Specified by:
replyEntryin interfaceConnectorInterface- Overrides:
replyEntryin classConnector- Parameters:
aEntry- the entry to send to the client.- Throws:
java.lang.Exception- if an error occurs.
-
getUserName
public java.lang.String getUserName()
Retrieves username.- Returns:
- the username used for the authentication.
-
getPassword
public java.lang.String getPassword()
Retrieves password.- Returns:
- the password the user has authenticated with.
-
rejectClientAuthentication
public void rejectClientAuthentication() throws java.lang.ExceptionPrints the Forbidden page and closes the connection. This method does not have effect if the basic authentication is not enabled for this connector.- Throws:
java.lang.Exception- if an error occurs.
-
setProperty
public void setProperty(Entry aEntry, java.lang.String aProperty, java.lang.Object aValue, boolean aTcpDataAsProps)
This method adds a property to the provided entry if theaTcpDataAsPropsis set to true, if it is set to false then the provided property is added as an attribute.- Parameters:
aEntry- the entry which the property will be set on.aProperty- the property name.aValue- the property value.aTcpDataAsProps- tells whether the property will be set as an Entry property or as Entry Attribute.
-
getVersion
public java.lang.String getVersion()
Version information.- Specified by:
getVersionin interfaceVersionInfoInterface- Returns:
- version information
-
setAutoChunking
public void setAutoChunking(boolean enabled)
This method lets the user dynamically configure chunked output mode. It has no effect if chunking already is enabled through the configuration. Setting this to "true" will cause the putEntry method to automatically initialize the chunked writer for output.- Parameters:
enabled- The new value for automatic chunking.
-
isAutoChunking
public boolean isAutoChunking()
Returns whether automatic chunking is enabled or not.- Returns:
- True if automatic chunking is enabled.
-
isChunked
public boolean isChunked()
Returns true if response is chunked.- Returns:
- True if response should be chunked.
-
isConnectionClosed
public boolean isConnectionClosed()
Returns true if the client socket is closed- Returns:
-
-