我有一个Java地图,我想将它发送到Web服务。 Web Service需要XML。
实施例
Map<String, String> dummyMap = new HashMap<String, String>();
dummyMap.put("A", "a");
dummyMap.put("B", "b");
dummyMap.put("C", "c");
dummyMap.put("D", "d");
是否有工具可以发送此Map,该内部转换为XML并以Java形式发送到Web服务?
答案 0 :(得分:0)
试试这个...我正在使用你的地图....填写我已设置评论的其他细节....
默认情况下,连接将是POST ...
import java.util.HashMap;
import java.util.Map;
import cjm.component.mb.commons.MBConstants;
import cjm.component.mb.ws.WSMessenger;
public class TestClass
{
public static void main(String[] args)
{
try
{
Map<String, String> dummyMap = new HashMap<String, String>();
dummyMap.put("A", "a");
dummyMap.put("B", "b");
dummyMap.put("C", "c");
dummyMap.put("D", "d");
WSMessenger wsMessenger = new WSMessenger();
String communicationURL = "http://whatever"; //Web Service Host URL
Map<String, String> propertyMap = new HashMap<String, String>(); // add all the properties related to the Web Service (like Hostname, Content Map, etc.) to this map
Map<String, Object> responseMap = wsMessenger.sendRequest(dummyMap, communicationURL , propertyMap );
System.out.println(responseMap.get(MBConstants.STATUS)); //Web Service hit Status Code
System.out.println(responseMap.get(MBConstants.RESPONSE_XML)); //Web Service Response as an XML
System.out.println(responseMap.get(MBConstants.RESPONSE)); //Web Service Response as a Map
}
catch (Exception e)
{
e.printStackTrace();
}
}
}