public class Connector extends java.lang.Object implements MessageListener
A connection to the Cordys ESB is always made for a SOAP Node. SOAPNodes are registered in a Directory Service, so that other applications can find it too. When you create a Connector, the Cordys ESB software will lookup what physical connection to open to the Cordys ESB. Starting from the moment that you call the open() method on the Connector, other applications on the Cordys ESB can send SOAPMessages to you, and you can send SOAPMessages to other applications.
A Connector can be used in a client oriented application (in which you ask things to other SOAP Nodes) or in a
service oriented application (in which you react on incoming SOAPMessages of clients).
When you build a service oriented application, you have to implement a SOAPMessageListener
that will handle incoming SOAPMessages. You have to register the listener in
the ListenerPool of the Connector.
When the Connector receives a SOAP message, it will look in the message for a message id.
If it finds the message id, it will check in the ListenerPool whether there is a SOAPMessageListener subscribed on this specific message id.
If there is no listener subscribed, the SOAP message will be deleted without notification.
You can register listeners per message id. There is also an option to register a default listener, that will handle
incoming SOAP Messages for which no listener is registered.
If you consider building a service oriented application, take a look at ApplicationConnector,
since extending this class will take automatic care of protocol specific issues, that must be handled in a SOAP message. ApplicationConnector
allows you to concentrate on your application specific contents of incoming SOAP messages.
When you build a client application, a typical communication scenario is that of sending a SOAP message to the Cordys ESB and
then hold the calling Thread until an answer is arrived. This is called synchronous communication. The methods sendAndWait
are designed for this. Underlying, these methods make use of the send methods, since the transport abstraction layers of the
Cordys ESB only support asynchronous communication.
If you call a sendAndWait() method, this call will block either until the answer comes back, or
until a timeout has expired. You can set the timeout in general, or specify it in the call.
If the timeout is 0, the method call will wait indefinitely if no answer comes back.
Any SOAP message that comes in from the Cordys ESB is parsed first. The SOAP message arrives as a Message object,
which is parsed with the Document of the Connector. For performance reasons,
this Document class is implemented in C. Object creation in Java is very expensive, when you compare it to C memory allocation. When you represent
each node in an XML Document as a Java Object, a lot of these objects have to be created. Therefore, the C implementation will create
'C objects' that are represented in Java as int
. A SOAP message is represented as an int
. You can manipulate your
SOAP message with the functions in the XML package and in the CO package.
Each Connector has only one Document, that is used for every XML manipulation. You are encouraged to use this same Document that you can
retrieve with the getDocument() method to do your XML manipulations as well.
If you call the close() method on the Connector, it has become invalid and you cannot use it anymore. It is also removed from the internal component cache. Any subsequent call on the Connector will result in an IllegalStateException. If you call any of the send methods on the Connector before it has been opened, this will also result in an IllegalStateException. If you call the open() method on an already opened Connector, nothing will happen.
com.eibus.connector.dom.Connector
,
Middleware
,
Message
,
ListenerPool
,
ApplicationConnector
,
Document
Modifier and Type | Class and Description |
---|---|
static class |
Connector.SOAPMethod
This class wraps a SOAP method through the NOM/DOM wrapper.
|
Modifier and Type | Field and Description |
---|---|
static int |
USE_MULTI_DOC |
static int |
USE_SINGLE_DOC |
Modifier and Type | Method and Description |
---|---|
void |
cancel(int envelope,
boolean restartServer)
Retrieves the message id from the header and calls the
cancel(messageId, restartServer) method. |
void |
cancel(java.lang.String messageId,
boolean restartServer)
Cancels an outstanding message with the specified identifier.
|
void |
close()
Closes the connection to the Cordys ESB.
|
void |
createManagedComponent(IManagedComponent parentComponent) |
void |
createManagedComponent(IManagedComponent parentComponent,
java.lang.String name,
java.lang.String description) |
int |
createSOAPMessage(java.lang.String uri)
The SOAP:Body node is returned from this function.
|
int |
createSOAPMessage(java.lang.String receiver,
Identity senderIdentity,
java.lang.String uri)
The SOAP:Body node is returned from this function.
|
int |
createSOAPMessage(java.lang.String receiver,
java.lang.String uri)
Creates a new SOAP Envelope node, with a header and a body in it.
|
int |
createSOAPMessage(java.lang.String receiver,
java.lang.String senderUser,
java.lang.String uri)
The SOAP:Body node is returned from this function.
|
int |
createSOAPMessageWithPrefix(java.lang.String receiver,
Identity senderIdentity,
java.lang.String uri,
java.lang.String prefix)
The
|
int |
createSOAPMessageWithPrefix(java.lang.String receiver,
java.lang.String senderUser,
java.lang.String uri,
java.lang.String prefix)
The
|
int |
createSOAPMethod(java.lang.String namespace,
java.lang.String method)
Creates the method node inside the body node
|
int |
createSOAPMethod(java.lang.String organization,
java.lang.String namespace,
java.lang.String method)
Creates the method node inside the body node
|
int |
createSOAPMethod(java.lang.String organizationalUser,
java.lang.String organization,
java.lang.String namespace,
java.lang.String method)
Creates the method node inside the body node.
|
int |
createSOAPMethodEx(java.lang.String namespace,
java.lang.String method,
java.lang.String organization,
java.lang.String senderUser,
java.lang.String receiver,
java.lang.String uri)
Creates the method node inside the body node
|
static java.util.Enumeration<Connector> |
getConnectors()
Returns an Enumeration of the currently created connectors.
|
Document |
getDocument()
Deprecated.
since BCP C.1, please use Node.getDocument(
|
static Connector |
getInstance(java.lang.String name)
Returns a Connector for the name.
|
static Connector |
getInstance(java.lang.String name,
int threadMultiplier) |
ListenerPool |
getListenerPool()
Returns the listener administration.
|
Middleware |
getMiddleware()
Returns the middleware object that is being used by this connector to send messages to
the Cordys ESB and receives messages from the Cordys ESB.
|
long |
getTimeout()
Synchronous calls 'to the Cordys ESB' suspend their Thread until an answer arrives, or until
a timer has expired.
|
static boolean |
isAuthenticated() |
boolean |
isClosed()
Indicates if the Connector is closed.
|
boolean |
isOpen()
Indicates if the Connector is open.
|
void |
onReceive(Message message)
Is called by the Cordys ESB when a message comes in.
|
void |
open()
Opens the connection to the Cordys ESB.
|
void |
send(int envelope)
Send a message to the Cordys ESB.
|
void |
send(int envelope,
MessageOptions messageOptions)
Send a message to the Cordys ESB.
|
void |
sendAndCallback(int envelope,
SOAPMessageListener listener)
Send a message to the Cordys ESB.
|
void |
sendAndCallback(int envelope,
SOAPMessageListener listener,
MessageOptions messageoptions)
Send a message with message options ( NON_TRANSACTIONAL_REPLY or TRANSACTIONAL_REPLY)
|
void |
sendAndCallbackEx(int request,
SOAPMessageListener listener,
Identity identity)
Populate the request with missing routing information, then send request.
|
int |
sendAndWait(int envelope)
Send a message to the Cordys ESB and suspend the current thread until a message comes
back, or until the default timeout period has expired.
|
int |
sendAndWait(int envelope,
long timeout)
Send a message to the Cordys ESB and suspend the current thread until a message comes
back, or until the timeout period has expired.
|
int |
sendAndWaitEx(int request,
Identity identity)
Populate the request with missing routing information, then send request and wait for response.
|
int |
sendAndWaitEx(int request,
long timeout,
Identity identity)
Populate the request with missing routing information, then send request and wait for response.
|
void |
sendEx(int request,
Identity identity)
Populate the request with missing routing information, then send request.
|
void |
sendEx(int request,
MessageOptions messageOptions,
Identity identity)
Populate the request with missing routing information, then send request.
|
static void |
setCredentials(java.lang.String userName,
java.lang.String password)
Deprecated.
|
void |
setDocPerThreadConfig(int config)
Set the configuration option for having a nom Document per thread.
|
void |
setTimeout(long timeout)
Synchronous calls 'to the Cordys ESB' suspend their Thread until an answer arrives, or until
a timer has expired.
|
Connector.SOAPMethod |
wrapSOAPMethod(int bodyNode)
Wraps the given body node in a wrapper object that provides XML DOM interfaces over it and provides memory
management.
|
public static final int USE_MULTI_DOC
public static final int USE_SINGLE_DOC
public static Connector getInstance(java.lang.String name) throws ExceptionGroup, DirectoryException
// This returns the connector instance "Anonymous Client" if already exists
// or else creates a new instance. This method only returns instance of connector
// A connection should be open explicitly by calling open() method if it is not already open.
Connector connector = Connector.getInstance("Anonymous Client");
name
- The name under which the connector will connect to the Cordys ESB (either existing in LDAP or not). If the name is not in the
LDAP server, then an anonymous connector is created, otherwise the connection points for listed for the entry in the LDAP server
are opened.LDAPException
- If error happened in the communication with the LDAP server. Passed on from the method Middleware.getInstance().ExceptionGroup
- Contains all exceptions that occured during creation of a connection to the underlying middleware. Passed on from the method Middleware.getInstance().DirectoryException
public static Connector getInstance(java.lang.String name, int threadMultiplier) throws ExceptionGroup, DirectoryException
ExceptionGroup
DirectoryException
public static java.util.Enumeration<Connector> getConnectors()
java.util.Enumeration enumeration = Connector.getConnectors();
public void createManagedComponent(IManagedComponent parentComponent)
public void createManagedComponent(IManagedComponent parentComponent, java.lang.String name, java.lang.String description)
public void open()
Connector connector = Connector.getInstance("Anonymous Client");
if(! connector.isOpen()) // it is always recommended to check whether the connection is already open
connector.open();
java.lang.IllegalStateException
- if the connector is closed.public boolean isOpen()
public boolean isClosed()
public Middleware getMiddleware()
Connector connector = Connector.getInstance("Anonymous Client");
Middleware middleWare = connector.getMiddleWare();
@Deprecated public Document getDocument()
Connector connector = Connector.getInstance("Anonymous Client");
Document document = connector.getDocument();
public void setTimeout(long timeout)
timeout
- The specified timeout period. Overrides current timeout period only if
timeout>=0
. If timeout==0, synchronous calls will block indefinitely, if
no answer is received.public long getTimeout()
public ListenerPool getListenerPool()
public void close()
public void onReceive(Message message)
onReceive
in interface MessageListener
message
- The incoming message.public int createSOAPMessage(java.lang.String uri)
uri
- A specific address to which this SOAP message should be tried
to sent first. Use this only if you want to send the message to a Soap
Node that is not registered in the directory server and is also not
running in this process.public int createSOAPMessage(java.lang.String receiver, java.lang.String uri)
SOAP:Envelope +-- SOAP:Header +-- header +-- sender +-- component +-- name of component in this connector +-- reply-to +-- primary reply address on which this connector is listening +-- user +-- name of currently logged on user +-- receiver +-- component <-- only if specified in receiver-parameter +-- receiver-parameter +-- sent-to <-- only if specified in uri-parameter +-- uri-parameter +-- SOAP:Body
Connector connector = Connector.getInstance("Anonymous Client");
String receiver = "dn of the receiver"
if(!connector.isOpen())
connector.open();
connector.createSOAPMessage(receiver,null);
receiver
- The name of the component that is supposed to receive this SOAP message. This name should either be a name that
is registered in the Directory Server, or it should be the name of a Connector that is running in this process as well.uri
- A specific address to which this SOAP message should be tried to sent first. Use this only if you want to send the message
to a Soap Node that is not registered in the directory server and is also not running in this process.public int createSOAPMessage(java.lang.String receiver, java.lang.String senderUser, java.lang.String uri)
receiver
- The name of the component that is supposed to receive this SOAP message. This name should either be a name that
is registered in the Directory Server, or it should be the name of a Connector that is running in this process as well.senderUser
- The name of the component/ user that is sending this
SOAP Message.uri
- A specific address to which this SOAP message should be tried to sent first. Use this only if you want to send the message
to a Soap Node that is not registered in the directory server and is also not running in this process.public int createSOAPMessageWithPrefix(java.lang.String receiver, java.lang.String senderUser, java.lang.String uri, java.lang.String prefix)
receiver
- The name of the component that is supposed to receive this SOAP message. This name should either be a name that
is registered in the Directory Server, or it should be the name of a Connector that is running in this process as well.senderUser
- The name of the component/ user that is sending this
SOAP Message.uri
- A specific address to which this SOAP message should be tried to sent first. Use this only if you want to send the message
to a Soap Node that is not registered in the directory server and is also not running in this process.prefix
- A prefix to SOAP Request. For example prefix is "SOAP".public int createSOAPMessage(java.lang.String receiver, Identity senderIdentity, java.lang.String uri)
receiver
- The name of the component that is supposed to receive this SOAP message. This name should either be a name that
is registered in the Directory Server, or it should be the name of a Connector that is running in this process as well.senderUser
- The name of the component/ user that is sending this
SOAP Message.uri
- A specific address to which this SOAP message should be tried to sent first. Use this only if you want to send the message
to a Soap Node that is not registered in the directory server and is also not running in this process.public int createSOAPMessageWithPrefix(java.lang.String receiver, Identity senderIdentity, java.lang.String uri, java.lang.String prefix)
receiver
- The name of the component that is supposed to receive this SOAP message. This name should either be a name that
is registered in the Directory Server, or it should be the name of a Connector that is running in this process as well.senderUser
- The name of the component/ user that is sending this
SOAP Message.uri
- A specific address to which this SOAP message should be tried to sent first. Use this only if you want to send the message
to a Soap Node that is not registered in the directory server and is also not running in this process.prefix
- A prefix to SOAP Request. For example prefix is "SOAP".public int createSOAPMethod(java.lang.String namespace, java.lang.String method) throws DirectoryException
namespace
- The namespace of the methodsetmethod
- Name of the method that should be invokedDirectoryException
- If a soapNode implementing the specified
namespace is not foundpublic Connector.SOAPMethod wrapSOAPMethod(int bodyNode) throws XMLException
bodyNode
- the body node to be wrappedXMLException
- when XML processing failspublic int createSOAPMethod(java.lang.String organization, java.lang.String namespace, java.lang.String method) throws DirectoryException
organization
- The name of the organizationnamespace
- The namespace of the methodsetmethod
- Name of the method that should be invokedDirectoryException
- If a soapNode implementing the specified
namespace is not foundpublic int createSOAPMethodEx(java.lang.String namespace, java.lang.String method, java.lang.String organization, java.lang.String senderUser, java.lang.String receiver, java.lang.String uri) throws DirectoryException
namespace
- The namespace of the methodsetmethod
- Name of the method that should be invokedorganization
- The name of the organizationsenderUser
- The name of the component/ user that is sending this
SOAP Message.receiver
- The name of the component that is supposed to receive
this SOAP message. This name should either be a name that is registered
in the Directory Server, or it should be the name of a Connector that is
running in this process as well.uri
- A specific address to which this SOAP message should be tried
to sent first. Use this only if you want to send the message to a Soap
Node that is not registered in the directory server and is also not
running in this process.DirectoryException
- If a soapNode implementing the specified
namespace is not foundpublic int createSOAPMethod(java.lang.String organizationalUser, java.lang.String organization, java.lang.String namespace, java.lang.String method) throws DirectoryException
organizationalUser
- The name of the acting user.organization
- The name of the organizationnamespace
- The namespace of the methodsetmethod
- Name of the method that should be invokedDirectoryException
- If a soapNode implementing the specified namespace is not foundpublic int sendAndWait(int envelope) throws TimeoutException, ExceptionGroup
Connector connector = Connector.getInstance("Anonymous Client");
if(! connector.isOpen())
connector.open();
int soapMethod = connector.createSOAPMethod("namespace","methodName");
int response = connector.sendAndWait(Node.getParent(soapMethod));
envelope
- The pointer to the XML tree representing the SOAP messageExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedpublic int sendAndWaitEx(int request, Identity identity) throws TimeoutException, ExceptionGroup
request
- The pointer to the XML tree representing the SOAP message
be blocked. If timeout is less than 0, the default timeout will be used.identity
- The identity that is send to the soap processorExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedConnector.sendAndWait()
,
Identity
public int sendAndWait(int envelope, long timeout) throws CancelRequestException, TimeoutException, ExceptionGroup
Connector connector = Connector.getInstance("Anonymous Client");
if(! connector.isOpen())
connector.open();
int soapMethod = connector.createSOAPMethod("namespace","methodName");
int response = connector.sendAndWait(Node.getParent(soapMethod),30000);
envelope
- The pointer to the XML tree representing the SOAP messagetimeout
- The timeout period for which the calling Thread at maximum should
be blocked. If timeout is less than 0, the default timeout will be used.ExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedCancelRequestException
public int sendAndWaitEx(int request, long timeout, Identity identity) throws TimeoutException, ExceptionGroup
request
- The pointer to the XML tree representing the SOAP message
be blocked. If timeout is less than 0, the default timeout will be used.timeout
- The timeout period for which the calling Thread at maximum should
be blocked. If timeout is less than 0, the default timeout will be used.identity
- The identity that is send to the soap processorExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedConnector.sendAndWait()
,
Identity
public void sendAndCallback(int envelope, SOAPMessageListener listener) throws ExceptionGroup
Connector connector = Connector.getInstance("Anonymous Client");
if(! connector.isOpen())
connector.open();
int soapMethod = connector.createSOAPMethod("namespace","methodName");
connector.sendAndCallback(Node.getParent(soapMethod),new MyListener());
........
........
.....
class MyListener implements SOAPMessageListener
{
public boolean onReceive(int message)
{
// do some thing
System.out.println(Node.writeToString(message,true));
return true;
}
}
envelope
- int reference of the SOAP Envelopelistener
- Listener that is listens for the specified SOAP MessageExceptionGroup
- if the message could not be sentpublic void sendAndCallbackEx(int request, SOAPMessageListener listener, Identity identity) throws TimeoutException, ExceptionGroup
request
- The pointer to the XML tree representing the SOAP message
be blocked. If timeout is less than 0, the default timeout will be used.listener
- Listener that is listens for the specified SOAP Messageidentity
- The identity that is send to the soap processorExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedConnector.sendAndCallback()
,
Identity
public void send(int envelope) throws ExceptionGroup
Connector connector = Connector.getInstance("Anonymous Client");
if(! connector.isOpen())
connector.open();
connector.getListenerPool().setDefaultListener(new MyListener());
int soapMethod = connector.createSOAPMethod("namespace","methodName");
connector.send(Node.getParent(soapMethod));
...........
........
.......
class MyListener implements SOAPMessageListener
{
public boolean onReceive(int message)
{
// do some thing
System.out.println(Node.writeToString(message,true));
return true;
}
}
envelope
- int reference of the SOAP MEssageExceptionGroup
- if connector fails to send messagepublic void sendEx(int request, Identity identity) throws TimeoutException, ExceptionGroup
request
- The pointer to the XML tree representing the SOAP message
be blocked. If timeout is less than 0, the default timeout will be used.identity
- The identity that is send to the soap processorExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedConnector.send()
,
Identity
public void send(int envelope, MessageOptions messageOptions) throws ExceptionGroup
Connector connector = Connector.getInstance("Anonymous Client");
if(! connector.isOpen())
connector.open();
connector.getListenerPool().setDefaultListener(new MyListener());
int soapMethod = connector.createSOAPMethod("namespace","methodName");
connector.send(Node.getParent(soapMethod),MessageOptions.NON_TRANSACTIONAL_REPLY);
...........
........
.......
class MyListener implements SOAPMessageListener
{
public boolean onReceive(int message)
{
// do some thing
System.out.println(Node.writeToString(message,true));
return true;
}
}
envelope
- int reference of the SOAP MEssagemessageOptions
- to set the transactional behaviour of the message send.ExceptionGroup
- if connector fails to send messagepublic void sendEx(int request, MessageOptions messageOptions, Identity identity) throws TimeoutException, ExceptionGroup
request
- The pointer to the XML tree representing the SOAP message
be blocked. If timeout is less than 0, the default timeout will be used.identity
- The identity that is send to the soap processormessageOptions
- to set the transactional behaviour of the message send.ExceptionGroup
- if the message could not be sentTimeoutException
- if the timer expired before a reply was receivedConnector.send()
,
Identity
public void cancel(int envelope, boolean restartServer)
cancel(messageId, restartServer)
method.envelope
- The request for which the reply needs to be canceled.restartServer
- not applicable irrespective of the value passed.public void cancel(java.lang.String messageId, boolean restartServer)
envelope
- The id of the request for which the reply needs to be canceled.restartServer
- not applicable irrespective of the value passed.@Deprecated public static void setCredentials(java.lang.String userName, java.lang.String password) throws CredentialsFailedException
CredentialsFailedException
public static boolean isAuthenticated()
public void setDocPerThreadConfig(int config)
config
- One of USE_SINGLE_DOC or USE_MULTI_DOC.public void sendAndCallback(int envelope, SOAPMessageListener listener, MessageOptions messageoptions) throws ExceptionGroup
envelope
- listener
- messageoptions
- ExceptionGroup