1

我正在尝试从我的应用程序中调用 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();
}
4

1 回答 1

0

前几天整理好了。基本上我现在正在使用 HttpURLConnection 在进行 Webservice 调用时在 java 代码本身中添加代理设置。刚刚结束这个问题,因为我的查询已经解决。

如果有人需要,将更新新代码。

于 2013-10-28T22:15:22.710 回答