我正在尝试从我的应用程序中调用 Web 服务。我的系统受防火墙保护,我使用代理访问任何外部 URL/互联网访问。该应用程序在 JBoss EAP 5.1 服务器上运行。应用程序无法写入服务 URL 并出现 IO 异常:“无法传输消息”。
但是,当我尝试使用 IE/Firefox 访问服务 URL 时,它正在打开。尽管我从浏览器收到的 XML 响应指出了一个通用错误 - “无效的请求参数...”,这很明显。因为我没有从浏览器发送正确的请求 XML。
我真的对这种差异感到困惑。我曾经相信 JBoss 会选择标准的 Windows 网络设置,但在我的情况下不是。
我的代码如下:
String strUrl = "http://theurlgoeshere";
String requestXml = "<request></request>";
String wsResponse="";
SOAPConnection conn = null;
try {
MessageFactory msgFac = MessageFactory.newInstance();
MimeHeaders mh = new MimeHeaders();
mh.setHeader("Content-Type", "text/xml; charset=UTF-8");
log.info("Request Xml:" + requestXml );
InputStream is = new ByteArrayInputStream(requestXml.getBytes("UTF-8"));
SOAPMessage reqMsg = msgFac.createMessage(mh, is);
SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
conn = conFac.createConnection();
SOAPMessage repMsg = conn.call(reqMsg, strUrl);
ByteArrayOutputStream out = new ByteArrayOutputStream();
repMsg.writeTo(out);
wsResponse = new String(out.toByteArray());
}
catch (Exception e) {
e.printStackTrace();
}