SpringWS(Kotlin) - 没有@Endpoint和@RequestPayload的端点适配器

时间:2018-03-19 04:48:39

标签: spring soap kotlin spring-ws

我试图在kotlin中实现这个guide

但是,当我提出请求时,我得到以下回复:

<SOAP-ENV:Envelope 
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Server</faultcode>
      <faultstring xml:lang="en">No adapter for endpoint [public final io.spring.guides.gs_producing_web_service.GetCountryResponse jp.tamagotchi.soap.endpoints.CountryEndpoint.getCountry(io.spring.guides.gs_producing_web_service.GetCountryRequest)]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我的端点类如下:

import io.spring.guides.gs_producing_web_service.Country
import io.spring.guides.gs_producing_web_service.Currency
import io.spring.guides.gs_producing_web_service.GetCountryRequest
import io.spring.guides.gs_producing_web_service.GetCountryResponse

import org.springframework.ws.server.endpoint.annotation.Endpoint
import org.springframework.ws.server.endpoint.annotation.PayloadRoot
import org.springframework.ws.server.endpoint.annotation.RequestPayload
import org.springframework.ws.server.endpoint.annotation.ResponsePayload

const val NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service"

/**
 * @author J. Pichardo
 */
@Endpoint
class CountryEndpoint {

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
    @ResponsePayload
    fun getCountry(@RequestPayload request: GetCountryRequest)  =
            GetCountryResponse().apply {
                country = Country().apply {
                    capital = "Mexico"
                    currency = Currency.EUR
                    name = request.name
                    population = Math.random().toInt()
                }
            }

}

服务配置:

import org.springframework.boot.web.servlet.ServletRegistrationBean
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
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.server.EndpointAdapter
import org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter
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
open class WebServiceConfiguration : WsConfigurerAdapter() {

    @Bean
    open fun messageDispatcherServlet(applicationContext: ApplicationContext): ServletRegistrationBean<*> =
            MessageDispatcherServlet().run {
                setApplicationContext(applicationContext)
                isTransformWsdlLocations = true
                ServletRegistrationBean(this, "/ws/*")
            }

    @Bean(name = ["countries"])
    open fun defaultWsdl11Definition(countriesSchema: XsdSchema): DefaultWsdl11Definition =
            DefaultWsdl11Definition().apply {
                setPortTypeName("CountriesPort")
                setLocationUri("/ws")
                setTargetNamespace("http://spring.io/guides/gs-producing-web-service")
                setSchema(countriesSchema)
            }

    @Bean
    open fun countriesSchema(): XsdSchema = SimpleXsdSchema(ClassPathResource("countries.xsd"))

    @Bean
    open fun messageEndpointAdapter(): EndpointAdapter = MessageEndpointAdapter()
}

对此有何想法?我已经阅读了有关此问题的几个问题,其中大多数都关注@Endpoint@RequestPayload@ResponsePayload注释,但我已经考虑过这一点。

提前致谢

0 个答案:

没有答案