AsyncChannel
, AsyncInvokerSupport
, Channel
, ChannelListenerSupport
, ConfigurationSupport
, ConnectionInvokerSupport
, EndpointSupport
, OutputChannel
, ProtocolDescriptionSupport
, Receiver
, ReceiverManagement
, RequestReceiver
, RequestReceiverManagement
, ResponseChannel
public class ExternalServiceProtocolListener extends ServerChannel
ExternalServiceProtocolListener
object as a server for ExternalServiceProtocol
.
// Example of using ExternalServiceProtocolListener
.
import com.genesyslab.platform.openmedia.protocol.ExternalServiceProtocol;
import com.genesyslab.platform.openmedia.protocol.ExternalServiceProtocolListener;
import com.genesyslab.platform.openmedia.protocol.externalservice.request.Request3rdServer;
import com.genesyslab.platform.openmedia.protocol.externalservice.event.Event3rdServerFault;
import com.genesyslab.platform.openmedia.protocol.externalservice.event.Event3rdServerResponse;
import com.genesyslab.platform.commons.protocol.Message;
import com.genesyslab.platform.commons.protocol.Endpoint;
import com.genesyslab.platform.commons.protocol.Referenceable;
import com.genesyslab.platform.commons.protocol.RequestContext;
import com.genesyslab.platform.commons.protocol.WildcardEndpoint;
import com.genesyslab.platform.commons.protocol.ProtocolException;
import com.genesyslab.platform.commons.protocol.ClientRequestHandler;
import com.genesyslab.platform.commons.collections.KeyValueCollection;
public class testESP {
public static void main(final String[] args)
throws ProtocolException, IllegalStateException, InterruptedException {
final int PORT = 11111;
final ExternalServiceProtocolListener server = new ExternalServiceProtocolListener(new WildcardEndpoint(PORT));
server.setClientRequestHandler(new ClientRequestHandler() {
public void processRequest(final RequestContext requestContext) {
Message msg = requestContext.getRequestMessage();
Message response = null;
Object refId = null;
if (msg instanceof Referenceable) {
refId = ((Referenceable) msg).retreiveReference();
}
if (msg != null && msg.messageId() == Request3rdServer.ID) {
Request3rdServer request = (Request3rdServer) msg;
KeyValueCollection request_data = request.getUserData();
String cmd = request_data.getString("cmd");
if (cmd != null) {
if (cmd.contentEquals("How are you?")) {
Event3rdServerResponse event = Event3rdServerResponse.create();
KeyValueCollection resp_data = new KeyValueCollection();
resp_data.addString("result", "fine");
event.setUserData(resp_data);
response = event;
}
}
if (response == null) {
KeyValueCollection resp_data = new KeyValueCollection();
resp_data.addString("info", "unknown request");
resp_data.addList("reuqest", request_data);
Event3rdServerFault event = Event3rdServerFault.create(resp_data);
response = event;
}
}
if (response != null) {
if (refId != null && response instanceof Referenceable) {
((Referenceable) response).updateReference(refId);
}
try {
requestContext.respond(response);
} catch (final ProtocolException e) {
e.printStackTrace();
}
}
}
});
server.open();
ExternalServiceProtocol client = new ExternalServiceProtocol(new Endpoint("localhost", PORT));
client.open();
Request3rdServer request = Request3rdServer.create();
KeyValueCollection data = new KeyValueCollection();
data.addString("cmd", "How are you?");
request.setUserData(data);
Message response = client.request(request);
if (response != null) {
switch (response.messageId()) {
case Event3rdServerResponse.ID: {
KeyValueCollection resp_data = ((Event3rdServerResponse) response).getUserData();
System.out.println("result: " + resp_data.getString("result"));
break;
}
case Event3rdServerFault.ID: {
KeyValueCollection resp_data = ((Event3rdServerFault) response).getRequest();
System.out.println("fail: " + resp_data);
break;
}
default:
//...
}
}
// ...
client.close();
server.close();
}
}
Note, that ServerChannel
adds ADDP support for incoming connections by default, if no protocol name option is specified.
The AddpInterceptor.ACTIVE_KEY
option always set to false, because it is client channel responsibility to initiate ADDP.AbstractChannel.AsyncErrorNotifier
DEFAULT_TIMEOUT, INFINITE_TIMEOUT
DEF_INPUT_SIZE
Constructor | Description |
---|---|
ExternalServiceProtocolListener(Endpoint endpoint) |
|
ExternalServiceProtocolListener(Endpoint endpoint,
long timeout) |
addChannelListener, configure, connectionContext, copyTLSSettings, createChannelClosedEvent, fireClosed, fireErrorEvent, fireErrorEvent, generateChannelId, getChannelId, getConfiguration, getDefaultInvoker, getEndpoint, getEnpointPrefixInfo, getInvoker, getListenerHelper, getLocalEndpointInfo, getServerContext, getState, getStateMods, getTimeout, getTimer, internal, onFireClosed, onFireErrorEvent, onFireOpened, onSetEndpoint, releaseDefaultInvoker, removeChannelListener, setConfiguration, setConnectionInvoker, setEndpoint, setInvoker, setServerContext, setState, setState, setTimeout, throwNotClosed, throwNotOpened, throwNotOpenedOnClose, throwNotOpenedOnSend, throwNull, throwNullEndpoint
getState
getTimeout, setTimeout
addChannelListener, removeChannelListener
configure, getConfiguration
getEndpoint, setEndpoint
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addListener, applyConfiguration, beginClose, beginOpen, clearInput, close, close, closeClientChannels, closeListener, getChannels, getInputSize, getLocalEndPoint, getProtocolDescription, getProtocolFactory, modifyNewChannel, open, open, receive, receive, receiveRequest, receiveRequest, releaseReceivers, removeListener, resetReceiver, send, sendToChannelsExcept, sendToChannelsExcept, setClientRequestHandler, setInputSize, setReceiver
Send comments on this topicTechpubs.webadmin@genesys.com.
Document version: 9.0.006.00
Copyright © 2006–2019 Genesys Telecommunications Laboratories, Inc. All rights reserved.