调用方法
private static void YNKY(){
try {
String xml = FileUtil.getFileToString("JTAutoClaim.xml");//获取要发送的报文
String result = XmlUtil.getXML("CommonAirDelayPort", "TransToClaimCommonAirDelay", xml, XmlUtil.UAT_SERVER);
} catch (Exception e) {
e.printStackTrace();
}finally {
}
工具类:
public class XmlUtil {
public static final String INT_SERVER="int";
public static final String UAT_SERVER="uat";
public static final String LOCAL_SERVER="local";
public static final String IP_SERVER="ip";
/**
* 调webservice接口获取xml
*/
public static String getXML(String port, String methodName, String xml,String server) throws AxisFault {
String retXML="";
String strUrl="";
String nameSpace = "http://service.wsCallcenter.sunshine.com/";
if("uat".equals(server)){
strUrl="http://10.8.198.39:7007/wsCallcenterAuto/"+port;
}else if ("int".equals(server)){
strUrl = "http://10.8.198.37:7051/wsCallcenter/" + port;
}else{
strUrl="http://localhost:7001/WebRoot/"+port;
}
RPCServiceClient serviceClient = null;
try {
serviceClient=new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(strUrl);
options.setTo(targetEPR);
options.setTimeOutInMilliSeconds(10000000);
options.setManageSession(true);
serviceClient.cleanupTransport();
// 指定要调用的addStudent方法及WSDL文件的命名空间
final QName qName = new QName(nameSpace, methodName);
// 域名不检查
serviceClient.getOptions().setProperty(HTTPConstants.CHUNKED, "false");
// 调用addStudent方法并输出该方法的返回值
retXML= serviceClient.invokeBlocking(qName, new Object[] { xml }, new Class[] { String.class })[0]
.toString();
} catch (AxisFault e) {
e.printStackTrace();
}finally {
if(serviceClient!=null){
serviceClient.cleanupTransport();
serviceClient.cleanup();
}
}
return retXML;
}
/**
* 读取本地文件转成字符串
*/
public static String getFileToString(String xmlName) throws Exception{
File file = new File("D:\\jarnew\\autoclaim\\wsCallcenterClient2\\src\\com\\sunshine\\file\\"+xmlName);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
byte[] data = null;
byte[] b = new byte[1024];
int read = 0;
FileInputStream in = new FileInputStream(file);
while ( ( read = in.read( b ) ) > 0 )
{
byteOut.write( b, 0, read );
}
data = byteOut.toByteArray();
in.close();
String result = new String( data );
return result;
}
}
}