我正在尝试使用spring-ws-2.2.0&amp ;;开发SOAP Web服务客户端。 spring-boot-1.1.8在一个独立的应用程序中,但是我收到了这个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'marshaller' defined in class pcc_load.ApexConfiguration: Invocation of init method
failed; nested exception is org.springframework.oxm.UncategorizedMappingException:
Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated:
javax.xml.bind.JAXBException: "pcc_load/src/com/company/dept/apex/stubs/ObjectFactory.java" doesnt contain ObjectFactory.class or jaxb.index
- with linked exception:
[javax.xml.bind.JAXBException: "pcc_load/src/com/company/department/apex/stubs/ObjectFactory.java" doesnt contain ObjectFactory.class or jaxb.index]
我使用ant& amp;创建了所有存根。 wsdl没有任何错误,这里是wsdl:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:s0="PCCDATA_APEX_WS" xmlns:tns1="dsws.businessobjects.com"
targetNamespace="PCCDATA_APEX_WS" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="BIServices">
<types>
<s:schema elementFormDefault="qualified" targetNamespace="PCCDATA_APEX_WS">
<s:simpleType name="Operator">
<s:restriction base="s:string">
<s:enumeration value="EQUAL" />
<s:enumeration value="GREATER" />
<s:enumeration value="GREATER_OR_EQUAL" />
<s:enumeration value="LESS" />
<s:enumeration value="LESS_OR_EQUAL" />
<s:enumeration value="NOT_EQUAL" />
<s:enumeration value="INLIST" />
<s:enumeration value="NOT_INLIST" />
</s:restriction>
</s:simpleType>
<s:complexType name="FilterCondition">
<s:sequence>
<s:element name="value" type="s:string" />
<s:element name="operator" type="s0:Operator" />
</s:sequence>
</s:complexType>
<s:complexType name="LovValueIndex">
<s:sequence>
<s:element name="valueofPrompt" type="s:string" />
<s:element name="index" type="s:string" />
</s:sequence>
</s:complexType>
<s:complexType name="DrillFilter">
<s:sequence>
<s:element name="dimension" type="s:string" />
<s:element name="value" type="s:string" />
<s:element name="operator" type="s0:Operator" />
</s:sequence>
</s:complexType>
<s:element name="GetReportBlock_PCCDATA_APEX_WS">
<s:complexType>
<s:sequence>
<s:element name="login" type="s:string" minOccurs="0"
nillable="true" />
<s:element name="password" type="s:string" minOccurs="0"
nillable="true" />
<s:element name="_Business_Segment__Multiple__Optional_"
type="s0:LovValueIndex" minOccurs="0" maxOccurs="unbounded"
nillable="true" />
<s:element name="resetState" type="s:boolean" minOccurs="0"
nillable="true" />
<s:element name="refresh" type="s:boolean" minOccurs="0"
nillable="true" />
<s:element name="getFromLatestDocumentInstance" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="getFromUserInstance" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="turnOutputToVTable" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="closeDocument" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="startRow" type="s:int" minOccurs="0"
nillable="true" />
<s:element name="endRow" type="s:int" minOccurs="0"
nillable="true" />
</s:sequence>
</s:complexType>
</s:element>
<s:simpleType name="DrillOperation">
<s:restriction base="s:string">
<s:enumeration value="UP" />
<s:enumeration value="DOWN" />
</s:restriction>
</s:simpleType>
<s:complexType name="DrillPath">
<s:sequence>
<s:element name="from" type="s:string" />
<s:element name="value" type="s:string" />
<s:element name="drillOperation" type="s0:DrillOperation" />
</s:sequence>
</s:complexType>
<s:element name="Drill_PCCDATA_APEX_WS">
<s:complexType>
<s:sequence>
<s:element name="login" type="s:string" minOccurs="0"
nillable="true" />
<s:element name="password" type="s:string" minOccurs="0"
nillable="true" />
<s:element name="drillPath" type="s0:DrillPath"
minOccurs="0" maxOccurs="unbounded" nillable="true" />
<s:element name="filter" type="s0:DrillFilter"
minOccurs="0" maxOccurs="unbounded" nillable="true" />
<s:element name="_Business_Segment__Multiple__Optional_"
type="s0:LovValueIndex" minOccurs="0" maxOccurs="unbounded"
nillable="true" />
<s:element name="resetState" type="s:boolean" minOccurs="0"
nillable="true" />
<s:element name="refresh" type="s:boolean" minOccurs="0"
nillable="true" />
<s:element name="getFromLatestDocumentInstance" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="getFromUserInstance" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="turnOutputToVTable" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="closeDocument" type="s:boolean"
minOccurs="0" nillable="true" />
<s:element name="startRow" type="s:int" minOccurs="0"
nillable="true" />
<s:element name="endRow" type="s:int" minOccurs="0"
nillable="true" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="TRow">
<s:sequence>
<s:element name="cell" type="s:anyType" maxOccurs="unbounded"
nillable="true" />
</s:sequence>
</s:complexType>
<s:complexType name="TTable">
<s:sequence>
<s:element name="row" maxOccurs="unbounded" type="s0:TRow" />
</s:sequence>
</s:complexType>
<s:complexType name="THeader">
<s:sequence>
<s:element name="row" maxOccurs="unbounded" type="s0:TRow" />
</s:sequence>
</s:complexType>
<s:complexType name="TFooter">
<s:sequence>
<s:element name="row" maxOccurs="unbounded" type="s0:TRow" />
</s:sequence>
</s:complexType>
<s:element name="GetReportBlock_PCCDATA_APEX_WSResponse">
<s:complexType>
<s:sequence>
<s:element name="table" type="s0:TTable" />
<s:element name="headers" type="s0:THeader" />
<s:element name="footers" type="s0:TFooter" />
<s:element name="user" type="s:string" />
<s:element name="documentation" type="s:string" />
<s:element name="documentname" type="s:string" />
<s:element name="lastrefreshdate" type="s:dateTime" />
<s:element name="creationdate" type="s:dateTime" />
<s:element name="creator" type="s:string" />
<s:element name="isScheduled" type="s:boolean" />
<s:element name="scheduleStartTime" type="s:dateTime" />
<s:element name="scheduleEndTime" type="s:dateTime" />
<s:element name="tableType" type="s:string" />
<s:element name="nbColumns" type="s:int" />
<s:element name="nbLines" type="s:int" />
<s:element name="message" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="Drill_PCCDATA_APEX_WSResponse">
<s:complexType>
<s:sequence>
<s:element name="table" type="s0:TTable" />
<s:element name="headers" type="s0:THeader" />
<s:element name="footers" type="s0:TFooter" />
<s:element name="user" type="s:string" />
<s:element name="documentation" type="s:string" />
<s:element name="documentname" type="s:string" />
<s:element name="lastrefreshdate" type="s:dateTime" />
<s:element name="creationdate" type="s:dateTime" />
<s:element name="creator" type="s:string" />
<s:element name="isScheduled" type="s:boolean" />
<s:element name="scheduleStartTime" type="s:dateTime" />
<s:element name="scheduleEndTime" type="s:dateTime" />
<s:element name="tableType" type="s:string" />
<s:element name="nbColumns" type="s:int" />
<s:element name="nbLines" type="s:int" />
<s:element name="message" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="QaaWSHeader">
<s:complexType>
<s:sequence>
<s:element name="sessionID" type="s:string" minOccurs="0"
maxOccurs="1" nillable="true" />
<s:element name="serializedSession" type="s:string"
minOccurs="0" maxOccurs="1" nillable="true" />
<s:element name="ClientType" type="s:string" minOccurs="0"
maxOccurs="1" nillable="true" />
<s:element name="AuditingObjectID" type="s:string"
minOccurs="0" maxOccurs="1" nillable="true" />
<s:element name="AuditingObjectName" type="s:string"
minOccurs="0" maxOccurs="1" nillable="true" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<message name="GetReportBlock_PCCDATA_APEX_WSSoapIn">
<part name="parameters" element="s0:GetReportBlock_PCCDATA_APEX_WS" />
<part name="request_header" element="s0:QaaWSHeader" />
</message>
<message name="GetReportBlock_PCCDATA_APEX_WSSoapOut">
<part name="parameters" element="s0:GetReportBlock_PCCDATA_APEX_WSResponse" />
</message>
<message name="Drill_PCCDATA_APEX_WSSoapIn">
<part name="parameters" element="s0:Drill_PCCDATA_APEX_WS" />
<part name="request_header" element="s0:QaaWSHeader" />
</message>
<message name="Drill_PCCDATA_APEX_WSSoapOut">
<part name="parameters" element="s0:Drill_PCCDATA_APEX_WSResponse" />
</message>
<portType name="BIServicesSoap">
<operation name="GetReportBlock_PCCDATA_APEX_WS">
<documentation></documentation>
<input message="s0:GetReportBlock_PCCDATA_APEX_WSSoapIn" />
<output message="s0:GetReportBlock_PCCDATA_APEX_WSSoapOut" />
</operation>
<operation name="Drill_PCCDATA_APEX_WS">
<documentation></documentation>
<input message="s0:Drill_PCCDATA_APEX_WSSoapIn" />
<output message="s0:Drill_PCCDATA_APEX_WSSoapOut" />
</operation>
</portType>
<binding name="BIServicesSoap" type="s0:BIServicesSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="GetReportBlock_PCCDATA_APEX_WS">
<documentation></documentation>
<soap:operation soapAction="PCCDATA_APEX_WS/GetReportBlock_PCCDATA_APEX_WS"
style="document" />
<input>
<soap:header message="s0:GetReportBlock_PCCDATA_APEX_WSSoapIn"
part="request_header" use="literal">
<soap:headerfault message="s0:GetReportBlock_PCCDATA_APEX_WSSoapIn"
part="request_header" use="literal" />
</soap:header>
<soap:body use="literal" parts="parameters" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
<operation name="Drill_PCCDATA_APEX_WS">
<documentation></documentation>
<soap:operation soapAction="PCCDATA_APEX_WS/Drill_PCCDATA_APEX_WS"
style="document" />
<input>
<soap:header message="s0:Drill_PCCDATA_APEX_WSSoapIn"
part="request_header" use="literal">
<soap:headerfault message="s0:Drill_PCCDATA_APEX_WSSoapIn"
part="request_header" use="literal" />
</soap:header>
<soap:body use="literal" parts="parameters" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="PCCDATA_APEX_WS">
<documentation></documentation>
<port name="BIServicesSoap" binding="s0:BIServicesSoap">
<soap:address
location="http://xyz.test.app.company.com:8080/dswsbobje/qaawsservices/queryasaservice/biws?cuid=AQyF0wiLGyhNgX41XOXwiEs&authType=secEnterprise&locale=en&timeout=60&ConvertAnyType=true" />
</port>
</service>
</definitions>
我在春天使用了本教程/指南:
https://spring.io/guides/gs/consuming-web-service/
这是我的主要内容:
import org.springframework.context.ApplicationContext;
import org.springframework.boot.SpringApplication;
public class main {
public static void main (String [] args)
{
ApplicationContext ctx = SpringApplication.run(ApexConfiguration.class);
apexClient newApexClient = ctx.getBean(apexClient.class);
newApexClient.callDrillPCCDATAAPEXWS();
}
}
这是我的Jaxb2Marshaller配置类:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class ApexConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
/* I tried these values but getting the same error?
* 1) "apex.wsdl"
* or
* 2) "/apex.wsdl"
3) "com.company.dept.apex.stubs"
* or
* 4) fully qualified package that stubs are generated in "com.company.dept.apex.stubs.ObjectFactory"
*/
marshaller.setContextPath("apex.wsdl");
return marshaller;
}
@Bean
public apexClient weatherClient(Jaxb2Marshaller marshaller) {
apexClient client = new apexClient();
client.setDefaultUri("http://xyz.test.app.company.com:8080");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
以下是实际的客户端Web服务实现&amp;请求电话:
import javax.xml.bind.JAXBElement;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.beans.factory.InitializingBean;
import com.company.dept.apex.stubs.DrillPCCDATAAPEXWS;
import com.company.dept.apex.stubs.DrillPCCDATAAPEXWSResponse;
import com.company.dept.apex.stubs.GetReportBlockPCCDATAAPEXWS;
import com.company.dept.apex.stubs.GetReportBlockPCCDATAAPEXWSResponse;
import com.company.dept.apex.stubs.ObjectFactory;
public class apexClient extends WebServiceGatewaySupport {
private WebServiceTemplate webServiceTemplate;
//ZBIJOB248/testme05
public String username="user1234";
public String pass="pass1234";
public DrillPCCDATAAPEXWSResponse callDrillPCCDATAAPEXWS()
{
setDefaultUri("http://xyz.test.app.company.com:8080/dswsbobje/qaawsservices/queryasaservice/biws?cuid=AQyF0wiLGyhNgX41XOXwiEs&authType=secEnterprise&locale=en&timeout=60&ConvertAnyType=true");
DrillPCCDATAAPEXWS request = new DrillPCCDATAAPEXWS();
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> login = objectFactory.createDrillPCCDATAAPEXWSLogin(username);
JAXBElement<String> password = objectFactory.createDrillPCCDATAAPEXWSPassword(pass);
request.setLogin(login);
request.setPassword(password);
//
DrillPCCDATAAPEXWSResponse response =
(DrillPCCDATAAPEXWSResponse) getWebServiceTemplate().marshalSendAndReceive(
request, new SoapActionCallback("http://xyz.test.app.company.com:8080/dswsbobje/qaawsservices/queryasaservice/biws?cuid=AQyF0wiLGyhNgX41XOXwiEs&authType=secEnterprise&locale=en&timeout=60&ConvertAnyType=true"));
return response;
}
public GetReportBlockPCCDATAAPEXWSResponse callGetReportBlockPCCDATAAPEXWSResponse()
{
setDefaultUri("http://xyz.test.app.company.com:8080/dswsbobje/qaawsservices/queryasaservice/biws?cuid=AQyF0wiLGyhNgX41XOXwiEs&authType=secEnterprise&locale=en&timeout=60&ConvertAnyType=true");
GetReportBlockPCCDATAAPEXWS request = new GetReportBlockPCCDATAAPEXWS();
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> login = objectFactory.createDrillPCCDATAAPEXWSLogin(username);
JAXBElement<String> password = objectFactory.createDrillPCCDATAAPEXWSPassword(pass);
request.setLogin(login);
request.setPassword(password);
//
GetReportBlockPCCDATAAPEXWSResponse response = (GetReportBlockPCCDATAAPEXWSResponse) getWebServiceTemplate().marshalSendAndReceive(
request, new SoapActionCallback("http://xyz.test.app.company.com:8080/dswsbobje/qaawsservices/queryasaservice/biws?cuid=AQyF0wiLGyhNgX41XOXwiEs&authType=secEnterprise&locale=en&timeout=60&ConvertAnyType=true"));
return response;
}
}//end client
似乎问题在于我传递给“marshaller.setContextPath(”?“);”它的格式错误或无法找到它。
1)我该如何解决这个问题?这个实现的任何其他问题?
2)(可选)为了知识“marshaller.setContextPath()”&amp;还有“client.setDefaultUri()”?
谢谢大家。
答案 0 :(得分:0)
好像你已经尝试过了,但是上下文路径应该是你生成JAXB类的包名,即包含ObjectFactory
的包。在您的情况下,它应该是com.company.dept.apex.stubs
。生成的类应该在类路径上。
或者,您可以通过设置Jaxb2Marshaller
属性来配置classesToBeBound
,而不是使用上下文路径,只需提供您想要(联合国)编组的类。
可选问题的AS:上下文路径和默认URI彼此无关:上下文路径用于JAXB编组目的;默认URI是WebServiceTemplate
连接到的默认URL(如果您不提供URL参数)。