Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

commons-HttpClient und https

Empfohlene Antworten

Veröffentlicht

Hallo ihr lieben Mitenwtickler,

Ich hab hier mal ein für mich etwas kniffliges Problem:

Ich muss den "Apacha HttpClient" auch "Jakarta commons-HttpClient" verwenden um einen Server und das darauf befindliche Servlet anzustossen.

Bisher tue ich das mit dem Http-Protokol und alles klappt wunderbar.

Mein Quellcode dazu:


HttpClient httpClient = new HttpClient();

GetMethod httpGetMethod = new GetMethod("http://"+args[0]+"/ats_app/Batch?APPLICATION_NAME=amisats&bensl="+args[1]+"&BATCH_CONTROLLER=de.allianz.ats." + batchControllerString  + "&BATCH_CONFIG_FILE=" + konfigfileString);

try {

	[B]int statusCode = httpClient.executeMethod(httpGetMethod);[/B]

	if (statusCode != HttpStatus.SC_OK) {

		System.out.println("ServletCaller Ergebnis: Fehlgeschlagen wegen: " + 	httpGetMethod.getStatusLine());

	}


	String responseBodyString = new String(httpGetMethod.getResponseBody());

	if (responseBodyString.indexOf(REQUEST_ERROR) > -1) {

		returnCode = RETURNCODE_ERROR; 

		System.out.println("ServletCaller Ergebnis: Error");

	}

	else if (responseBodyString.indexOf(REQUEST_OK) > -1) {

		returnCode = RETURNCODE_OK;

		System.out.println("ServletCaller Ergebnis: OK");

	}

}

catch(Exception e) {

	returnCode = RETURNCODE_ERROR;

	System.out.println("ServletCaller Exception: " + e); 

	System.out.println("ServletCaller Ergebnis: Error: " + e.getMessage());

}

finally {

	httpGetMethod.releaseConnection();

	System.exit(returnCode);

}

Nun soll ich aber das Https Protocol verwenden und den Get somit verschlüsselt absetzen.

Hat von euch einer schon sowas gemacht?

Ich hab dazu mehrere Begriffe gehört: "Truststore", "Keystore"

Aber weis leider nicht wie ich das einsetzen muss.

Bin für jede Hilfe dankbar auch wenns nur Hinweise in die richtige Richtung sind :-)

Protocol https = new Protocol("https", (ProtocolSocketFactory) newEasySSLProtocolSocketFactory(), 443);

Protocol.registerProtocol("https", https);

HttpClient client = new HttpClient();

So sieht bei mir der anfang aus und damit gehts (rest ist gleich).(habe es aber nur für "Post" gemacht, sollte aber trotzdem gehen) Auf der http://jakarta.apache.org/

sind aber gute Bsp. (im bereich commons) hätte auch das pasende rausgesucht aber die seite ist gerade nicht erreichbar.

Hoffe es hilft weiter

Danke für die nette Antwort.

Hab aber noch ne Frage dazu:

Was liefert die Funktion "newEasySSLProtocolSocketFactory" denn bei dir, bzw. wie sieht die denn aus ... sonst hilft mir das Beispiel nämlich erstmal nicht soviel.

Werd aber noch die Jakarta Seite weiter durchforsten.

AHHH habs gefunden

da fehlte nur das Leerzeichen ;-)

sollte new Easy...() heissen

Aber wenn du noch weisst welches Bsp das war wär ich dir höllisch dankbar.:)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.