2028 lines
69 KiB
Plaintext
2028 lines
69 KiB
Plaintext
#-------------------------------------------------------------------------------
|
|
# File: ws_calculator.4gl
|
|
# GENERATED BY fglwsdl 202111081619
|
|
#-------------------------------------------------------------------------------
|
|
# THIS FILE WAS GENERATED. DO NOT MODIFY.
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
IMPORT FGL WSHelper
|
|
IMPORT com
|
|
IMPORT xml
|
|
IMPORT security
|
|
IMPORT os
|
|
|
|
|
|
GLOBALS "ws_calculator.inc"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
# Service: Calculator
|
|
# Port: CalculatorPortType
|
|
# Server: http://localhost:8090
|
|
#-------------------------------------------------------------------------------
|
|
|
|
PRIVATE DEFINE AddHTTPReq com.HTTPRequest
|
|
PRIVATE DEFINE AddHTTPResp com.HTTPResponse
|
|
|
|
PRIVATE DEFINE SubtractHTTPReq com.HTTPRequest
|
|
PRIVATE DEFINE SubtractHTTPResp com.HTTPResponse
|
|
|
|
PRIVATE DEFINE MultiplyHTTPReq com.HTTPRequest
|
|
PRIVATE DEFINE MultiplyHTTPResp com.HTTPResponse
|
|
|
|
PRIVATE DEFINE DivideHTTPReq com.HTTPRequest
|
|
PRIVATE DEFINE DivideHTTPResp com.HTTPResponse
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
# Operation: Add
|
|
#
|
|
|
|
#
|
|
# FUNCTION: Add
|
|
#
|
|
FUNCTION Add(p_a, p_b)
|
|
DEFINE p_a INTEGER
|
|
DEFINE p_b INTEGER
|
|
DEFINE soapStatus INTEGER
|
|
|
|
|
|
LET Add.a = p_a
|
|
LET Add.b = p_b
|
|
|
|
LET soapStatus = Add_g()
|
|
|
|
RETURN soapStatus, AddResponse.r
|
|
END FUNCTION
|
|
|
|
#
|
|
# FUNCTION: Add_g
|
|
# RETURNING: soapStatus
|
|
# INPUT: GLOBAL Add
|
|
# OUTPUT: GLOBAL AddResponse
|
|
#
|
|
FUNCTION Add_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE retryAuth INTEGER
|
|
DEFINE retryProxy INTEGER
|
|
DEFINE retry INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE request com.HTTPRequest
|
|
DEFINE response com.HTTPResponse
|
|
DEFINE writer xml.StaxWriter
|
|
DEFINE reader xml.StaxReader
|
|
|
|
#
|
|
# INIT VARIABLES
|
|
#
|
|
LET wsstatus = -1
|
|
LET retryAuth = FALSE
|
|
LET retryProxy = FALSE
|
|
LET retry = TRUE
|
|
LET fault = FALSE
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET request = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL request.setMethod("POST")
|
|
CALL request.setCharset("UTF-8")
|
|
CALL request.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(request, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL request.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL request.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL request.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL request.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL request.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL request.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# START LOOP
|
|
WHILE retry
|
|
LET retry = FALSE
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = request.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Add,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL request.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET response = request.getResponse()
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = response.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(response, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
|
|
CASE
|
|
WHEN response.getStatusCode()==200 OR response.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = response.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
CALL reader.nextSibling() # Skip SOAP detail
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,AddResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL response.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==401 # HTTP Authentication
|
|
IF retryAuth THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 401 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryAuth = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==407 # Proxy Authentication
|
|
IF retryProxy THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 407 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryProxy = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||response.getStatusCode()||" ("||response.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# END LOOP
|
|
END WHILE
|
|
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION AddRequest_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE writer xml.StaxWriter
|
|
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF AddHTTPReq IS NOT NULL AND AddHTTPResp IS NULL THEN
|
|
# Request was sent but there was no response yet
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot issue a new request until previous response was received")
|
|
RETURN -2 # waiting for the response
|
|
ELSE
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET AddHTTPReq = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL AddHTTPReq.setMethod("POST")
|
|
CALL AddHTTPReq.setCharset("UTF-8")
|
|
CALL AddHTTPReq.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(AddHTTPReq, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL AddHTTPReq.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL AddHTTPReq.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL AddHTTPReq.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL AddHTTPReq.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL AddHTTPReq.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL AddHTTPReq.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
LET AddHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = AddHTTPReq.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Add,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL AddHTTPReq.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
LET AddHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET AddHTTPResp = AddHTTPReq.getAsyncResponse()
|
|
RETURN 0 # SUCCESS
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
LET AddHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION AddResponse_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE reader xml.StaxReader
|
|
|
|
LET fault = FALSE
|
|
LET wsstatus = -1
|
|
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF AddHTTPReq IS NULL THEN
|
|
# No request was sent
|
|
CALL WSHelper_FillSOAP11WSError("Client","No request has been sent")
|
|
RETURN -1
|
|
END IF
|
|
|
|
TRY
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
IF AddHTTPResp IS NULL THEN
|
|
# Still no response, try again
|
|
LET AddHTTPResp = AddHTTPReq.getAsyncResponse()
|
|
END IF
|
|
|
|
IF AddHTTPResp IS NULL THEN
|
|
# We got no response, still waiting for
|
|
CALL WSHelper_FillSOAP11WSError("Client","Response was not yet received")
|
|
RETURN -2
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = AddHTTPResp.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(AddHTTPResp, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
CASE
|
|
WHEN AddHTTPResp.getStatusCode()==200 OR AddHTTPResp.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = AddHTTPResp.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
CALL reader.nextSibling() # Skip SOAP detail
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,AddResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL AddHTTPResp.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||AddHTTPResp.getStatusCode()||" ("||AddHTTPResp.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
#
|
|
# RESET VARIABLES
|
|
#
|
|
LET AddHTTPReq = NULL
|
|
LET AddHTTPResp = NULL
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
|
|
#
|
|
# Operation: Subtract
|
|
#
|
|
|
|
#
|
|
# FUNCTION: Subtract
|
|
#
|
|
FUNCTION Subtract(p_a, p_b)
|
|
DEFINE p_a INTEGER
|
|
DEFINE p_b INTEGER
|
|
DEFINE soapStatus INTEGER
|
|
|
|
|
|
LET Subtract.a = p_a
|
|
LET Subtract.b = p_b
|
|
|
|
LET soapStatus = Subtract_g()
|
|
|
|
RETURN soapStatus, SubtractResponse.r
|
|
END FUNCTION
|
|
|
|
#
|
|
# FUNCTION: Subtract_g
|
|
# RETURNING: soapStatus
|
|
# INPUT: GLOBAL Subtract
|
|
# OUTPUT: GLOBAL SubtractResponse
|
|
#
|
|
FUNCTION Subtract_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE retryAuth INTEGER
|
|
DEFINE retryProxy INTEGER
|
|
DEFINE retry INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE request com.HTTPRequest
|
|
DEFINE response com.HTTPResponse
|
|
DEFINE writer xml.StaxWriter
|
|
DEFINE reader xml.StaxReader
|
|
|
|
#
|
|
# INIT VARIABLES
|
|
#
|
|
LET wsstatus = -1
|
|
LET retryAuth = FALSE
|
|
LET retryProxy = FALSE
|
|
LET retry = TRUE
|
|
LET fault = FALSE
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET request = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL request.setMethod("POST")
|
|
CALL request.setCharset("UTF-8")
|
|
CALL request.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(request, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL request.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL request.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL request.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL request.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL request.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL request.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# START LOOP
|
|
WHILE retry
|
|
LET retry = FALSE
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = request.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Subtract,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL request.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET response = request.getResponse()
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = response.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(response, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
|
|
CASE
|
|
WHEN response.getStatusCode()==200 OR response.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = response.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
CALL reader.nextSibling() # Skip SOAP detail
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,SubtractResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL response.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==401 # HTTP Authentication
|
|
IF retryAuth THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 401 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryAuth = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==407 # Proxy Authentication
|
|
IF retryProxy THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 407 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryProxy = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||response.getStatusCode()||" ("||response.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# END LOOP
|
|
END WHILE
|
|
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION SubtractRequest_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE writer xml.StaxWriter
|
|
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF SubtractHTTPReq IS NOT NULL AND SubtractHTTPResp IS NULL THEN
|
|
# Request was sent but there was no response yet
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot issue a new request until previous response was received")
|
|
RETURN -2 # waiting for the response
|
|
ELSE
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET SubtractHTTPReq = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL SubtractHTTPReq.setMethod("POST")
|
|
CALL SubtractHTTPReq.setCharset("UTF-8")
|
|
CALL SubtractHTTPReq.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(SubtractHTTPReq, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL SubtractHTTPReq.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL SubtractHTTPReq.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL SubtractHTTPReq.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL SubtractHTTPReq.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL SubtractHTTPReq.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL SubtractHTTPReq.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
LET SubtractHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = SubtractHTTPReq.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Subtract,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL SubtractHTTPReq.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
LET SubtractHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET SubtractHTTPResp = SubtractHTTPReq.getAsyncResponse()
|
|
RETURN 0 # SUCCESS
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
LET SubtractHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION SubtractResponse_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE reader xml.StaxReader
|
|
|
|
LET fault = FALSE
|
|
LET wsstatus = -1
|
|
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF SubtractHTTPReq IS NULL THEN
|
|
# No request was sent
|
|
CALL WSHelper_FillSOAP11WSError("Client","No request has been sent")
|
|
RETURN -1
|
|
END IF
|
|
|
|
TRY
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
IF SubtractHTTPResp IS NULL THEN
|
|
# Still no response, try again
|
|
LET SubtractHTTPResp = SubtractHTTPReq.getAsyncResponse()
|
|
END IF
|
|
|
|
IF SubtractHTTPResp IS NULL THEN
|
|
# We got no response, still waiting for
|
|
CALL WSHelper_FillSOAP11WSError("Client","Response was not yet received")
|
|
RETURN -2
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = SubtractHTTPResp.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(SubtractHTTPResp, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
CASE
|
|
WHEN SubtractHTTPResp.getStatusCode()==200 OR SubtractHTTPResp.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = SubtractHTTPResp.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
CALL reader.nextSibling() # Skip SOAP detail
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,SubtractResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL SubtractHTTPResp.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||SubtractHTTPResp.getStatusCode()||" ("||SubtractHTTPResp.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
#
|
|
# RESET VARIABLES
|
|
#
|
|
LET SubtractHTTPReq = NULL
|
|
LET SubtractHTTPResp = NULL
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
|
|
#
|
|
# Operation: Multiply
|
|
#
|
|
|
|
#
|
|
# FUNCTION: Multiply
|
|
#
|
|
FUNCTION Multiply(p_a, p_b)
|
|
DEFINE p_a INTEGER
|
|
DEFINE p_b INTEGER
|
|
DEFINE soapStatus INTEGER
|
|
|
|
|
|
LET Multiply.a = p_a
|
|
LET Multiply.b = p_b
|
|
|
|
LET soapStatus = Multiply_g()
|
|
|
|
RETURN soapStatus, MultiplyResponse.r
|
|
END FUNCTION
|
|
|
|
#
|
|
# FUNCTION: Multiply_g
|
|
# RETURNING: soapStatus
|
|
# INPUT: GLOBAL Multiply
|
|
# OUTPUT: GLOBAL MultiplyResponse
|
|
#
|
|
FUNCTION Multiply_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE retryAuth INTEGER
|
|
DEFINE retryProxy INTEGER
|
|
DEFINE retry INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE request com.HTTPRequest
|
|
DEFINE response com.HTTPResponse
|
|
DEFINE writer xml.StaxWriter
|
|
DEFINE reader xml.StaxReader
|
|
|
|
#
|
|
# INIT VARIABLES
|
|
#
|
|
LET wsstatus = -1
|
|
LET retryAuth = FALSE
|
|
LET retryProxy = FALSE
|
|
LET retry = TRUE
|
|
LET fault = FALSE
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET request = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL request.setMethod("POST")
|
|
CALL request.setCharset("UTF-8")
|
|
CALL request.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(request, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL request.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL request.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL request.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL request.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL request.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL request.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# START LOOP
|
|
WHILE retry
|
|
LET retry = FALSE
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = request.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Multiply,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL request.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET response = request.getResponse()
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = response.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(response, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
|
|
CASE
|
|
WHEN response.getStatusCode()==200 OR response.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = response.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
CALL reader.nextSibling() # Skip SOAP detail
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,MultiplyResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL response.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==401 # HTTP Authentication
|
|
IF retryAuth THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 401 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryAuth = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==407 # Proxy Authentication
|
|
IF retryProxy THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 407 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryProxy = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||response.getStatusCode()||" ("||response.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# END LOOP
|
|
END WHILE
|
|
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION MultiplyRequest_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE writer xml.StaxWriter
|
|
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF MultiplyHTTPReq IS NOT NULL AND MultiplyHTTPResp IS NULL THEN
|
|
# Request was sent but there was no response yet
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot issue a new request until previous response was received")
|
|
RETURN -2 # waiting for the response
|
|
ELSE
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET MultiplyHTTPReq = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL MultiplyHTTPReq.setMethod("POST")
|
|
CALL MultiplyHTTPReq.setCharset("UTF-8")
|
|
CALL MultiplyHTTPReq.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(MultiplyHTTPReq, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL MultiplyHTTPReq.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL MultiplyHTTPReq.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL MultiplyHTTPReq.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL MultiplyHTTPReq.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL MultiplyHTTPReq.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL MultiplyHTTPReq.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
LET MultiplyHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = MultiplyHTTPReq.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Multiply,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL MultiplyHTTPReq.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
LET MultiplyHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET MultiplyHTTPResp = MultiplyHTTPReq.getAsyncResponse()
|
|
RETURN 0 # SUCCESS
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
LET MultiplyHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION MultiplyResponse_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE reader xml.StaxReader
|
|
|
|
LET fault = FALSE
|
|
LET wsstatus = -1
|
|
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF MultiplyHTTPReq IS NULL THEN
|
|
# No request was sent
|
|
CALL WSHelper_FillSOAP11WSError("Client","No request has been sent")
|
|
RETURN -1
|
|
END IF
|
|
|
|
TRY
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
IF MultiplyHTTPResp IS NULL THEN
|
|
# Still no response, try again
|
|
LET MultiplyHTTPResp = MultiplyHTTPReq.getAsyncResponse()
|
|
END IF
|
|
|
|
IF MultiplyHTTPResp IS NULL THEN
|
|
# We got no response, still waiting for
|
|
CALL WSHelper_FillSOAP11WSError("Client","Response was not yet received")
|
|
RETURN -2
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = MultiplyHTTPResp.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(MultiplyHTTPResp, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
CASE
|
|
WHEN MultiplyHTTPResp.getStatusCode()==200 OR MultiplyHTTPResp.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = MultiplyHTTPResp.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
CALL reader.nextSibling() # Skip SOAP detail
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,MultiplyResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL MultiplyHTTPResp.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||MultiplyHTTPResp.getStatusCode()||" ("||MultiplyHTTPResp.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
#
|
|
# RESET VARIABLES
|
|
#
|
|
LET MultiplyHTTPReq = NULL
|
|
LET MultiplyHTTPResp = NULL
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
|
|
#
|
|
# Operation: Divide
|
|
# FAULT #1: GLOBALS DividedByZero
|
|
#
|
|
|
|
#
|
|
# FUNCTION: Divide
|
|
#
|
|
FUNCTION Divide(p_a, p_b)
|
|
DEFINE p_a INTEGER
|
|
DEFINE p_b INTEGER
|
|
DEFINE soapStatus INTEGER
|
|
|
|
|
|
LET Divide.a = p_a
|
|
LET Divide.b = p_b
|
|
|
|
LET soapStatus = Divide_g()
|
|
|
|
RETURN soapStatus, DivideResponse.quotient, DivideResponse.remainder
|
|
END FUNCTION
|
|
|
|
#
|
|
# FUNCTION: Divide_g
|
|
# RETURNING: soapStatus
|
|
# INPUT: GLOBAL Divide
|
|
# OUTPUT: GLOBAL DivideResponse
|
|
#
|
|
FUNCTION Divide_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE retryAuth INTEGER
|
|
DEFINE retryProxy INTEGER
|
|
DEFINE retry INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE request com.HTTPRequest
|
|
DEFINE response com.HTTPResponse
|
|
DEFINE writer xml.StaxWriter
|
|
DEFINE reader xml.StaxReader
|
|
|
|
#
|
|
# INIT VARIABLES
|
|
#
|
|
LET wsstatus = -1
|
|
LET retryAuth = FALSE
|
|
LET retryProxy = FALSE
|
|
LET retry = TRUE
|
|
LET fault = FALSE
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET request = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL request.setMethod("POST")
|
|
CALL request.setCharset("UTF-8")
|
|
CALL request.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(request, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL request.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL request.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL request.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL request.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL request.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL request.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# START LOOP
|
|
WHILE retry
|
|
LET retry = FALSE
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = request.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Divide,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL request.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET response = request.getResponse()
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = response.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(response, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
|
|
CASE
|
|
WHEN response.getStatusCode()==200 OR response.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = response.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
IF NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
IF reader.getLocalName()=="DividedByZero" AND reader.getNamespace()=="http://tempuri.org/" THEN
|
|
CALL xml.Serializer.StaxToVariable(reader,DividedByZero)
|
|
LET wsstatus = FaultID_DividedByZero
|
|
END IF
|
|
IF wsstatus == -1 THEN
|
|
CALL reader.nextTag() # Skip unknown SOAP Fault detail
|
|
END IF
|
|
END IF
|
|
CALL reader.nextTag() # Read detail close tag
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,DivideResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL response.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==401 # HTTP Authentication
|
|
IF retryAuth THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 401 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryAuth = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
WHEN response.getStatusCode()==407 # Proxy Authentication
|
|
IF retryProxy THEN
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error 407 ("||response.getStatusDescription()||")")
|
|
ELSE
|
|
LET retryProxy = TRUE
|
|
LET retry = TRUE
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||response.getStatusCode()||" ("||response.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
# END LOOP
|
|
END WHILE
|
|
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION DivideRequest_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE writer xml.StaxWriter
|
|
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF DivideHTTPReq IS NOT NULL AND DivideHTTPResp IS NULL THEN
|
|
# Request was sent but there was no response yet
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot issue a new request until previous response was received")
|
|
RETURN -2 # waiting for the response
|
|
ELSE
|
|
IF Calculator_CalculatorPortTypeEndpoint.Address.Uri IS NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Address.Uri = "http://localhost:8090"
|
|
END IF
|
|
END IF
|
|
|
|
#
|
|
# CREATE REQUEST
|
|
#
|
|
TRY
|
|
LET DivideHTTPReq = com.HTTPRequest.Create(Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
CALL DivideHTTPReq.setMethod("POST")
|
|
CALL DivideHTTPReq.setCharset("UTF-8")
|
|
CALL DivideHTTPReq.setHeader("SOAPAction","\"\"")
|
|
CALL WSHelper_SetRequestHeaders(DivideHTTPReq, Calculator_CalculatorPortTypeEndpoint.Binding.Request.Headers)
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Version IS NOT NULL THEN
|
|
CALL DivideHTTPReq.setVersion(Calculator_CalculatorPortTypeEndpoint.Binding.Version)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.Cookie IS NOT NULL THEN
|
|
CALL DivideHTTPReq.setHeader("Cookie",Calculator_CalculatorPortTypeEndpoint.Binding.Cookie)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout <> 0 THEN
|
|
CALL DivideHTTPReq.setConnectionTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ConnectionTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout <> 0 THEN
|
|
CALL DivideHTTPReq.setTimeout(Calculator_CalculatorPortTypeEndpoint.Binding.ReadWriteTimeout)
|
|
END IF
|
|
IF Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest IS NOT NULL THEN
|
|
CALL DivideHTTPReq.setHeader("Content-Encoding",Calculator_CalculatorPortTypeEndpoint.Binding.CompressRequest)
|
|
END IF
|
|
CALL DivideHTTPReq.setHeader("Accept-Encoding","gzip, deflate")
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client","Cannot create HTTPRequest")
|
|
LET DivideHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# Stax request
|
|
#
|
|
TRY
|
|
LET writer = DivideHTTPReq.beginXmlRequest()
|
|
CALL WSHelper_WriteStaxSOAP11StartEnvelope(writer)
|
|
CALL WSHelper_WriteStaxSOAP11StartBody(writer)
|
|
#
|
|
# STAX SOAP REQUEST SERIALIZE
|
|
#
|
|
CALL xml.Serializer.VariableToStax(Divide,writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndBody(writer)
|
|
CALL WSHelper_WriteStaxSOAP11EndEnvelope(writer)
|
|
CALL DivideHTTPReq.endXmlRequest(writer)
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Client",SQLCA.SQLERRM)
|
|
LET DivideHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
TRY
|
|
LET DivideHTTPResp = DivideHTTPReq.getAsyncResponse()
|
|
RETURN 0 # SUCCESS
|
|
CATCH
|
|
LET wsstatus = STATUS
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
LET DivideHTTPReq = NULL
|
|
RETURN wsstatus
|
|
END TRY
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION DivideResponse_g()
|
|
DEFINE wsstatus INTEGER
|
|
DEFINE fault BOOLEAN
|
|
DEFINE nb INTEGER
|
|
DEFINE uri STRING
|
|
DEFINE setcookie STRING
|
|
DEFINE mustUnderstand INTEGER
|
|
DEFINE reader xml.StaxReader
|
|
|
|
LET fault = FALSE
|
|
LET wsstatus = -1
|
|
|
|
LET uri = com.WebServiceEngine.GetOption("SoapModuleURI")
|
|
#
|
|
# CHECK PREVIOUS CALL
|
|
#
|
|
IF DivideHTTPReq IS NULL THEN
|
|
# No request was sent
|
|
CALL WSHelper_FillSOAP11WSError("Client","No request has been sent")
|
|
RETURN -1
|
|
END IF
|
|
|
|
TRY
|
|
#
|
|
# PROCESS RESPONSE
|
|
#
|
|
IF DivideHTTPResp IS NULL THEN
|
|
# Still no response, try again
|
|
LET DivideHTTPResp = DivideHTTPReq.getAsyncResponse()
|
|
END IF
|
|
|
|
IF DivideHTTPResp IS NULL THEN
|
|
# We got no response, still waiting for
|
|
CALL WSHelper_FillSOAP11WSError("Client","Response was not yet received")
|
|
RETURN -2
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE SERVICE SESSION COOKIE
|
|
#
|
|
LET setcookie = DivideHTTPResp.getHeader("Set-Cookie")
|
|
IF setcookie IS NOT NULL THEN
|
|
LET Calculator_CalculatorPortTypeEndpoint.Binding.Cookie = WSHelper_ExtractServerCookie(setcookie,Calculator_CalculatorPortTypeEndpoint.Address.Uri)
|
|
END IF
|
|
|
|
#
|
|
# RETRIEVE HTTP RESPONSE Headers
|
|
#
|
|
CALL WSHelper_SetResponseHeaders(DivideHTTPResp, Calculator_CalculatorPortTypeEndpoint.Binding.Response.Headers)
|
|
CASE
|
|
WHEN DivideHTTPResp.getStatusCode()==200 OR DivideHTTPResp.getStatusCode()==500
|
|
#
|
|
# STAX SOAP RESPONSE OR FAULT
|
|
#
|
|
LET reader = DivideHTTPResp.beginXmlResponse() # Begin Streaming Response
|
|
IF NOT WSHelper_ReadStaxSOAP11StartEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# Process SOAP headers
|
|
LET nb = 0
|
|
IF WSHelper_CheckStaxSOAP11Header(reader) AND NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
WHILE (reader.getEventType()=="START_ELEMENT")
|
|
IF WSHelper_CheckStaxSOAP11HeaderActor(reader,uri) THEN
|
|
LET mustUnderstand = WSHelper_GetStaxSOAP11HeaderMustUnderstand(reader)
|
|
IF mustUnderstand = -1 THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","Invalid mustUnderstand value")
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE HEADER DESERIALIZE
|
|
#
|
|
IF mustUnderstand THEN
|
|
CALL WSHelper_FillSOAP11WSError("MustUnderstand","Mandatory header block not understood")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not necessary
|
|
END IF
|
|
ELSE
|
|
CALL reader.nextSibling() # Skip header, not intended to us
|
|
END IF
|
|
END WHILE
|
|
IF NOT WSHelper_CheckStaxSOAP11Header(reader) THEN
|
|
CALL WSHelper_FillSOAP11WSError("Client","No ending header tag found")
|
|
EXIT CASE
|
|
ELSE
|
|
CALL reader.nextTag()
|
|
END IF
|
|
ELSE
|
|
IF reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
END IF
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11StartBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11StartFault(reader) THEN # Handle SOAP Fault
|
|
LET fault = TRUE
|
|
CALL reader.nextTag()
|
|
IF NOT WSHelper_ReadStaxSOAP11FaultUntilDetail(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF WSHelper_CheckStaxSOAP11FaultDetail(reader) THEN
|
|
#
|
|
# STAX SOAP FAULT DESERIALIZE
|
|
#
|
|
IF NOT reader.isEmptyElement() THEN
|
|
CALL reader.nextTag()
|
|
IF reader.getLocalName()=="DividedByZero" AND reader.getNamespace()=="http://tempuri.org/" THEN
|
|
CALL xml.Serializer.StaxToVariable(reader,DividedByZero)
|
|
LET wsstatus = FaultID_DividedByZero
|
|
END IF
|
|
IF wsstatus == -1 THEN
|
|
CALL reader.nextTag() # Skip unknown SOAP Fault detail
|
|
END IF
|
|
END IF
|
|
CALL reader.nextTag() # Read detail close tag
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndFault(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
ELSE # Handle SOAP Response
|
|
IF nb != 0 THEN # Check mandatory headers
|
|
CALL WSHelper_FillSOAP11WSError("Client","Headers are missing")
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_RetrieveStaxSOAP11Message(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
#
|
|
# STAX SOAP RESPONSE DESERIALIZE
|
|
#
|
|
CALL xml.Serializer.StaxToVariable(reader,DivideResponse)
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndBody(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
IF NOT WSHelper_ReadStaxSOAP11EndEnvelope(reader) THEN
|
|
EXIT CASE
|
|
END IF
|
|
# End Streaming Response
|
|
CALL DivideHTTPResp.endXmlResponse(reader)
|
|
IF NOT fault THEN
|
|
LET wsstatus = 0
|
|
END IF
|
|
|
|
OTHERWISE
|
|
CALL WSHelper_FillSOAP11WSError("Server","HTTP Error "||DivideHTTPResp.getStatusCode()||" ("||DivideHTTPResp.getStatusDescription()||")")
|
|
|
|
END CASE
|
|
CATCH
|
|
LET wsstatus = status
|
|
CALL WSHelper_FillSOAP11WSError("Server",SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
#
|
|
# RESET VARIABLES
|
|
#
|
|
LET DivideHTTPReq = NULL
|
|
LET DivideHTTPResp = NULL
|
|
RETURN wsstatus
|
|
|
|
END FUNCTION
|
|
|
|
|