use of de.janrufmonitor.service.commons.http.IRequester in project janrufmonitor by tbrandt77.
the class HttpCallerManager method removeCaller.
public void removeCaller(ICallerList callerList) {
if (!this.isConnected()) {
this.m_logger.warning("Client is not yet connected with the server.");
return;
}
IRequester r = null;
IHttpResponse resp = null;
r = this.getRequester(new CallerListRemoveHandler(callerList, this.getCallerManager()));
resp = r.request();
this.handleRequester(resp, r);
}
use of de.janrufmonitor.service.commons.http.IRequester in project janrufmonitor by tbrandt77.
the class HttpCallerManager method getCallers.
public ICallerList getCallers(IFilter filter) {
if (!this.isConnected()) {
this.m_logger.warning("Client is not yet connected with the server.");
return this.getRuntime().getCallerFactory().createCallerList();
}
if (filter != null) {
return this.getCallers(new IFilter[] { filter });
}
this.m_logger.info("No filter is applied.");
IRequester r = this.getRequester(new CallerListGetHandler(this.getCallerManager()));
IHttpResponse resp = r.request();
String xml = this.getXmlContent(resp);
this.handleRequester(resp, r);
ICallerList l = XMLSerializer.toCallerList(xml);
if (l != null) {
this.addCallerManagerAttribute(l);
return l;
}
this.m_logger.warning("Callerlist from remote host was empty.");
return this.getRuntime().getCallerFactory().createCallerList();
}
use of de.janrufmonitor.service.commons.http.IRequester in project janrufmonitor by tbrandt77.
the class HttpCallerManager method getCaller.
public ICaller getCaller(IPhonenumber number) throws CallerNotFoundException {
if (!this.isConnected()) {
this.m_logger.warning("Client is not yet connected with the server.");
throw new CallerNotFoundException("No caller found. Client is not yet connected with the server.");
}
IRequester r = this.getRequester(new CallerGetHandler(number, this.getCallerManager()));
IHttpResponse resp = r.request();
String xml = this.getXmlContent(resp);
this.handleRequester(resp, r);
ICaller c = XMLSerializer.toCaller(xml);
if (c != null) {
return c;
}
throw new CallerNotFoundException("no caller found.");
}
use of de.janrufmonitor.service.commons.http.IRequester in project janrufmonitor by tbrandt77.
the class Client method sendRequest.
private void sendRequest(int event, IHttpRequest request) {
try {
this.m_logger.info("Sending request to server: " + request.getURI());
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
IRequester req = RequesterFactory.getInstance().createRequester(request);
req.request();
}
use of de.janrufmonitor.service.commons.http.IRequester in project janrufmonitor by tbrandt77.
the class HttpImageProvider method getImage.
public File getImage(ICaller caller) {
if (caller.getPhoneNumber().isClired())
return null;
File cacheFile = (File) ImageCache.getInstance().get(caller.getPhoneNumber().getTelephoneNumber());
if (cacheFile != null) {
this.m_logger.info("Taking image file from cache: " + cacheFile.getName());
return cacheFile;
}
try {
IHttpRequest cgh = new GetImageHandler(caller.getPhoneNumber(), this.m_cm);
IRequester r = this.getRequester(cgh);
InputStream in = new BufferedInputStream(r.request().getContentStreamForRead());
File tmpOut = new File(PathResolver.getInstance().getTempDirectory() + "~images" + File.separator + caller.getPhoneNumber().getTelephoneNumber() + this.getExtension("image/jpeg"));
if (!tmpOut.exists()) {
tmpOut.getParentFile().mkdirs();
tmpOut.createNewFile();
}
FileOutputStream fos = new FileOutputStream(tmpOut);
Stream.copy(in, fos);
in.close();
fos.flush();
fos.close();
ImageCache.getInstance().add(caller.getPhoneNumber().getTelephoneNumber(), tmpOut);
return tmpOut;
} 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 (NullPointerException e) {
this.m_logger.log(Level.WARNING, e.getMessage(), e);
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
Aggregations