Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: Trying to send an XML document to state of MD server

$
0
0
Re: Trying to send an XML document to state of MD server
Web Connection
Re: Trying to send an XML document to state of MD server
Jul. 19, 2013
08:59 am
3U30J9TIKShow this entire thread in new window
Gratar Image based on email address
From:John Kiernan
To:John Kiernan
Hey guys...

I still don't have an answer to this, but I got more info from the other side. Here is the code that processes the incoming XML and returns the various error messages:

private String processRequest( HttpServletRequest request, HttpServletResponse response) throws Exception {

String result = "";

if ( !request.isSecure() )
return "<incidents><https>Not Secure</https></incidents>";

boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if ( isMultipart ){
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();

try{
// Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
//String name = item.getFieldName();
InputStream stream = item.openStream();
String xml_data = Streams.asString(stream);
if (item.isFormField()) {
try{
result = processXML( "form_field.xml", xml_data );
}catch(Exception e){
result = "<incidents>\n";
result += "\t<upload_result>Fail</upload_result>\n";
result += "\t<upload_error>1.Unknown error occurred: " + e.getMessage() + "</upload_error>\n";
result += "</incidents>";
}
} else {
try{
result = processXML( item.getName(), xml_data );
} catch(Exception e){
result = "<incidents>\n";
result += "\t<upload_result>Fail</upload_result>\n";
result += "\t<upload_error>2.Unknown error occurred: " + e.getMessage() + "</upload_error>\n";
result += "</incidents>";
}

}
}
} catch(Exception e){
result = "<incidents>\n";
result += "\t<upload_result>Fail</upload_result>\n";
result += "\t<upload_error>3.Unknown error occurred: " + e.getMessage() + "</upload_error>\n";
result += "</incidents>";
}
}
else{
try{
String xml_data = Streams.asString(request.getInputStream());
result = processXML( "input_stream.xml", xml_data );
} catch(Exception e){
result = "<incidents>\n";
result += "\t<upload_result>Fail</upload_result>\n";
result += "\t<upload_error>4.Unknown error occurred: " + e.getMessage() + "</upload_error>\n";
result += "</incidents>";
}
}

return result;
}


Perhaps this might help figure it out?

-- John



Hey WW folks...

Been using West Wind for years, but this is the first time I've tried to send an XML file (I think).

I have an XML file that passes muster with the state. I can upload it manually with a super small HTML I wrote:

<HTML>
<body>
<form action="https://pcispreprod.dhmh.state.md.us/Pcis2New2a/upload/incident" enctype="multipart/form-data" method="post">

<input type="file" name="upload" >
<input type="submit" value="Submit" >
</form>
</body>
</html>

I get back:
<incidents>
<incident_ir>
<provider_no>C020</provider_no>
<agency_id>97759</agency_id>
<incident_id>2235</incident_id>
<upload_result>Success</upload_result>
</incident_ir>
</incidents>

However...

When I try this:

loHTTP = CREATEOBJECT("wwHTTP")
lcUrl = [https://pcispreprod.dhmh.state.md.us/Pcis2New2a/upload/incident]
loHTTP.cusername = [tester]
loHTTP.cpassword = lcPassword

*** Set mode to multi-part form
loHttp.nHttpPostMode = 4

*** Posting XML
lcXML = FILETOSTR("test3.xml") &&Hard coded for name for testing
loHTTP.AddPostKey() && Clear POST buffer
loHTTP.AddPostKey(lcXML)
lcString = loHTTP.HttpGet(lcUrl)

What I get back is (I tried all Post Modes out of frustration):
If loHttp.nHttpPostMode = 1:
<incidents>
<upload_result>Fail</upload_result>
<upload_error>4.Unknown error occurred: Expected 'EOF'.</upload_error>
</incidents>

If loHttp.nHttpPostMode = 2:
<incidents>
<upload_result>Fail</upload_result>
<upload_error>3.Unknown error occurred: Stream ended unexpectedly</upload_error>
</incidents>

If loHttp.nHttpPostMode = 4:
<incidents>
<upload_result>Fail</upload_result>
<upload_error>4.Unknown error occurred: Start of root element expected.</upload_error>
</incidents>

Anybody know what I can be doing wrong? Again, this exact XML file uploads fine manually. I even tested the XML file at the W3Schools validator: http://www.w3schools.com/xml/xml_validator.asp and it says "No errors".

Help! Thanks in advance!
-- John Kiernan, VocShop


Viewing all articles
Browse latest Browse all 10393

Trending Articles