Search in sources :

Example 1 with SimplePortListener

use of de.janrufmonitor.service.commons.http.simple.SimplePortListener in project janrufmonitor by tbrandt77.

the class Client method connect.

public synchronized boolean connect() {
    if (this.isConnected)
        return true;
    this.m_httpSrv = new SimplePortListener(new ClientHandler(), this.getListenPort());
    this.m_httpSrv.start();
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        this.m_logger.severe(e.getMessage());
    }
    // register client at server
    if (this.m_httpSrv != null) {
        try {
            IHttpRequest rq = new RegisterGetHandler(InetAddress.getLocalHost().getHostName(), InetAddress.getLocalHost().getHostAddress(), this.m_httpSrv.getPort(), this.getRegisterEvents());
            try {
                this.m_logger.info("Connecting to server with URI: " + rq.getURI());
            } catch (Exception e1) {
                this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
            }
            IRequester r = RequesterFactory.getInstance().createRequester(rq);
            r.request();
            int responseCode = r.request().getCode();
            if (responseCode == 200) {
                this.isConnected = true;
                this.m_logger.info("Registration of client " + this.m_httpSrv.getServerIP() + " successfull.");
                this.m_logger.info("Client is started and connected with server ...");
                ClientStateManager.getInstance().fireState(IClientStateMonitor.CONNECTION_OK, "");
                return true;
            }
            if (responseCode == 0) {
                this.m_logger.severe("Registration of client " + this.m_httpSrv.getServerIP() + " failed. Server not reachable.");
                ClientStateManager.getInstance().fireState(IClientStateMonitor.SERVER_NOT_FOUND, "Server: " + r.getServer() + "\nPort: " + r.getPort());
            }
            if (responseCode == 403) {
                this.m_logger.severe("Client " + InetAddress.getLocalHost().getHostName() + " (" + InetAddress.getLocalHost().getHostAddress() + ") is not authorized to connect to server: " + r.getServer());
                ClientStateManager.getInstance().fireState(IClientStateMonitor.SERVER_NOT_AUTHORIZED, "Client " + InetAddress.getLocalHost().getHostName() + " (" + InetAddress.getLocalHost().getHostAddress() + ") is not authorized to connect to server: " + r.getServer());
            }
            this.m_logger.severe("Response code from server was not OK: " + responseCode);
        } catch (UnknownHostException e) {
            this.m_logger.severe(e.getMessage());
            ClientStateManager.getInstance().fireState(IClientStateMonitor.SERVER_NOT_FOUND, e.getMessage());
        }
        this.m_httpSrv.stop();
        this.m_httpSrv = null;
    }
    return false;
}
Also used : IHttpRequest(de.janrufmonitor.service.commons.http.IHttpRequest) UnknownHostException(java.net.UnknownHostException) SimplePortListener(de.janrufmonitor.service.commons.http.simple.SimplePortListener) ClientHandler(de.janrufmonitor.service.client.http.simple.ClientHandler) IRequester(de.janrufmonitor.service.commons.http.IRequester) UnknownHostException(java.net.UnknownHostException)

Example 2 with SimplePortListener

use of de.janrufmonitor.service.commons.http.simple.SimplePortListener in project janrufmonitor by tbrandt77.

the class Server method startup.

public void startup() {
    super.startup();
    this.m_httpSrv = new SimplePortListener(new ServerHandler(), this.getListenPort());
    IEventBroker eventBroker = this.getRuntime().getEventBroker();
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_INCOMINGCALL));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLACCEPTED));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLCLEARED));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_CALLREJECTED));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_MANUALCALLACCEPTED));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_APPLICATION_READY));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_IDENTIFIED_CALL));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_IDENTIFIED_OUTGOING_CALL));
    eventBroker.register(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_OUTGOINGCALL));
    // start HTTP Server
    this.m_httpSrv.start();
    this.m_logger.info("Server is started ...");
}
Also used : SimplePortListener(de.janrufmonitor.service.commons.http.simple.SimplePortListener) ServerHandler(de.janrufmonitor.service.server.http.simple.ServerHandler) IEventBroker(de.janrufmonitor.framework.event.IEventBroker)

Aggregations

SimplePortListener (de.janrufmonitor.service.commons.http.simple.SimplePortListener)2 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)1 ClientHandler (de.janrufmonitor.service.client.http.simple.ClientHandler)1 IHttpRequest (de.janrufmonitor.service.commons.http.IHttpRequest)1 IRequester (de.janrufmonitor.service.commons.http.IRequester)1 ServerHandler (de.janrufmonitor.service.server.http.simple.ServerHandler)1 UnknownHostException (java.net.UnknownHostException)1