wood burning stoves*
The moose likes Servlets and the fly likes Velocity / XML response   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Velocity / XML response   " Watch "Velocity / XML response   " New topic
Author

Velocity / XML response

Ruth Marx
Greenhorn

Joined: Jul 12, 2007
Posts: 11
Hi everyone, I'd be grateful if someone could help me out here. I use apache velocity to generate an xml request to send to a gateway which processes the request and sends an xml response. At the moment, the response (xmlString) is outputted to the browser as a string (see code below).

I want to separate out the elements in the response and display them in a more readable format on the browser eg.


Name = "xyz"
Address = "xyz"

Here is a snippet of what I have. What is the quickest way to extract the individual elements from the xml response and display them?

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {

DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(new File( _FOLDER_UPLOAD ));
PrintWriter writer = response.getWriter();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(60000000);

String xmlResult = executeCheck( upload, request);
manageResponse( writer, xmlResult);

} catch (FileUploadException e) {
e.printStackTrace();
}
}

private void manageResponse(PrintWriter writer, String xmlResult) {
writer.println(xmlResult);
writer.flush();
}

private String executeCheck( ServletFileUpload upload, HttpServletRequest request ) throws FileUploadException, IOException {

List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while( iter.hasNext() ) {
System.out.println(items.toString());
FileItem item = (FileItem)iter.next();
if ( !item.isFormField() && item.getFieldName().equalsIgnoreCase("upload") ) {
InputStream in = item.getInputStream();
VasGatewayClient wsC = new VasGatewayClient( in, _URL );
return wsC.send();
}
}
return null;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Velocity / XML response
 
Similar Threads
HTTP Status 405 - HTTP method POST is not supported by this URL.
Uploading file in a database
How to redirect from servlet to JSP/Servlet with out executing the below code
Velocity / XML response
getting nullPointerException on line upload.parseRequest(request);