HttpEndpoint

Vom Front-End bis SOAP.

Moderator: Moderatoren

Antworten
psp
Rekursionen-Architekt
Rekursionen-Architekt
Beiträge: 250
Registriert: Do, 22. Okt 2009 13:42
Kontaktdaten:

HttpEndpoint

Beitrag von psp »

Hi,

hat wer Erfahrung mit dem HttpEndpoint ?
Habe das Problem das nach dem ausliefern einer html seite ein Fatal Error Auftritt und sich die exe beendet.
Tritt aber wohl nur bei meinem Pc auf auch Bei Deaktivierter Firewall/Virenscanner.
Mit anderen Programmiersprachen Läuft es wie es soll nur Xbase Macht da wohl was anders

Dank im Voraus

xpp Version: 2.00.1113 - Aktuelle

Log:
FATAL ERROR LOG
No continue after this Error!
SYS Thread-ID: 2096
Module: EXE
Error Codes: EH: 10 Sub: 0(0) OS: 0 XPP: 0
Call Stack of Thread 1 (1020):
MAIN(41)
Call Stack of GUI Thread (1196):
Call Stack of Thread 3 (1972):
@HTTPENDPOINT@I@CONNECTED(436)
@HTTPENDPOINT@I@LISTEN(392)
@LISTENERTHREAD@I@EXECUTE(119)
Call Stack of Thread 4 (2032):
Call Stack of Thread 5 (2096):
@APPSTORAGEMANAGER@I@OPENORCREATE(198)
@APPSTORAGEMANAGER@I@START(173)
@CXPAPPLICATION@I@STARTUP(1910)
@ABSTRACTHOSTADAPTOR@I@STARTUP(164)
@WEBJOB@I@EXECUTEWEBREQUEST(570)
@WEBJOB@I@EXECUTEHTTP(528)
@WEBJOB@I@EXECUTE(484)
File: D:\Workspace\xbase\web_service\web_server.exe
TimeStamp: 20200121 08:50
End of FATAL ERROR LOG.
Code:
// This example creates an html file in the current directory.
// The HttpEndpoint loads the file and returns it to the
// connected client on request. If an SSL certificate is
// installed on the computer, the end point is bound to this
// certificate in order to allow clients to connect via SSL
// for increased security.
#include "inkey.ch"
#include "web.ch"

#define PORT 81
PROCEDURE Main()
LOCAL cPort
LOCAL oHttpEndpoint
LOCAL nKey
LOCAL cHtml
LOCAL lStarted

//
// Creates a sample html file on the local drive.
//
IF .NOT. File( "default.html" )
cHtml := ""
cHtml += "<h1>Hello World!</h1>"
cHtml += "<h2>Greetings from: "+AppName()+"</h2>"
MemoWrit( "default.html", cHtml )
ENDIF

cPort := Var2Char(PORT)
? "HttpEndpoint sample."
?
? "With a web browser navigate to:"
?
? " http://localhost:"+cPort+"/default.html"
?
? "Press ESC to quit"

//
// Create an end point for handling incoming
// connections on the specified port
//
// Note: Requests to .html files are handled
// automatically by the Http end point!
// No code must be written for returning
// the sample .html file.
//
oHttpEndpoint := HttpEndpoint():new( PORT, "localhost" )
lStarted := oHttpEndpoint:start()
IF .NOT. lStarted
? "Startup error. Check if port "+cPort+" is already in use."
WAIT
RETURN
ENDIF

// Continue after the ESC key was pressed
nKey := 0
DO WHILE nKey <> K_ESC
nKey := Inkey(1)
ENDDO

//
// Stop the endpoint before the application
// terminates
//
oHttpEndpoint:stop()

RETURN
Project File:
//
// Project - Definition - File created by PBUILD Version 2.00.1150
// Date: 10.01.2020 Time: 08:51:31
//

[PROJECT]
VERSION = 2.2
PBUILD = @project.txt
MAKE =
project.xpj

[project.xpj]
web_server.exe

[web_server.exe]
COMPILE = xpp
COMPILE_FLAGS = /q /ga
DEBUG = yes
GUI = yes
LINKER = alink
LINK_FLAGS =
RC_COMPILE = arc
RC_FLAGS =
INTERMEDIATE_DEBUG = .debug
INTERMEDIATE_RELEASE = .release
web_server.prg
psp
Rekursionen-Architekt
Rekursionen-Architekt
Beiträge: 250
Registriert: Do, 22. Okt 2009 13:42
Kontaktdaten:

Re: HttpEndpoint

Beitrag von psp »

Problem hat sich von selbst gelöst
jobbisoft
Rookie
Rookie
Beiträge: 15
Registriert: Mi, 12. Jan 2022 20:13
Kontaktdaten:

Re: HttpEndpoint

Beitrag von jobbisoft »

Hallo,

ich habe mich noch nicht vorgestellt, mein Name ist Osvaldo Ramirez und ich benutze xbase++ seit Version 1.3.
Meine Frage ist, hat jemand das folgende Beispiel verwendet:

aber mit einer URL wie dieser http://localhost:"+Port"/v1/production/Current Time/get" ?
wie wäre der Programmiercode ?


#include "inkey.ch"
#include "web.ch"

#define PORT 81
PROCEDURE Main()
LOCAL cPort
LOCAL oHttpEndpoint
LOCAL nKey

cPort := AllTrim(Str(PORT))
? "Time Server sample."
?
? "With a web browser navigate to:"
?
? " http://localhost:"+cPort+"/CurrentTime/get"
? " http://localhost:"+cPort+"/CurrentTime/unknown"
?
? "Press ESC to quit"

//
// The listener thread is established
//
oHttpEndpoint := HttpEndpoint():new( PORT, "localhost" )
oHttpEndpoint:start()

// This sample does not do anything special
nKey := 0
DO WHILE nKey <> K_ESC
nKey := Inkey(1)
ENDDO

//
// Stop the endpoint before the application
// is terminated
//
oHttpEndpoint:stop()

RETURN

//
// Handler for the current time
//
CLASS CurrentTime FROM WebHandler
EXPORTED:
METHOD get
METHOD execute
ENDCLASS

//
// The method :get() handles the RESTful path CurrentTime/get
//
METHOD CurrentTime:get()
LOCAL cThreadId
LOCAL cResponse := ""

cThreadId := AllTrim(Str(ThreadId()))

cResponse += "<!DOCTYPE html>"
cResponse += "<html>"
cResponse += "<head><title>"+ProcName()+"</title></head>"
cResponse += "<body>"
cResponse += "<h1>Current Time:</h1>"
cResponse += "<p>"+Time()+" (HH:MM:SS)</p>"
cResponse += "<small>By thread: "+cThreadId+"</small>"
cResponse += "</body>"
cResponse += "</html>"

RETURN cResponse

//
// Dispatch the request to existing methods. Return a generic
// web page for all other requests.
//
METHOD CurrentTime:execute( cMethodName )
LOCAL cResponse := ""

IF IsMethod(SELF, cMethodName)
RETURN SUPER:execute( cMethodName )
ENDIF

cResponse += "<!DOCTYPE html>"
cResponse += "<html>"
cResponse += "<head><title>Unhandled request</title></head>"
cResponse += "<body>"
cResponse += "<h1>No handler for: "+cMethodName+"</h1>"
cResponse += "<p>Please try with: /CurrentTime/get</p>"
cResponse += "<small>Sorry</small>"
cResponse += "</body>"
cResponse += "<html>"

RETURN cResponse

Hinweis:
Kann ich auf Englisch oder Spanisch schreiben?


grüße und danke
Osvaldo Ramirez
Grüße
Osvaldo Ramirez
Antworten