1 Reply Latest reply: Dec 4, 2011 2:30 PM by 903547 RSS

    SOAP Reponse contains &gt and &lt instead of < and >

    843830
      I am new to Web Services. I wrote a simple SOAP client in Java. It seems to work and I get the SOAP response back; however the XML response has < and > instead of < and >. Am I making a mistake in my source code? I have placed my source code below and the result that I get when I run the code. How do I get a proper response with < and > instead of &lt and &gt?


      Webservice Endpoint: http://www.webservicex.net/stockquote.asmx

      WSDL Location: http://www.webservicex.net/stockquote.asmx?wsdl

      From the <GetQuoteResult>, the reponse I get has &lt and &gt for < and >. However, when I past it here, the &lt and &gt are being converted to < and >.

      SOAP Response that I get:

      <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.
      xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
      " xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetQuoteResponse xmln
      s="http://www.webserviceX.NET/"><GetQuoteResult><StockQuotes><Stock>
      <Symbol>IBN</Symbol><Last>38.58</Last><Date>7/30/2
      010</Date><Time>10:24am</Time><Change>-0.35</Change&g
      t;<Open>38.42</Open><High>38.86</High><Low>38.29&l
      t;/Low><Volume>314170</Volume><MktCap>21.505B</MktCap&gt
      ;<PreviousClose>38.93</PreviousClose><PercentageChange>-0.90%&
      lt;/PercentageChange><AnnRange>28.53 - 45.95</AnnRange><Earns&
      gt;1.782</Earns><P-E>21.85</P-E><Name>ICICI Bank Limite&
      lt;/Name></Stock></StockQuotes></GetQuoteResult></GetQuoteRespons
      e></soap:Body></soap:Envelope>


      SOAP response that I am expecting:


      <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.
      xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
      " xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetQuoteResponse xmln
      s="http://www.webserviceX.NET/"><GetQuoteResult><StockQuotes><Stock>
      <Symbol>IBN</Symbol><Last>38.58</Last><Date>7/30/2
      010</Date><Time>10:24am</Time><Change>-0.35</Change&g
      t;<Open>38.42</Open><High>38.86</High><Low>38.29&l
      t;/Low><Volume>314170</Volume><MktCap>21.505B</MktCap&gt
      ;<PreviousClose>38.93</PreviousClose><PercentageChange>-0.90%&
      lt;/PercentageChange><AnnRange>28.53 - 45.95</AnnRange><Earns&
      gt;1.782</Earns><P-E>21.85</P-E><Name>ICICI Bank Limite&
      lt;/Name></Stock></StockQuotes></GetQuoteResult></GetQuoteRespons
      e></soap:Body></soap:Envelope>


      Source Code:
      import java.net.*;
      import java.io.*;
      
      
      public class stocksoapClient {
      
        public final static String DEFAULT_SERVER = "http://www.webservicex.net/stockquote.asmx";
        public final static String SOAP_ACTION = "http://www.webserviceX.NET/GetQuote";
      
        public static void main(String[] args) {
        
          String input = "IBN";
          String server = DEFAULT_SERVER;
          if (args.length >= 2) server = args[1];
          
          try {
               
                 Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.compaq.com", 8080));         
                 URL u = new URL(server);
                 URLConnection uc = u.openConnection(proxy);
                 HttpURLConnection connection = (HttpURLConnection) uc;
            
                 connection.setDoOutput(true);
                 connection.setDoInput(true);
                 connection.setRequestMethod("POST");
                 connection.setRequestProperty("Content-Type",  "text/xml; charset=utf-8");
                 connection.setRequestProperty("Content-Length",  String.valueOf(input.length()));
                 connection.setRequestProperty("SOAPAction", SOAP_ACTION);
            
                 //connection.connect();
                 OutputStream out = connection.getOutputStream();
                 Writer wout = new OutputStreamWriter(out);
                 
            
                 //wout.write("POST" + DEFAULT_SERVER  + "HTTP/1.1");
                 //wout.write("Host:www.webservicex.net");
                 //wout.write("Content-Type: text/xml; charset=utf-8");
                 //wout.write("Content-Length: " + String.valueOf(input.length()));
                 //wout.write("SOAPAction:" + SOAP_ACTION);          
                //wout.write("\n");      
            
                 wout.write("<?xml version='1.0' encoding='utf-8'?>");  
                 wout.write("<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>");
                 wout.write("<soap:Body>");
                 wout.write("<GetQuote xmlns='http://www.webserviceX.NET/'>");
                 wout.write("<symbol>"+input+"</symbol>");
                 wout.write("</GetQuote>");     
                 wout.write("</soap:Body>"); 
                 wout.write("</soap:Envelope>"); 
                 
            
                 wout.flush();
                 wout.close();
            
                 
      
                 BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                         
                 String line;      
            
            
                 //InputStream in = connection.getInputStream();
      
            
      
                 //int c;
                 while ((line=rd.readLine()) != null) {
      
                    System.out.println(line);
                 }
      
                 rd.close();
      
          } catch (IOException e) {
                 System.err.println(e); 
            }
        
        } 
      
      }