问题
i'm trying to use spring boot ws in order to create a SOAP service, but i'm facing the exception "No adapter for endpoint...".
here is my xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://nisws.it.fastweb"
targetNamespace="http://nisws.it.fastweb" elementFormDefault="qualified">
<xs:element name="doEventRequest" type="tns:doEventRequest"/>
<xs:element name="doEventResponse" type="tns:doEventResponse"/>
<xs:complexType name="doEventRequest">
<xs:sequence>
<xs:element name="header" type="tns:header"/>
<xs:element name="trackingbody" type="tns:trackingbody"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="header">
<xs:sequence>
<xs:element name="IdMessaggio" type="xs:string"/>
<xs:element name="NomeBE" type="xs:string"/>
<xs:element name="DataInserimentoBE" type="xs:string"/>
<xs:element name="Release" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="trackingbody">
<xs:all>
<xs:element name="Sorgente" type="xs:string"/>
<xs:element name="Parametri" type="tns:Parametri" minOccurs="0"/>
<xs:element name="Componenti" type="tns:Componenti" minOccurs="0"/>
</xs:all>
</xs:complexType>
<xs:complexType name="Parametri">
<xs:sequence>
<xs:element name="Parametro" type="tns:TagParametro" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TagParametro">
<xs:sequence>
<xs:element name="Descrizione" type="xs:string"/>
<xs:element name="Valore" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Componenti">
<xs:sequence>
<xs:element name="Componente" type="tns:TagComponente" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TagComponente">
<xs:sequence>
<xs:element name="ID" type="xs:string" minOccurs="0"/>
<xs:element name="Descrizione" type="xs:string" minOccurs="0"/>
<xs:element name="Tipo" type="xs:string"/>
<xs:element name="Parametri" type="tns:Parametri"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="doEventResponse">
<xs:sequence>
<xs:element name="header" type="tns:header"/>
<xs:element name="trackingbody" type="tns:trackingbody"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Here is the class for the servlet
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;
@EnableWs
@Configuration
public class WebServiceConfig {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/nis/*");
}
@Bean(name = "nisDoEvent")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema doEventSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("nisDoEvent");
wsdl11Definition.setLocationUri("/nis/ws");
wsdl11Definition.setTargetNamespace("http://nisws.it.fastweb");
wsdl11Definition.setSchema(doEventSchema);
// wsdl11Definition.setRequestSuffix("doEvent");
return wsdl11Definition;
}
@Bean (name = "doEventSchema")
public XsdSchema doEventSchema() {
return new SimpleXsdSchema(new ClassPathResource("doEventSchema.xsd"));
}
}
and here is my Endpoint
@Endpoint
public class CompletaMigrBNGEndpoint {
private static final String NAMESPACE_URI = "http://nisws.it.fastweb";
private static final String EXAMPLE_NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";
private CountryRepository countryRepository;
@Autowired
public CompletaMigrBNGEndpoint(CountryRepository countryRepository) {
this.countryRepository = countryRepository;
}
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "doEventRequest")
@ResponsePayload
public DoEventResponse doEvent(@RequestPayload DoEventRequest request){
DoEventResponse response = new DoEventResponse();
response.setHeader(request.getHeader());
response.setTrackingbody(request.getTrackingbody());
return response;
}
@PayloadRoot(namespace = EXAMPLE_NAMESPACE_URI, localPart = "getCountryRequest")
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
GetCountryResponse response = new GetCountryResponse();
response.setCountry(countryRepository.findCountry(request.getName()));
return response;
}
As you can see i also tried to follow the guide "https://spring.io/guides/gs/producing-web-service/"
and the example provided works fine.
Regarding my own service I tried to call it via soapui and I get the exception:
16:43:38.674 [http-nio-8080-exec-4] DEBUG o.s.w.s.server.SoapMessageDispatcher - Endpoint invocation resulted in exception - responding with Fault
java.lang.IllegalStateException: No adapter for endpoint [public org.hp.doEventSchema.DoEventResponse org.hp.resources.connection.soap.services.CompletaMigrBNGEndpoint.doEvent(org.hp.doEventSchema.DoEventRequest)]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?
at org.springframework.ws.server.MessageDispatcher.getEndpointAdapter(MessageDispatcher.java:302) [spring-ws-core-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:235) [spring-ws-core-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:176) [spring-ws-core-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
I believe that probably my error is in xsd or in endpoint mapping but i cannot fix it.
Thanks in advance
Regards
回答1:
I solved using JAXBElement to encapsulate my request/response object generated by jaxb plugin. This why i notice that in those classes there is no @XmlRootElement annotation.
Thanks anyway
Regards
回答2:
Just wrap the request and response with JAXBElement like below
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "doEventRequest")
@ResponsePayload
public JAXBElement< DoEventResponse > doEvent(@RequestPayload JAXBElement< DoEventRequest > request){}
we can get the object by calling like below
DoEventRequest d = request.getValue();
来源:https://stackoverflow.com/questions/30152864/spring-boot-ws-no-adapter-for-endpoint