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.String
ATTR_NAME_HTTP_AUTH_ENTRY
AnEntry
attribute name: "auth.entry"static java.lang.String
ATTR_NAME_HTTP_BODY
AnEntry
attribute name: "http.body"static java.lang.String
ATTR_NAME_HTTP_CHARACTER_SET
AnEntry
attribute name: "characterSet"static java.lang.String
ATTR_NAME_HTTP_CONNECTION
AnEntry
attribute name: "http.connection"static java.lang.String
ATTR_NAME_HTTP_CONTENT_TYPE
AnEntry
attribute name: "http.Content-Type"static java.lang.String
ATTR_NAME_HTTP_REMOTE_PASSWORD
AnEntry
attribute name: "http.remote_pass"static java.lang.String
ATTR_NAME_HTTP_REMOTE_USER
AnEntry
attribute name: "http.remote_user"static java.lang.String[]
CONNECTOR_MODES
Possible Connector modes.static java.lang.String
HTTP_BAD_REQUEST
Error String: "400 Bad Request"static java.lang.String
PARAM_SYSTEM_TCP_BACKLOG
Parameter Name: "com.ibm.di.tcp.backlog"static java.lang.String
PARAM_TCP_BACKLOG
Parameter Name: "backlog"static java.lang.String
PARAMETER_AUTH_CONN
Parameter Name: "authConnector"static java.lang.String
PARAMETER_AUTH_REALM
Parameter Name: "authRealm"static java.lang.String
PARAMETER_CONTENT_TYPE
Parameter Name: "contentType"static java.lang.String
PARAMETER_HEADERS_AS_PROPS
Parameter Name: "headersAsProperties"static java.lang.String
PARAMETER_HTTP_BASIC_AUTH
Parameter Name: "httpAuth"static java.lang.String
PARAMETER_IDLE_CONNECTION_TIMEOUT
Parameter Name: .static java.lang.String
PARAMETER_REQUIRE_CLIENT_AUTH
Parameter Name: "needClientAuth"static java.lang.String
PARAMETER_TCP_DATA_AS_PROPS
Parameter Name: "tcpDataAsProperties"static java.lang.String
PARAMETER_TCP_PORT
Parameter Name: "tcpPort"static java.lang.String
PARAMETER_USE_CHUNKS
Parameter Name: "msgChunked"static java.lang.String
PARAMETER_USE_SSL
Parameter Name: "useSSL"static java.lang.String
VERSION_INFO
The 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 ConnectorInterface
getNextClient()
This method blocks until a client is connected.Entry
getNextEntry()
This method is called when this connector is used in Iterator mode.java.lang.String
getPassword()
Retrieves password.HTTPServerConnector
getServerConnector()
Retrieves server connector.java.lang.String
getUserName()
Retrieves username.java.lang.String
getVersion()
Version information.void
initialize(java.lang.Object aObject)
Parsers all the configuration parameters of this connector and prepares for starting the HTTP Server.boolean
isAccepting()
Checks whether the connector is waiting for a client connection.boolean
isAutoChunking()
Returns whether automatic chunking is enabled or not.boolean
isChunked()
Returns true if response is chunked.boolean
isConnectionClosed()
Returns true if the client socket is closedboolean
isTerminating()
Checks whether a termination request is sent.void
putEntry(Entry aEntry)
This method provides chunking capabilities to the HTTP server.void
rejectClientAuthentication()
Prints the Forbidden page and closes the connection.void
replyEntry(Entry aEntry)
This method sends the provided entry to the client as an HTTP response.void
setAutoChunking(boolean enabled)
This method lets the user dynamically configure chunked output mode.void
setProperty(Entry aEntry, java.lang.String aProperty, java.lang.Object aValue, boolean aTcpDataAsProps)
This method adds a property to the provided entry if theaTcpDataAsProps
is set to true, if it is set to false then the provided property is added as an attribute.void
setServerConnector(HTTPServerConnector aServerConnector)
Sets the server connector for this connector.void
terminate()
Terminate the connector.void
terminateServer()
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
AnEntry
attribute 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
AnEntry
attribute name: "http.remote_pass"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_BODY
public static final java.lang.String ATTR_NAME_HTTP_BODY
AnEntry
attribute name: "http.body"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_CONTENT_TYPE
public static final java.lang.String ATTR_NAME_HTTP_CONTENT_TYPE
AnEntry
attribute 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
AnEntry
attribute name: "characterSet"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_CONNECTION
public static final java.lang.String ATTR_NAME_HTTP_CONNECTION
AnEntry
attribute name: "http.connection"- See Also:
- Constant Field Values
-
ATTR_NAME_HTTP_AUTH_ENTRY
public static final java.lang.String ATTR_NAME_HTTP_AUTH_ENTRY
AnEntry
attribute 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.Exception
Parsers all the configuration parameters of this connector and prepares for starting the HTTP Server. If aSocket
is provided as a parameter then that socket will be used for communication with the client on the other end of the socket.- Specified by:
initialize
in interfaceConnectorInterface
- Overrides:
initialize
in 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:
getNextClient
in interfaceConnectorInterface
- Overrides:
getNextClient
in classConnector
- Returns:
- a new instance of
HTTPServerConnector
responsible 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
null
if 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.Exception
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).- Specified by:
terminateServer
in interfaceConnectorInterface
- Overrides:
terminateServer
in classConnector
- Throws:
java.lang.Exception
- if an error occurs.
-
terminate
public void terminate() throws java.lang.Exception
Terminate 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:
terminate
in interfaceConnectorInterface
- Overrides:
terminate
in 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 anEntry
object and returned.- Specified by:
getNextEntry
in interfaceConnectorInterface
- Overrides:
getNextEntry
in classConnector
- Returns:
- the parsed HTTP request as an
Entry
object. - 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:
putEntry
in interfaceConnectorInterface
- Overrides:
putEntry
in 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:
replyEntry
in interfaceConnectorInterface
- Overrides:
replyEntry
in 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.Exception
Prints 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 theaTcpDataAsProps
is 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:
getVersion
in 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:
-
-