public static void main(String[] args) throws Exception{
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpHost target = new HttpHost("ADRESSE", 80, "http");
HttpEntity entity = null;
HttpPost req = new HttpPost("WEBSERVICE");
String username = "USERNAME";
String password = "PASSWORD";
String authorizationHeaderValue = username + ":" + password;
BASE64Encoder encoder = new BASE64Encoder();
authorizationHeaderValue = "Basic " + encoder.encode(authorizationHeaderValue.getBytes());
Header authorizationHeader = new BasicHeader("Authorization", authorizationHeaderValue);
req.addHeader(authorizationHeader);
String soapActionHeaderValue = "http.....................";
Header soapActionHeader = new BasicHeader("SOAPAction", soapActionHeaderValue);
req.addHeader(soapActionHeader);
InputStream is = com.generali.test.Main.class.getClassLoader().getResourceAsStream("templateRequest");
String templateString = IOUtils.toString(is, "UTF-8");
FileFilter filter = new FileNameExtensionFilter("Excel-Datei", "xls");
// JFileChooser zum öffnen einer bestimmten Excel-Tabelle
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("D:/"));
chooser.addChoosableFileFilter(filter);
chooser.showOpenDialog(null);
Workbook workbook = Workbook.getWorkbook(chooser.getSelectedFile());
Sheet sheet = workbook.getSheet(0);
//Geht das Excel Dokument durch und nimmt die Werte aus der ersten und dritten Spalte...
for (int i = 3; i < sheet.getRows(); i++) {
// ...solange es Zeilen im Excel Dokument gibt
List<AbfrageObjekt> objekte = new ArrayList<AbfrageObjekt>();
AbfrageObjekt ao = new AbfrageObjekt();
// Wenn die VorgangsID in der 1.Spalten liegt
ao.setVorgangsID(sheet.getCell(0, i));
ao.setSchluessel(sheet.getCell(2, i));
objekte.add(ao);
// Übergibt die Werte an hisVorgangsIdentifikation und referenzschluesselMeldung
Cell hisVorgangsIdentifikation = ao.getVorgangsID();
Cell referenzschluesselMeldung = ao.getSchluessel();
String HisVorgangsIdentifikation = hisVorgangsIdentifikation.getContents();
String ReferenzschluesselMeldung = referenzschluesselMeldung.getContents();
System.out.println("|||||||||||||||||||||||||||||||||||||||||||||||||||");
System.out.println("ID lautet: " + HisVorgangsIdentifikation + " Schlüssel lautet: " + ReferenzschluesselMeldung );
System.out.println("|||||||||||||||||||||||||||||||||||||||||||||||||||");
String referenzschluesselLoeschung = "L1";
String content = MessageFormat.format(templateString, HisVorgangsIdentifikation, ReferenzschluesselMeldung, referenzschluesselLoeschung);
StringEntity stringEntity = new StringEntity(content);
stringEntity.setContentType("application/xml");
req.setEntity(stringEntity);
entity = req.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
System.out.println("executing request to " + target);
HttpResponse rsp = httpclient.execute(target, req);
System.out.println("----------------------------------------");
System.out.println(rsp.getStatusLine());
Header[] headers = rsp.getAllHeaders();
for (int j = 0; j < headers.length; j++) {
System.out.println(headers[j]);
}
System.out.println("----------------------------------------");
entity = rsp.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
//JOptionPane.showMessageDialog(null, "Die Objekte wurden erfolgreich gelöscht !");
httpclient.getConnectionManager().shutdown();
}
}
}