Foros de discusión

How to consume JSON Webservice from java client in liferay?

Shibu K V, modificado hace 11 años.

How to consume JSON Webservice from java client in liferay?

New Member Mensajes: 13 Fecha de incorporación: 28/11/12 Mensajes recientes
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {

Map countryList = new HashMap();

String str = "http://10.10.10.25/TEPortalIntegration/CustomerPortalAppIntegrationService.svc/PaymentSchedule/PEPL/Unit336";

try {
URL url = new URL(str);

URLConnection urlc = url.openConnection();

BufferedReader bfr = new BufferedReader(new InputStreamReader(urlc.getInputStream()));

String line, title, des;

while ((line = bfr.readLine()) != null) {

JSONArray jsa = new JSONArray(line);

for (int i = 0; i < jsa.length(); i++) {
JSONObject jo = (JSONObject) jsa.get(i);

title = jo.getString("Amount");

countryList.put(i, title);
}

renderRequest.setAttribute("out-string", countryList);

super.doView(renderRequest, renderResponse);
}
} catch (Exception e) {

}
}

JSP CODE:
Country <select id="countryList">
<option value="0">-- Please Select amoun --</option>
<%
// String stringFromMyPortlet = (String)renderRequest.getAttribute("out-string");
Map countryList = (HashMap) renderRequest.getAttribute("out-string");

Iterator it = countryList.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
%>
<option value="<%=pairs.getKey()%>"><%=pairs.getValue()%></option>
<%
out.println(countryList.size());}
%>
This code is not giving me the result... please help me to fix it...