How to get Apache XML-RPC 3.1.3 compliance (ISO date format along with time zone) in Java 1.6

懵懂的女人 提交于 2019-12-24 04:51:53

问题


We are using Apache XML-RPC 3.1.3 to communicate with Air billing solution. In documentation its mentioned that apache xml-rpc follow date format as java.util.Date '19980717T14:08:55' but our vendor implemented date as 'yyyyMMdd'T'HH:mm:ssZ' addition with time zone :(

After reviewing documentation we come to know that, we need to develop custom data type to work with ISO different date format. http://ws.apache.org/xmlrpc/faq.html#nonstandard_date_format We tried to continue with provided example but end up with two errors

1 - pFormat variable not found in MyTypeFactory.java class

2 - no constructor found while pointing these changes in client class client.setTypeFactory(new MyTypeFactory());

Can someone please correct us if we are missing anything or share any other way to implement custom datatypes in Apache XML-RPC 3.1.3

Our client class code is

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://10.x.x.x:1234/Air"));
        config.setEnabledForExceptions(true);
        config.setBasicUserName("myUser");
        config.setBasicPassword("myPassword");
        config.setEncoding(XmlRpcClientConfigImpl.UTF8_ENCODING);

        config.setReplyTimeout(3 * 1000);
        config.setUserAgent("ITIVR/4.3/1.0"); //3.1 or 4.3
        client.setConfig(config);

        XmlRpcClient client = new XmlRpcClient();
        XmlRpcSunHttpTransport http = (XmlRpcSunHttpTransport) new XmlRpcSunHttpTransportFactory(client).getTransport();            

        Hashtable request = new Hashtable();
        request.put("originNodeType", new String("IVR"));
        request.put("originHostName", new String("ITIVR"));
        request.put("originTransactionID", new String(new SimpleDateFormat("ddMMyyyyHHmmss").format(new Date())));
        request.put("originTimeStamp", new Date());
        request.put("subscriberNumber", "0111111111");

        Vector v = new Vector();
        v.add(request);

        HashMap o =    (HashMap) http.sendRequest(new XmlRpcClientRequestImpl(config, "GetBalanceAndDate", v));

In this code we are getting error 'Data out of bounds' because we are not passing date in invalid format.


回答1:


After reviewing documentations we come to know that, its date format related issue. Apache XML-RPC default date format is without time zone and Air billing solution(Ericsson CS 5.1) accept date along with time zone.

We have fixed above both problems

Error 1 - By adding new format in SimpleDateFormat and replacing pFormat with newFormat() in MyTypeFactory class

Error 2 - By passing XmlRpcClient object in constructor, because XmlRpcClient is bass class of XmlRpcServer and XmlRpcClient :) e.g.

client.setTypeFactory(new MyTypeFactory(client));


来源:https://stackoverflow.com/questions/23763272/how-to-get-apache-xml-rpc-3-1-3-compliance-iso-date-format-along-with-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!