I'm setting up a punchout system to use with Oracle Exchange.
Exchange will be sending data via an http post and my site must accept
it, process it, and pass the authenticated user into the secure area.
This code works on an older server, but I keep receiving an error
message on a newer server that I have, and that's the one it MUST work
on. What do I need to change to make this actually work?
The http post is sent to the first page
(punchoutsetuprequestredirect.asp) that has the following code:
<% @LANGUAGE = VBScript%>
<%
Dim xml
Dim xml2
Dim xmlstr
Dim totalBytes
Dim url
Dim xdoc
'********************************Comments****************************
' MSDOM can't resolve DTD's, so replace defination with URL
' GET dtd's from http://cxml.org/
' But put them locally for performance
'********************************************************************
Dim olddtdvalue
Dim newdtdvalue
olddtdvalue = """cXML.dtd"""
' set the location of your dtd's
newdtdvalue = """http://mysite.com/aPunchout/cXML.dtd"""
'set redirect url here of cold fusion page you are going to call.
url = "http://mysite.com/aPunchout/recievePunchoutSetupRequest.cfm"
if (Request.ServerVariables("REQUEST_METHOD") = "POST") then
'********************************Comments****************************
' This command reads the incoming HTTP cXML Request
'********************************************************************
totalBytes = Request.TotalBytes
IF totalBytes > 0 THEN
xml = Request.BinaryRead( totalBytes )
for i = 1 to totalBytes
xmlstr = xmlstr + String(1,AscB(MidB(xml, i, 1)))
Next
xml2 = xmlstr
xml2 = Replace(xml2,olddtdvalue,newdtdvalue)
xml2 = Replace(xml2,"utf-8","utf-16")
END IF
'********************************Comments****************************
' Create MSDOM Object and set load values
'********************************************************************
Set xdoc = Server.CreateObject("Microsoft.XMLDOM")
xdoc.ValidateOnParse = False
xdoc.async = False
xdoc.resolveExternals = True
loadStatus = xdoc.loadXML(xml2)
If loadStatus = True then
Set fromIdentity = xdoc.getElementsByTagName("Header/From/Credential/Identity")
fromIdentity = (fromIdentity.item(0).text)
Set toSuppCred = xdoc.getElementsByTagName("Header/To/Credential/Identity")
toSuppCred = (toSuppCred.item(0).text)
Set senderCred = xdoc.getElementsByTagName("Header/Sender/Credential/Identity")
senderCred = (senderCred.item(0).text)
Set sharedSecret =
xdoc.getElementsByTagName("Header/Sender/Credential/SharedSecret")
sharedSecret = (sharedSecret.item(0).text)
Set fromUserAgent = xdoc.getElementsByTagName("Header/Sender/UserAgent")
fromUserAge = (fromUserAgent.item(0).text)
Set operation = xdoc.documentElement.childNodes(1).childNodes(0).attributes.getNamedItem("operation")
operation = xdoc.documentElement.childNodes(1).childNodes(0).attributes.getNamedItem("operation").text
Set buyerCookie = xdoc.getElementsByTagName("Request/PunchOutSetupRequest/BuyerCookie")
buyerCookie = (buyerCookie.item(0).text)
Set buyExtrinsics =
xdoc.getElementsByTagName("Request/PunchOutSetupRequest/Extrinsic")
For i = 0 To (buyExtrinsics.length -1)
BuyExtrinsicVars = (buyExtrinsics.item(i).text) & "," & BuyExtrinsicVars
Next
Set BrowserFormPost =
xdoc.getElementsByTagName("Request/PunchOutSetupRequest/BrowserFormPost")
BrowserFormPost = (BrowserFormPost.item(0).text)
Else
Response.Write " <P> xml @ supplier site failed to load using MSDOM: "
Dim strErrText
Dim xPE
Set xPE = xdoc.parseError
strErrText = "Your XML Document failed to load due the following
error: " & "Error #: " & xPE.errorCode & ": " & "Line #: " &
xPE.Line & "Line Position: " & xPE.linepos & "Position In File: " &
xPE.filepos & "Source Text: " & xPE.srcText & "Document URL: " &
xPE.url
Response.Write strErrText
End If
'********************************Comments****************************
' This get the http post "http RCP type call"
' This will convert a http post to a FORM post Variable with CXML in it
'********************************Comments****************************
'Create and Send the XML Post Request
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
objXML.open "POST", url, false
' Set HTTP Header so Cold fusion can read it. Cool trick..
objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
' Send the variables to look like a FORM POST. Note I didn't send the
orgional message, but you could with ("cXML=" & xml2 & "&" &).
objXML.send("fromIdentity=" & fromIdentity & "&" &
"BrowserFormPost=" & BrowserFormPost & "&" & "sharedSecret=" &
sharedSecret & "&" & "operation=" & operation & "&" &
"BuyExtrinsicVars=" & BuyExtrinsicVars & "&" & "buyerCookie=" &
buyerCookie & "&" & "toSuppCred=" & toSuppCred)
' Now write new page contents out. This shows the executed Cold Fusion Page
' this is really cool!! CFin from within asp. I love it.
Response.Write objXML.responseText
' Get method called. It's not valid for a PunchoutSetupRequest
else
Response.Write "<P> Wrong Method Get: Post supported only"
End if
%>
okay, that's that. now the next file is referenced in first page. the
code for this page (receivepunchoutsetuprequest.cfm) is here:
<!--- set vars locally from form vars submitted. Example for
ilistration. I will not support. --->
<CFSET fromIdentity = "#fromIdentity#">
<CFSET BrowserFormPost = "#BrowserFormPost#">
<CFSET sharedSecret = "#sharedSecret#">
<CFSET operation = "#operation#">
<CFSET BuyExtrinsicVars = "#Trim(ListChangeDelims(BuyExtrinsicVars,",",","))#">
<CFSET buyerCookie = "#buyerCookie#">
<CFSET toSuppCred = "#toSuppCred#">
<!--- authenticate fromIdentity to database and shared secret.. --->
<cfquery name="getSharedSecret" datasource="mydatasrc" dbtype="ODBC" maxrows="1">
Select AribaSharedSecret
FROM SharedSecrets
</cfquery>
<!--- just to make sure buyercookies arn't duplicated --->
<CFSET InsertTIME = "#TimeFormat(NOW())#">
<!---Insert records into database --->
<cfquery name="insertPunchoutSetupRequest" datasource="mydatasrc" dbtype="ODBC">
INSERT INTO punchoutSetupRequest
(fromIdentity,BrowserFormPost,operation,BuyExtrinsicVars,buyerCookie,toSuppCred,InsertTIME)
VALUES ('#fromIdentity#','#BrowserFormPost#','#operation#','#BuyExtrinsicVars#
','#buyerCookie#','#toSuppCred#','#InsertTIME#')
</cfquery>
<!--- Get record Inserted.. Get Primary Key --->
<cfquery name="getrecord" datasource="mydatasrc" dbtype="ODBC">
Select PunchoutID from punchoutSetupRequest
WHERE buyerCookie = '#buyerCookie#'
AND InsertTIME = '#InsertTIME#'
</cfquery>
<!--- you may want to hash up the results--->
<cfoutput>
<CFIF FORM.sharedSecret IS "#getSharedSecret.AribaSharedSecret#">
<?xml version="1.0"?><!DOCTYPE cXML SYSTEM "cXML.dtd"><cXML
version="1.0" payloadID="6/7/00 11:41:48 AM@10.10.101.205"
timestamp="6/7/00 11:41:48 AM">
<Response>
<Status code="200" text="Success"></Status><PunchOutSetupResponse><StartPage>
<URL>http://mysite.com/aPunchoutTRU/b2b/shop.cfm?keyvalue=#getrecord.PunchoutID#</URL>
</StartPage></PunchOutSetupResponse></Response></cXML>
<CFELSE>
<?xml version="1.0"?><!DOCTYPE cXML SYSTEM "cXML.dtd"><cXML
version="1.0" payloadID="#Now()#&#cgi.path_info#"
timestamp="#TimeFormat(Now())#">
<Response><Status code="500" Text="Invalid document"/></Response></cXML>
</CFIF>
</cfoutput>
okay, so that's that.
the cxml.dtd can be found here: http://cxml.org/
the error message i get is this:
Server Responce:
xml @ supplier site failed to load using MSDOM: Your XML Document
failed to load due the following error: Error #: -1072896765: Line #:
1Line Position: 262Position In File: 261Source Text:
xml @ supplier site failed to load using MSDOM: Your XML Document
failed to load due the following error: Error #: -2146697209: Line #:
0Line Position: 0Position In File: 0Source Text: Document URL:
http://mysite.com/aPunchout/cXML.dtd
also, when we uncomment:
' Response.Write objXML.responseText
' Response.Write newcxml
The response that is returned is a cold fusion database error:
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC
Microsoft Access Driver] Field 'punchoutSetupRequest.fromIdentity'
cannot be a zero-length string.
This is a tough question, one that Ben Forta himself may not be able
to answer. Or Bill Gates. But it's worth $200. Plus, whoever gets
me the solution that actually works on my server, in addition to the
$200, I'll send them a nice tip: an Apple Video iPod. Or any of the
iPods. |