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;
}
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;
}
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 "";
}
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);
}
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);
}
Aggregations