/* * TestCommRest.java * * Created on 1 October 2016 * * Version 1.0 * * Copyright (c) Kieran Greer */ package org.licas_test; import org.jlog2.CustomLoggerFactory; import org.jlog2.LoggerFactory; import org.jlog2.LoggerHandler; import org.licas.call.CallObject; import org.licas.call.MethodFactory; import org.licas.ws.WsMethodInfo; import org.licas_text.util.XmlHtmlHandler; import org.licas_xml.abs.Element; import org.licas_xml.model.XmlHandler; /** * Test the REST interface calling mechanism. * @author Kieran Greer */ public class TestCommRest { /** * Create a new instance of TestCommRest. * @param args input arguments. */ public TestCommRest(String[] args) throws Exception { LoggerFactory.setLoggerFactory(new CustomLoggerFactory()); test1(); } /** Execute the query on the endpoint */ private void test1() { String endpoint; //endpoint address String theQuery; //the query String reply; //the reply WsMethodInfo methodInfo; //message info CallObject call; //call object Element replyXml; //reply xml try { //note this does not terminate completely endpoint = "http://www.webservicex.net/ConvertAcceleration.asmx/ChangeAccelerationUnit"; theQuery = "?AccelerationValue=100&fromAccelerationUnit=centigal&toAccelerationUnit=decigal"; call = new CallObject(); methodInfo = MethodFactory.createRestCall(endpoint, theQuery); reply = (String)call.call(methodInfo); if (reply != null) { try { reply = XmlHtmlHandler.decodeString(reply); replyXml = XmlHandler.stringToElement(reply); System.out.println(XmlHandler.xmlToFormattedString(replyXml)); } catch (Exception foex) { System.out.println(reply); } } else { System.out.println("No query reply."); } } catch (Exception ex) { ex.printStackTrace(); } } /** * Main class to initialise the tests. * @param args the command line arguments. */ public static void main(String[] args) { try { new TestCommRest(args); } catch (Exception ex) { ex.printStackTrace(System.out); } } }