Catch AJAX XML using Java agent

I have the following code to catch XML with a LotusScript agent:

Set xmlDOM = createobject("Microsoft.XMLDOM")

xmlDOM.async = False

xmlDOM.loadXML strReq

If (xmlDOM.parseError.errorCode <> 0) Then

	Set myErr = xmlDOM.parseError

	Call alog.LogAction("MSXML parse error: " & myErr.reason)

	Goto Finished

End If

strXML=xmlDOM.xml

This code works fine, except the XML we are sending has got too big and causes the agent to fail thinking it has caught an empty string.

The only way around this I can think of is to rewrite the agent using Java. Can anyone point me towards some example code which does the same thing as above in Java ???

TIA,

Mark.

Subject: Catch AJAX XML using Java agent

Hey Mark - how’s things?

Is it the case that the XMLDOM object is receiving an empty string or is that (as I suspect) the xml is too large for the ‘strXML’ variable you are trying to assign the XML to?

If it is the latter - I got round this by writing “xmlDOM.xml” to a NotesStream and then using that NotesStream as an input to either the DOM or SAX parser.

Not the cleanest of solutions but it worked. According to the documentation you should be able to write the XML to a rich-text item (thus avoiding the need for unrestricted signing) and then import to the parser from there, but I was unable to get this working :frowning:

If the issue is that XMLDOM object isn’t returning any XML via the .xml property then I guess Java is your way forwards.

Best of luck bud,

Tom.

Subject: RE: Catch AJAX XML using Java agent

Hiya Tom,

Hey that was a surprise. I’m good, how’s things with you? You still doing Notes too ??

That’s a good idea I didn’t think of… I’ll try the NotesStream solution and see what happens.

Thanks for your help

Cheers,

Mark.

Subject: SOLUTION

The problem is an undocumented feature …

When the context document Request_Content item gets too big, domino splits it into

Request_Content_000

Request_Content_001

Request_Content_002

etc

Below is a bit of code to read these items and reassemble the XML. Hope this saves somebody some time

Mark.

Function fnGetRequestContent(docContext As NotesDocument) As String

'===============================================

' If the Request_Content field contains too much data then

' the Domino Server will split the the items as 

'	Request_Content_001

'	Request_Content_002 

'===============================================

Dim i As Long

Dim strItemName As String

Dim itm As NotesItem

Dim strContent As String



On Error Goto ScriptError



If docContext.HasItem("Request_Content") Then

	fnGetRequestContent=docContext.GetRequestContext(0)

Else

	i=0

	strItemName="REQUEST_CONTENT_"+fnPad(i, 3)

	Set itm=docContext.GetFirstItem(strItemName)

	While Not itm Is Nothing

		Call alog.LogAction("Got item: "+strItemName)

		strContent=docContext.GetItemValue(stritemName)(0)

		fnGetRequestContent=fnGetRequestContent+strContent

		i=i+1

		strItemName="REQUEST_CONTENT_"+fnPad(i, 3)

		Set itm=docContext.GetFirstItem(strItemName)

	Wend

End If



Goto Finished

ScriptError:

Call alog.LogError(Err, "fnGetRequestContent / Line "+Cstr(Erl)+": "+Error$)

fnGetRequestContent=""

Resume Finished

Finished:

End Function

Function fnPad(intNumber, intMaxLength) As String

'=====================================

' Return a string with intNumber padded to

' intMaxLength places with leading zeros.

'=====================================

Dim strNumber As String

Dim strPad As String



strNumber=Cstr(intNumber)

strPad=String$(intMaxLength-Len(strNumber), "0")

fnPad=strPad+strNumber

Finished:

End Function