xml - Axis 2 : "URI cannot be null" using Tomcat 8

标签 xml ant tomcat7 axis2 tomcat8

我将 Axis2/Java (1.6.2) 安装为 Tomcat (8.0.5) Webapp。

我开发了两个服务(HelloWorld 和简单计算器),它们运行良好。

现在,我尝试使用一种从外部 XML 读取信息的方法开发服务。

此文件位于此目录中:“$CATALINA_HOME/webapps/axis2/myService/”。

我使用 Ant 编译 .aar 存档。

当我通过url调用这个方法时

http://127.0.0.1:8080/axis2/services/InventoryCheck/doCheck?args0=12&args1=9

我收到:

<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">URI cannot be null</soapenv:Text>
</soapenv:Reason>

我在 Tomcat 7 上尝试了同样的服务,它工作正常。

我该如何解决?

谢谢


这是服务 java 类:

public class InventoryCheckService {

private String path = "myService/products.xml";

public boolean doCheck(String sku, int quantity){

    MessageContext msgContext = MessageContext.getCurrentMessageContext();
    ServletContext servletContext = (ServletContext) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
    String realPath = servletContext.getRealPath(path);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    factory.setNamespaceAware(true);

    Document doc = null;
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.parse(realPath);
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

    ReaderXML reader = new ReaderXML(doc);
    Product product = reader.getBySku(sku);

    return (product != null) && (product.getQuantity() >= quantity);

}
}

如果我将字符串 realPath 定义为 products.xml 文件的绝对路径,它工作正常。所以问题出在这三行:

MessageContext msgContext = MessageContext.getCurrentMessageContext();
ServletContext servletContext = (ServletContext) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
String realPath = servletContext.getRealPath(path);

还有两个简单的 java 类定义了 Object ReaderXML 和 Product。

这是 services.xml 文件:

<service name="InventoryCheck">

<description>
    Webservice Inventory Check
</description>

<messageReceivers>
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>

<parameter name="ServiceClass">com.myService.service.InventoryCheckService</parameter>

</service>

最佳答案

已解决:

为了使该服务也能与 Tomcat 8 一起工作,我只更改了字符串路径

来自:

private String path = "myService/products.xml";

到:

private String path = "/myService/products.xml";

这个不带“/”的字符串只适用于 Tomcat 7 而不适用于 Tomcat 8.0.5。

关于xml - Axis 2 : "URI cannot be null" using Tomcat 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23384550/

相关文章:

c# - XML 解析错误 : not well-formed, MasterPage asp.net

xml - 如何将版本maven插件添加到pom.xml?

sql - ANT sql 任务 : How to run SQL and PL/SQL and notice execution failure?

java - 使用 VisualVM 分析内存泄漏

Tomcat7 允许访问多个主机配置的管理器应用程序

java - Spring Integration Mail - 将 XML 转换为 Java Config

android - 将 Doclava 与 Ant 和 Android 一起使用

java - 替换任务不支持嵌套文件集

java - Java和Tomcat 7中的UTF-8解码问题

c# - 我的 LINQ to XML 代码中的空引用异常