Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Velocity / XML response

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do not you parse the response xml in the server and format it in the way you like and flush it to the browser.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!