0

I have got question about better way to parse xml package to get some info.

First of all this is my html response from server:

 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
 <title>Error 404 Invalid SID.</title>
 </head>
 <body>
 <h2>HTTP ERROR: 404</h2>
 <p>Problem accessing /http-bind/. Reason:
 <pre>    Invalid SID.</pre></p>
 <hr /><i><small>Powered by Jetty://</small></i>   
 </body>
 </html>

This is openfire response when i send invalid frame. So i need to be sure that this status contains char sequence Invalid SID.

this is my code : res is object class = com.google.gwt.http.client.Response

if (res.getStatusCode() != Response.SC_OK){
   final XMLPacket resXML = XMLBuilder.fromXML(res.getText());
   if (resXML != null && resXML.getFirstChild("head") != null) {
      for (XMLPacket subPacket : resXML.getChildren("head")) {
           if (subPacket.toString().toUpperCase().contains("INVALID SID")) {
               Log.debug("HURRA SUCCESS");
            }
      }
   }
}

But i do not think that is the best way to do it. I am using GWT 2.5 . So my question is ther is better way to get info from html request using gwt ??

RAS
  • 8,100
  • 16
  • 64
  • 86
Łukasz Woźniczka
  • 1,625
  • 3
  • 28
  • 51
  • Does it have to be an html response? This is much easier if you use RequestFactory and just throw an exception from the server to the client to for bad data. – Deanna May 18 '13 at 15:43
  • No i must fire new event if server return that response. – Łukasz Woźniczka May 19 '13 at 11:35
  • I'd use the simplest way: `int errorCode = res.getStatusCode(); String errorMessage = res.getText().replaceFirst("^.*(.+)<\\/title>.*$", "$1");` – domax Feb 14 '14 at 17:29

0 Answers0