use of de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException in project janrufmonitor by tbrandt77.
the class FritzOS559Firmware method getCallerList.
public List getCallerList(int id, String name) throws GetCallerListException, IOException {
if (!this.isInitialized())
throw new GetCallerListException("Could not get phone book from FritzBox: FritzBox firmware not initialized.");
InputStream in = null;
try {
in = this.getCallerListAsStream(Integer.toString(id), name);
} catch (IOException e) {
throw new GetCallerListException(e.getMessage());
}
if (in == null)
return new ArrayList(0);
List result = new ArrayList();
StringBuffer xml = new StringBuffer();
String encoding = (is600 ? "utf-8" : "iso-8859-1");
InputStreamReader inr = new InputStreamReader(in, encoding);
BufferedReader bufReader = new BufferedReader(inr);
// drop header
String line = bufReader.readLine();
while (bufReader.ready()) {
line = bufReader.readLine();
xml.append(line + " ");
}
bufReader.close();
in.close();
result.addAll(parseXML(xml, name));
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Phonebook from FritzBox succuessfully fetched. List size: " + result.size());
return result;
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException in project janrufmonitor by tbrandt77.
the class FritzOS559Firmware method getCallerListAsStream.
private InputStream getCallerListAsStream(String pb_id, String pb_name) throws GetCallerListException, IOException {
long start = System.currentTimeMillis();
this.m_logger.info("Starting retrieving phone book...");
// The list should be updated now
// Get the csv file for processing
String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/firmwarecfg";
URL url;
URLConnection urlConn;
DataOutputStream printout;
try {
this.m_logger.info("Calling FritzBox URL: " + urlstr);
url = new URL(urlstr);
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new GetCallerListException("Invalid URL: " + urlstr);
}
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
// Sending postdata to the fritz box
urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7dc2fd11290438");
printout = new DataOutputStream(urlConn.getOutputStream());
StringBuffer sb = new StringBuffer();
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"sid\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(this.m_sid + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookId\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(pb_id + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookExportName\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(pb_name + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookExport\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438--" + IJAMConst.CRLF);
printout.writeBytes(sb.toString());
printout.flush();
printout.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e2) {
this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
}
try {
// Get response data from the box
ByteArrayOutputStream bos = new ByteArrayOutputStream();
this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
Stream.copy(urlConn.getInputStream(), bos);
ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
// this.m_logger.info(bos.toString());
this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
urlConn.getInputStream().close();
return bin;
} catch (IOException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
throw new GetCallerListException(e1.getMessage());
}
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException in project janrufmonitor by tbrandt77.
the class FritzOSFirmware method getCallerList.
public List getCallerList(int id, String name) throws GetCallerListException, IOException {
if (!this.isInitialized())
throw new GetCallerListException("Could not get phone book from FritzBox: FritzBox firmware not initialized.");
InputStream in = null;
try {
in = this.getCallerListAsStream(Integer.toString(id), name);
} catch (IOException e) {
throw new GetCallerListException(e.getMessage());
}
if (in == null)
return new ArrayList(0);
List result = new ArrayList();
StringBuffer xml = new StringBuffer();
InputStreamReader inr = new InputStreamReader(in, "iso-8859-1");
BufferedReader bufReader = new BufferedReader(inr);
// drop header
String line = bufReader.readLine();
while (bufReader.ready()) {
line = bufReader.readLine();
xml.append(line + " ");
}
bufReader.close();
in.close();
result.addAll(parseXML(xml, name));
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Phonebook from FritzBox succuessfully fetched. List size: " + result.size());
return result;
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException in project janrufmonitor by tbrandt77.
the class FritzOSFirmware method getCallerListAsStream.
private InputStream getCallerListAsStream(String pb_id, String pb_name) throws GetCallerListException, IOException {
long start = System.currentTimeMillis();
this.m_logger.info("Starting retrieving phone book...");
// The list should be updated now
// Get the csv file for processing
String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/firmwarecfg";
URL url;
URLConnection urlConn;
DataOutputStream printout;
try {
this.m_logger.info("Calling FritzBox URL: " + urlstr);
url = new URL(urlstr);
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new GetCallerListException("Invalid URL: " + urlstr);
}
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
// Sending postdata to the fritz box
urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7dc2fd11290438");
printout = new DataOutputStream(urlConn.getOutputStream());
StringBuffer sb = new StringBuffer();
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"sid\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(this.m_sid + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookId\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(pb_id + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookExportName\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(pb_name + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookExport\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438--" + IJAMConst.CRLF);
printout.writeBytes(sb.toString());
printout.flush();
printout.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e2) {
this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
}
try {
// Get response data from the box
ByteArrayOutputStream bos = new ByteArrayOutputStream();
this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
Stream.copy(urlConn.getInputStream(), bos);
ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
// this.m_logger.info(bos.toString());
this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
urlConn.getInputStream().close();
return bin;
} catch (IOException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
throw new GetCallerListException(e1.getMessage());
}
}
use of de.janrufmonitor.fritzbox.firmware.exception.GetCallerListException in project janrufmonitor by tbrandt77.
the class UnitymediaFirmware method getCallerListAsStream.
private InputStream getCallerListAsStream(String pb_id, String pb_name) throws GetCallerListException, IOException {
long start = System.currentTimeMillis();
this.m_logger.info("Starting retrieving phone book...");
// The list should be updated now
// Get the csv file for processing
String urlstr = getProtocol() + this.m_address + ":" + this.m_port + "/cgi-bin/firmwarecfg";
URL url;
URLConnection urlConn;
DataOutputStream printout;
try {
this.m_logger.info("Calling FritzBox URL: " + urlstr);
url = new URL(urlstr);
} catch (MalformedURLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new GetCallerListException("Invalid URL: " + urlstr);
}
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
// Sending postdata to the fritz box
urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=---------------------------7dc2fd11290438");
printout = new DataOutputStream(urlConn.getOutputStream());
StringBuffer sb = new StringBuffer();
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"sid\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(this.m_sid + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookId\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(pb_id + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookExportName\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(pb_name + IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438" + IJAMConst.CRLF);
sb.append("Content-Disposition: form-data; name=\"PhonebookExport\"" + IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append("-----------------------------7dc2fd11290438--" + IJAMConst.CRLF);
printout.writeBytes(sb.toString());
printout.flush();
printout.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e2) {
this.m_logger.log(Level.SEVERE, e2.getMessage(), e2);
}
try {
// Get response data from the box
ByteArrayOutputStream bos = new ByteArrayOutputStream();
this.m_logger.info("Fetching call list from FritzBox took " + (System.currentTimeMillis() - start) + "ms");
Stream.copy(urlConn.getInputStream(), bos);
ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
// this.m_logger.info(bos.toString());
this.m_logger.info("Finished retrieving call list took " + (System.currentTimeMillis() - start) + "ms");
urlConn.getInputStream().close();
return bin;
} catch (IOException e1) {
this.m_logger.log(Level.SEVERE, e1.getMessage(), e1);
throw new GetCallerListException(e1.getMessage());
}
}
Aggregations