Danke
Falls es jemand interessiert, hier der ziemlich rohe jakarta httpClient code, falls jemand was damit anfangen kann:
Geht wesentlich einfacher. Sind ein paar Experimente drin und unnötiges. Korrigiere das später.
Jedenfalls kommt man so durch:
1. Reverse Proxy in Firma
2. Authentifizierungsrequest von WebMail Server.
3. Serverseitiges SSL ist für httpClient völlig transparent. Wir haben nur einen internen Zugang von innen. Fürs Testen spare ich mir dann das rumhampeln mit dem "das SSL-Zertifikat der VM bekannt machen".
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.util.EncodingUtil;
import de.img.network.util.ReverseProxyBean;
import de.img.network.util.WebRetrievalException;
public class MyMail {
private HttpClient client;
private ReverseProxyBean reverseProxyBean;
private String urlMyMail = "http://x.x.x.x/mail/ajanssen.nsf/($All)/doUnid?open&ui=webmail";
//private String urlMyMail = "http://x.x.x.x/mail/ajanssen.nsf/($ApptUNID)/";
//private String urlMyMail = "http://x.x.x.x/mail/ajanssen.nsf/iNotes/Mail/?OpenDocument&PresetFields=s_ViewLabel;Eingang,s_ViewName;(%24Inbox)&KIC&UNH=8s21349e0gh7ouk65g4v0ns0bvk";
private byte[] responseBody = null;
public MyMail () {
client = new HttpClient();
setReverseProxyBean (new ReverseProxyBean());
}
public void setReverseProxyBean(ReverseProxyBean myReverseProxyBean) {
// depency injection "The Ramones"-way :-)
reverseProxyBean = myReverseProxyBean;
reverseProxyBean.setProxyHost("x.x.x.x");
reverseProxyBean.setProxyPort(8080);
reverseProxyBean.setProxyUsername("name");
reverseProxyBean.setProxyPassword("password");
}
/**
* Retrieves the historic exchange rates from a webservice of the european central banks and writes them to a database.
* @throws WebRetrievalException
*/
public void readMyMail() throws WebRetrievalException {
buildRequestHeader();
GetMethod get = new GetMethod(urlMyMail);
try {
InputStream is = downloadXml(get);
String responseCharSet = get.getResponseCharSet();
System.out.println("responseCharSet=" + responseCharSet);
ByteArrayOutputStream outstream = new ByteArrayOutputStream(
get.getResponseContentLength()> 0 ? (int) get.getResponseContentLength() : 4 * 1024);
byte[] buffer = new byte[4096];
int len;
while ((len = is.read(buffer)) > 0) {
outstream.write(buffer, 0, len);
}
outstream.close();
this.responseBody = outstream.toByteArray();
String val = EncodingUtil.getString(responseBody, responseCharSet);
System.out.println("val=" + val);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* user credentials for proxy and service server.
*/
private void buildRequestHeader() {
client.getParams().setAuthenticationPreemptive(true);
client.getHostConfiguration().setProxy(reverseProxyBean.getProxyHost(), reverseProxyBean.getProxyPort());
Credentials credsProxy = new UsernamePasswordCredentials(
reverseProxyBean.getProxyUsername(),
reverseProxyBean.getProxyPassword());
client.getState().setProxyCredentials(AuthScope.ANY, credsProxy);
Credentials defaultcreds = new UsernamePasswordCredentials(
"nameServer", "pwdServer");
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
// client.getState().setCredentials(AuthScope.ANY, defaultcreds);
}
private InputStream downloadXml(GetMethod get) throws WebRetrievalException {
String errMsg = "";
try {
client.executeMethod(get);
if (get.getStatusCode() != 200) {
errMsg = "Die URL ist nicht erreichbar:" + get + ". (http-Statuscode=" + get.getStatusCode();
throw new WebRetrievalException(errMsg);
}
return get.getResponseBodyAsStream();
}
catch (Exception e) {
throw new WebRetrievalException("Die URL ist nicht erreichbar:" + get, e);
}
}
public static void main (String [] ars) {
try {
MyMail myMail = new MyMail();
myMail.readMyMail();
System.out.println(myMail.responseBody);
} catch (Exception e) {
e.printStackTrace();
}
}
}