Search in sources :

Example 1 with IRequester

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);
}
Also used : IRequester(de.janrufmonitor.service.commons.http.IRequester) IHttpResponse(de.janrufmonitor.service.commons.http.IHttpResponse) CallerListRemoveHandler(de.janrufmonitor.service.client.request.handler.CallerListRemoveHandler)

Example 2 with IRequester

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();
}
Also used : CallerListGetHandler(de.janrufmonitor.service.client.request.handler.CallerListGetHandler) ICallerList(de.janrufmonitor.framework.ICallerList) IRequester(de.janrufmonitor.service.commons.http.IRequester) IHttpResponse(de.janrufmonitor.service.commons.http.IHttpResponse)

Example 3 with IRequester

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.");
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IRequester(de.janrufmonitor.service.commons.http.IRequester) CallerGetHandler(de.janrufmonitor.service.client.request.handler.CallerGetHandler) IHttpResponse(de.janrufmonitor.service.commons.http.IHttpResponse)

Example 4 with IRequester

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();
}
Also used : IRequester(de.janrufmonitor.service.commons.http.IRequester) UnknownHostException(java.net.UnknownHostException)

Example 5 with IRequester

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;
}
Also used : IHttpRequest(de.janrufmonitor.service.commons.http.IHttpRequest) MalformedURLException(java.net.MalformedURLException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) GetImageHandler(de.janrufmonitor.service.client.request.handler.GetImageHandler) IRequester(de.janrufmonitor.service.commons.http.IRequester) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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