简体   繁体   English

简单的nusoap请求返回java.lang.nullPointerException

[英]Simple nusoap request returns java.lang.nullPointerException

I'm trying to consume a Web Service published by JAX-WS, which I have never done before so please bear with me. 我正在尝试使用JAX-WS发布的Web Service,这是我之前从未做过的,因此请耐心等待。 When performing the nusoap call in my local environment, it provides all data requested. 在我的本地环境中执行nusoap调用时,它将提供所有请求的数据。 However, once I deploy the java app to my Dev environment, it returns a null pointer exception from the server side. 但是,一旦将Java应用程序部署到我的Dev环境中,它就会从服务器端返回空指针异常。

Below are snippets of my code (would be glad to provide with any further info you may need, since i've never used JAX WS before). 以下是我的代码片段(很高兴为您提供您可能需要的更多信息,因为我以前从未使用过JAX WS)。 Thanks in advance!!! 提前致谢!!!

XML file, published in the example url below (relevant sections) XML文件,发布在下面的示例网址中(相关部分)

http://services.myapp.dev.com:8080/myapp-1.0-SNAPSHOT/MyService?wsdl

/* Content */ / *内容* /

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01  svn-revision#${svn.Last.Changed.Rev}. 
-->
<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01  svn-revision#${svn.Last.Changed.Rev}. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.myapp.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.myapp.com/" name="MyServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://service.myapp.com/" schemaLocation="http://services.myapp.com:8080/myapp-1.0-SNAPSHOT/MyService?xsd=1"/>
</xsd:schema>
</types>
<message name="SearchDailyRecords">
<part name="parameters" element="tns:SearchDailyRecords"/>
</message>
<message name="SearchDailyRecordsResponse">
<part name="parameters" element="tns:SearchDailyRecordsResponse"/>
</message>
<portType name="MyService">
<operation name="SearchDailyRecords">
<input wsam:Action="http://services.myapp.com:8080/myapp-1.0-SNAPSHOT/MyService/SearchDailyRecordsRequest" message="tns:SearchDailyRecords"/>
<output wsam:Action="http://services.myapp.com:8080/myapp-1.0-SNAPSHOT/MyService/SearchDailyRecordsResponse" message="tns:SearchDailyRecordsResponse"/>
<fault message="tns:Exception" name="Exception" wsam:Action="http://services.myapp.com:8080/myapp-1.0-SNAPSHOT/MyService/SearchDailyRecords/Fault/Exception"/>
</operation>
</portType>
<binding name="MyServicePortBinding" type="tns:MyService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="SearchDailyRecords">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="Exception">
<soap:fault name="Exception" use="literal"/>
</fault>
</operation>
</binding>
<service name="MyServiceService">
<port name="MyServicePort" binding="tns:MyServicePortBinding">
<soap:address location="http://services.myapp.com:8080/myapp-1.0-SNAPSHOT/MyService"/>
</port>
</service>
</definitions>

Java Backend Service: Java后端服务:

 @Override
    public @WebResult(name = "response")
    List<SearchDailyRecordsResponse> SearchDailyRecords(@WebParam(name = "employeeId") @XmlElement(required = true) String employeeId, @WebParam(name = "date") @XmlElement(required = true) String date) throws Exception {                   

        SearchDailyRecordsRequest request = new SearchDailyRecordsRequest();
        request.employeeId = employeeId;        
        request.date = date;

        try {

            IDailyRecordDAO dailyRecordDAO = (IDailyRecordDAO) DAOFactory.getInstance().getDAO("DailyRecord");

            List<DailyRecord> dailyRecords = registroGenericoDAO.get(request.employeeId, request.date);
            List<SearchDailyRecordsResponse> response = new ArrayList<SearchDailyRecordsResponse>();

            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");        

            for (DailyRecord dailyRecord : dailyRecords) {
                SearchDailyRecordsResponse searchDailyRecords = new SearchDailyRecordsResponse();
                searchDailyRecords.recordId = dailyRecord.getRecord().getId();                   
                /* some other info populating record */ 

                response.add(searchDailyRecords);
            }
            return response;
        } catch (Exception e) {
                Logger.getLogger(MyService.class.getName()).log(Level.WARNING, null, e);
                throw new Exception("Error getting daily records");
        }
    }
}

PHP test script PHP测试脚本

<?php

require_once('../backend/libraries/nusoap/nusoap.php');

$url = "http://services.myapp.com:8080/myapp-1.0-SNAPSHOT/MyService?wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new nusoap_client($url, 'wsdl');

try {
    echo 'try: ';

    /* date("d/m/Y") --> DATE FORMAT */

    $date = '06/05/2016';  

    $request = array(
        'employeeId' => 1234,
        'date' => $date
    );    


    $response = $client->call('SearchDailyRecords', array('request' => $request));    
    //die('<pre>'.print_r($client, true).'</pre>');


    if ($client->fault) {
    echo 'fault?: ';
        echo "<h2>Fault</h2><pre>";
        print_r($response);
        echo "</pre>";
    } else {
        $error = $client->getError();
        if ($error) {
            echo "<h2>Error</h2><pre>" . $error . "</pre>";
        } else {
            echo "<h2>Main</h2>";
            echo $response;
        }
    }

    // show soap request and response
    echo "<h2>Request</h2>";
    echo "<pre>" . htmlspecialchars(formatXmlString($client->request), ENT_QUOTES) . "</pre>";
    echo "<h2>Response</h2>";
    echo "<pre>" . htmlspecialchars(formatXmlString($client->response), ENT_QUOTES) . "</pre>";

    /******************************************/
} catch (SoapFault $exc) {
    die('<pre>' . print_r($exc, true) . '</pre>');
}

function formatXmlString($xml){
    $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml);
    $token      = strtok($xml, "\n");
    $result     = '';
    $pad        = 0; 
    $matches    = array();
    while ($token !== false) : 
        if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) : 
          $indent=0;
        elseif (preg_match('/^<\/\w/', $token, $matches)) :
          $pad--;
          $indent = 0;
        elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) :
          $indent=1;
        else :
          $indent = 0; 
        endif;
        $line    = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT);
        $result .= $line . "\n";
        $token   = strtok("\n");
        $pad    += $indent;
    endwhile; 
    return $result;
}

?> 

After some research, I found what the problem was and how to fix it, so here I'm posting what I did in case somebody else comes accross a similar issue: 经过研究后,我发现了问题所在以及解决方法,因此,在此发布我的工作,以防其他人遇到类似问题:

After requesting the Tomcat Server Log deployed to Development, i found this exception: 在请求将Tomcat服务器日志部署到Development之后,我发现了以下异常:

SEVERE: null
com.myappconfiguration.ConfigurationException: La variable DailyRecord no existe!
    at com.myapp.Configuration.getEnvironmentVariable(Configuration.java:17)
    at com.myapp.dao.DAOFactory.LoadDaoFromFile(DAOFactory.java:57)
    at com.myapp.dao.DAOFactory.getDAO(DAOFactory.java:42)
    at com.myapp.service.MyAppService.SeachDailyRecords(MyAppService.java:515)
    at sun.reflect.GeneratedMethodAccessor322.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:250)
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1063)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:979)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:950)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:825)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:380)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:651)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:264)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:218)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:159)
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:194)
    at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:80)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.naming.NameNotFoundException: Name [DailyRecord] is not bound in this Context. Unable to find [DailyRecord].
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    at com.myappconfiguration.Configuration.getEnvironmentVariable(Configuration.java:14)

So i figured a new Class and DAO was not being loaded, which was resolved by adding the entry to my context.xml file (located in the META-INF folder) 所以我想出了一个新的类,并且没有加载DAO,这是通过将条目添加到我的context.xml文件(位于META-INF文件夹中)来解决的

<Environment name="DailyRecord" override="false" type="java.lang.String" value="com.myapp.dao.oracle.DailyRecordDAO"/>

After doing that i rebuilt the app, and deployed the newly generated .war file without problems. 之后,我重新构建了该应用程序,并部署了新生成的.war文件,没有出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM