我正在尝试使用JAX-WS发布的Web服务,这是我以前从未做过的,所以请耐心等待。 在我的本地环境中执行nusoap调用时,它会提供所有请求的数据。但是,一旦我将Java应用程序部署到我的Dev环境,它就会从服务器端返回一个空指针异常。
以下是我的代码片段(很高兴提供您可能需要的任何进一步信息,因为我之前从未使用过JAX WS)。在此先感谢!!!
XML文件,发布在下面的示例网址(相关部分)
中http://services.myapp.dev.com:8080/myapp-1.0-SNAPSHOT/MyService?wsdl
/ *内容* /
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后端服务:
@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测试脚本
<?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;
}
?>
答案 0 :(得分:0)
经过一番研究后,我发现问题是什么以及如何解决问题,所以在这里我发布了我所做的事情以防其他人遇到类似的问题:
在请求部署到Development的Tomcat Server Log之后,我发现了这个异常:
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)
所以我认为没有加载新的类和DAO,这是通过将条目添加到我的context.xml文件(位于META-INF文件夹中)来解决的。
<Environment name="DailyRecord" override="false" type="java.lang.String" value="com.myapp.dao.oracle.DailyRecordDAO"/>
这样做之后我重建了应用程序,并且没有问题地部署了新生成的.war文件。