Domino 9 und frühere Versionen > ND6: Entwicklung
existiert die URL ???
eknori (retired):
Hab dann hier auch noch eine Lösung in Script ( mit API ).
Hier kann man auch recht eindrucksvoll sehen, wie einfach man das in Java lösen kann und welche Klimmzüge man machen muß, um eine Lösung in Script hinzubekommen.
Zwar kann ich bei meiner Lösung noch ein paar Informationen mehr auslesen, da ich mir den responseHeader von der URL hole. Trotzdem fehlt hier noch die komplette Logig, um erst einmal an das zu prüfende Dokument ranzukommen.
Zudem muß dann noch die zu testende URL aufbereitet werden, um an die Funktion übergeben werden zu können. ( Kann man mit Sicherheit noch vereinfachen )
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_SERVICE_HTTP = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const INTERNET_DEFAULT_HTTP_PORT = 80
Const HTTP_QUERY_RAW_HEADERS_CRLF = 22
Declare Function W32_InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (Byval sAgent As String, Byval lAccessType As Long, Byval sProxyName As String, Byval sProxyBypass As String, Byval lFlags As Long) As Long
Declare Function W32_InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (Byval hInternetSession As Long, Byval sServerName As String, Byval nServerPort As Integer, Byval sUsername As String, Byval sPassword As String, Byval lService As Long, Byval lFlags As Long, Byval lContext As Long) As Long
Declare Function W32_InternetCloseHandle Lib "wininet.dll" Alias "InternetCloseHandle" (Byval hInet As Long) As Integer
Declare Function W32_HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" (Byval hHttpSession As Long, Byval sVerb As String, Byval sObjectName As String, Byval sVersion As String, Byval sReferer As String, Byval something As Long, Byval lFlags As Long, Byval lContext As Long) As Long
Declare Function W32_HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (Byval hHttpRequest As Long, Byval sHeaders As String, Byval lHeadersLength As Long, sOptional As Any, Byval lOptionalLength As Long) As Integer
Declare Function W32_HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (Byval hHttpRequest As Long, Byval lInfoLevel As Long, Byval sBuffer As String, lBufferLength As Long, lIndex As Long) As Integer
Function getResponseHeaders(sHost As String, sObject As String, sUserName As String, sPassword As String) As String
Dim rc%
Dim hSession&, hRequest&, hConnection&, cbHeaderBuf&
Dim headerBuf$
' initialize the WinInet API, retrieving any proxy or direct configuration info from the registry
hSession& = W32_InternetOpen("Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0)
If hSession& = 0 Then
Msgbox "Can't initialize Win32 Internet Functions (wininet.dll)", 16, "WinInet Error"
Else
' open an HTTP session for the site
hConnection& = W32_InternetConnect(hSession&, sHost, INTERNET_DEFAULT_HTTP_PORT, sUserName, sPassword, INTERNET_SERVICE_HTTP, 0, 0)
If hConnection& = 0 Then
Msgbox "Could not open HTTP session for site " & sHost, 16, "WinInet Error"
Else
' create a new HTTP request handle that will retrieve a resource from the server and not cache;
' note that you can also pass a POST request to upload info (see MS doc), or send an HTTP/1.0 request instead.
hRequest& = W32_HttpOpenRequest(hConnection&, "GET", sObject, "HTTP/1.1", 0, 0, INTERNET_FLAG_RELOAD, 0)
If hRequest& = 0 Then
Msgbox "Could not generate an HTTP request handle", 16, "WinInet Error"
Else
' send the request to the server with no additional headers (see MS doc to add your own headers)
rc%=W32_HttpSendRequest(hRequest&, "", 0, 0, 0)
If rc%=False Then
Msgbox "Could not send HTTP request", 16, "WinInet Error"
Else
' prepare a buffer for the response headers, then query 'em
headerBuf$=Space$(1024)
cbHeaderBuf&=Len(headerBuf$)
rc%=W32_HttpQueryInfo(hRequest&, HTTP_QUERY_RAW_HEADERS_CRLF, headerBuf$, cbHeaderBuf&, 0)
If rc% = 0 Then
Msgbox "Could not retrieve HTTP response headers", 16, "WinInet Error"
Else
' return the response headers on success
getResponseHeaders=Trim$(Left$(headerBuf$, cbHeaderBuf&))
End If
End If
End If
End If
End If
' close all handles
W32_InternetCloseHandle hRequest&
W32_InternetCloseHandle hSession&
W32_InternetCloseHandle hConnection&
End Function
Sub Click(Source As Button)
Dim sHeaders$, sHost$, sObject$
sHost$="www.google.de"
sObject$="search?q=eknori&hl=de&ie=UTF-8&oe=UTF-8"
sHeaders$=getResponseHeaders(sHost$, sObject$, "", "")
Msgbox "The HTTP response headers from " & sHost$ & " are: " _
& Chr(13) & Chr(10) & Chr(13) & Chr(10) _
& sHeaders$, 0, "HTTP Response Headers"
If Instr(sHeaders$,"200 OK") Then
Msgbox "URL OK"
Else
Msgbox "URL NICHT OK"
End If
End Sub
Axel_Janssen:
--- Zitat von: eknori am 02.07.03 - 07:39:19 ---[...] einfach man das in Java lösen kann und welche Klimmzüge man machen muß, um eine Lösung in Script hinzubekommen [...]
--- Ende Zitat ---
v.a. wenn der Server auf Linux umgestellt werden soll ;D ::) ;D
write everywhere, run again (oder so ähnlich)
fritandr:
Hallo,
stimmt, der Java Agent ist schön kurz ;D
Aber leider bekomme ich für jede Adresse, die ich prüfe auf der Java Console folgende Fehlermeldungen: :'(
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:345)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:157)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:144)
at java.net.Socket.<init>(Socket.java:294)
at java.net.Socket.<init>(Socket.java:121)
at sun.net.NetworkClient.doConnect(NetworkClient.java:65)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:356)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:543)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:291)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:301)
at sun.net.www.http.HttpClient.New(HttpClient.java:313)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:429)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:522)
at java.net.URL.openStream(URL.java:825)
at JavaAgent.NotesMain(JavaAgent.java:21)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(NotesThread.java:208)
Habt Ihr eine Idee, was ich falsch mache?
Viele Grüße
fritandr
Axel_Janssen:
kannst du bitte genau den Source code posten, den du laufen lässt (aus einem Agenten, auf Kommandozeilenebene).
Das kann mit Firewall-Dingen zusammenhängen, bin mir nicht ganz sicher.
Gruss Axel
Axel_Janssen:
WICHTIG!!!
Habe UnknownHostException vergessen.
Das funktioniert jedenfalls. Du musst diese UnknownHostException in den code noch einklinken (wie unten gezeigt.
Gruss Axel
--- Code: ---import lotus.domino.*;
import java.net.*;
import java.io.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
try {
URL url = new URL("http://www.javaranchc.com");
InputStream in = url.openStream();
in.close();
System.out.println("url ist da");
} catch (MalformedURLException e) {
System.out.println("url ist nicht da");
} catch (UnknownHostException e) {
System.out.println("url ist nicht da");
} catch (Exception e) {
e.printStackTrace();
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
--- Ende Code ---
--- Code: ---
--- Ende Code ---
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln