Search in sources :

Example 16 with IRequester

use of de.janrufmonitor.service.commons.http.IRequester 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 17 with IRequester

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

the class Client method disconnect.

public synchronized boolean disconnect() {
    if (!this.isConnected)
        return true;
    // unregister client at server
    if (this.m_httpSrv != null) {
        try {
            IRequester r = RequesterFactory.getInstance().createRequester(new UnregisterGetHandler(InetAddress.getLocalHost().getHostName(), InetAddress.getLocalHost().getHostAddress(), this.m_httpSrv.getPort()));
            int responseCode = r.request().getCode();
            if (responseCode == 200) {
                this.m_logger.info("Unregistration of client " + this.m_httpSrv.getServerIP() + " successfull.");
            }
            if (responseCode == 0)
                this.m_logger.severe("Unregistration of client " + this.m_httpSrv.getServerIP() + " failed. Server not reachable.");
            if (responseCode == 403)
                this.m_logger.severe("Client " + this.m_httpSrv.getServerIP() + " was rejected by the server. Client is not allowd to connect to server.");
        } catch (UnknownHostException e) {
            this.m_logger.severe(e.getMessage());
        }
        this.isConnected = false;
        this.m_httpSrv.stop();
        this.m_httpSrv = null;
    }
    return true;
}
Also used : UnknownHostException(java.net.UnknownHostException) IRequester(de.janrufmonitor.service.commons.http.IRequester)

Example 18 with IRequester

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

the class HttpImageProvider method getImagePath.

public String getImagePath(ICaller caller) {
    if (caller.getPhoneNumber().isClired())
        return "";
    if (!hasImage(caller))
        return "";
    try {
        IHttpRequest cgh = new GetImageHandler(caller.getPhoneNumber(), this.m_cm);
        IRequester r = this.getRequester(cgh);
        return "http://" + r.getServer() + ":" + r.getPort() + cgh.getURI().toString();
    } catch (MalformedURLException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (Exception e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return "";
}
Also used : IHttpRequest(de.janrufmonitor.service.commons.http.IHttpRequest) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) GetImageHandler(de.janrufmonitor.service.client.request.handler.GetImageHandler) IRequester(de.janrufmonitor.service.commons.http.IRequester) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 19 with IRequester

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

the class HttpCallManager method removeCalls.

public void removeCalls(ICallList calllist) {
    if (!this.isConnected()) {
        this.m_logger.warning("Client is not yet connected with the server.");
        return;
    }
    IRequester r = this.getRequester(new CallListRemoveHandler(calllist, this.getCallManager()));
    IHttpResponse resp = r.request();
    this.handleRequester(resp, r);
}
Also used : IRequester(de.janrufmonitor.service.commons.http.IRequester) CallListRemoveHandler(de.janrufmonitor.service.client.request.handler.CallListRemoveHandler) IHttpResponse(de.janrufmonitor.service.commons.http.IHttpResponse)

Example 20 with IRequester

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

the class HttpCallManager method getCallCount.

public int getCallCount(IFilter[] filters, ISearchTerm[] searchTerms) {
    if (!this.isConnected()) {
        this.m_logger.warning("Client is not yet connected with the server.");
        return 0;
    }
    IRequester r = this.getRequester(new CallListCountGetHandler(this.getCallManager(), filters, searchTerms));
    IHttpResponse resp = r.request();
    String xml = this.getXmlContent(resp);
    this.handleRequester(resp, r);
    if (xml.length() > 0) {
        return Integer.parseInt(xml);
    }
    return super.getCallCount(filters);
}
Also used : CallListCountGetHandler(de.janrufmonitor.service.client.request.handler.CallListCountGetHandler) IRequester(de.janrufmonitor.service.commons.http.IRequester) IHttpResponse(de.janrufmonitor.service.commons.http.IHttpResponse)

Aggregations

IRequester (de.janrufmonitor.service.commons.http.IRequester)21 IHttpResponse (de.janrufmonitor.service.commons.http.IHttpResponse)14 UnknownHostException (java.net.UnknownHostException)4 ICallerList (de.janrufmonitor.framework.ICallerList)3 GetDialExtensions (de.janrufmonitor.service.client.request.handler.GetDialExtensions)3 IHttpRequest (de.janrufmonitor.service.commons.http.IHttpRequest)3 IOException (java.io.IOException)3 CallerListGetHandler (de.janrufmonitor.service.client.request.handler.CallerListGetHandler)2 GetImageHandler (de.janrufmonitor.service.client.request.handler.GetImageHandler)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 Message (de.janrufmonitor.exception.Message)1 ICall (de.janrufmonitor.framework.ICall)1 ICallList (de.janrufmonitor.framework.ICallList)1 ICaller (de.janrufmonitor.framework.ICaller)1 IMsn (de.janrufmonitor.framework.IMsn)1 ClientHandler (de.janrufmonitor.service.client.http.simple.ClientHandler)1 CallListCountGetHandler (de.janrufmonitor.service.client.request.handler.CallListCountGetHandler)1 CallListGetHandler (de.janrufmonitor.service.client.request.handler.CallListGetHandler)1