我在尝试调用SOAP服务时遇到错误。在我们的应用程序中,OSGi Bundle(在AEM-JDK 1.8上运行)试图使用SOAP Web服务。存根是使用Apache CXF 3.3.1生成的。点击SOAP服务后,我得到了一个空指针异常。这是我们看到的错误日志:
com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: java.lang.NullPointerException Please see the server log to find more detail regarding exact cause of the failure.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at com.sun.proxy.$Proxy274.processSearch(Unknown Source)
在查看服务端的日志时,日志似乎指向空指针异常:
[5/30/19 16:42:27:953 EDT] 00017406 EndpointMetho E <Null Message>
java.lang.NullPointerException
at com.XXXX.edms.services.search.EDRSearchServiceSOAPImpl.processSearch(EDRSearchServiceSOAPImpl.java:69)
at sun.reflect.GeneratedMethodAccessor97.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:471)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:79)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:964)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1104)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:914)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:456)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:518)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:309)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84)
at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1818)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1720)
尽管我没有直接访问代码的权限,但是我得到的信息是抛出Null指针异常的对象是'metaDataList'。这是负责进行SOAP调用的代码片段:
SearchRequest request = getSearchRequest();
EDRSearchServiceSOAPImplService edrSearchServiceSOAPImplService = new EDRSearchServiceSOAPImplService();
EDRSearchServiceSOAPImpl edrSearchServiceSOAPImpl = edrSearchServiceSOAPImplService.getEDRSearchServiceSOAPImplPort();
SearchResponse searchResponse = edrSearchServiceSOAPImpl.processSearch(request, userCredentials);
System.out.println("response is====================="+searchResponse);
getSearchRequest()方法如下:
public SearchRequest getSearchRequest() {
DocumentLaunchSettings docLaunchSettings = new DocumentLaunchSettings();
SearchRequest searchRequest = new SearchRequest();
docLaunchSettings.setLauncher("dev_lom");
docLaunchSettings.setShowLink(true);
docLaunchSettings.setUseChronicleId(true);
DocumentACLSettings docACLSettings = new DocumentACLSettings();
docACLSettings.setReturnACL(true);
searchRequest.setDocbase("edmsdev");
searchRequest.setVersion("1.0");
searchRequest.setMaxNumberOfDocuments("1000");
//searchRequest.setObjectType("dm_document");
searchRequest.setObjectType("dm_document");
searchRequest.getFolderPaths().add("/");
//searchRequest.getFolderPaths().add("/eLibrary/Fleet and Remarketing");
searchRequest.setDocumentLaunchSettings(docLaunchSettings);
searchRequest.setDocumentACLSettings(docACLSettings);
String[] metaDataList = new String[] { "object_name", "r_object_id", "r_object_type" };
//String[] metaDataList = new String[] { "r_object_id" };
searchRequest.getMetaDataList().addAll(Arrays.asList(metaDataList));
List<LogicalOp> logicalOpList = searchRequest.getSearchCriteria();
LogicalOp logicalOp = new LogicalOp();
logicalOp.setType("metadata");
logicalOp.setRelational("equals");
logicalOp.setLogical("and");
logicalOp.setName("i_chronicle_id");
logicalOp.setValue("0900cad9824ba5bf");
logicalOpList.add(logicalOp);
return searchRequest;
}
但是,在我们的代码中,我们确保该值不为null。这是我们的设置方法,如方法getSearchRequest()所示:
String[] metaDataList = new String[] { "object_name", "r_object_id", "r_object_type" };
再次,只是为了确保它不为null,我已经调试了代码,并且在检查时可以看到对象设置正确。这是为SearchRequest对象生成的存根:
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "searchRequest", propOrder = {
"metaDataList"
})
public class SearchRequest {
@XmlElement(required = true)
protected List<String> metaDataList;
public List<String> getMetaDataList() {
if (metaDataList == null) {
metaDataList = new ArrayList<String>();
}
return this.metaDataList;
}
public void setMetaDataList(List<String> metaDataList) {
this.metaDataList = metaDataList;
}
}
它没有metaDataList的设置方法,我补充说,但我认为它没有任何区别。
我还注意到,在xsd中,类型设置为xs:string,而在代码中,类型为java.util.List。我不知道这是否可能是NullPointerException的原因。
有趣的是,当我在独立的Java应用程序中尝试相同的代码段时,可以看到成功的SOAP调用。但是只有在AEM中,我才遇到这个问题。我不知道这里有什么不同。
<xs:complexType name="searchRequest">
<xs:sequence>
<xs:element name="metaDataList" type="xs:string" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>