我试图编写一个相当简单的Spring-WS服务,它接受一个String并返回一个String,我已经定义了端点Class,据我所知,一切看起来都很好。但是当我使用SOAP-UI命中服务时,我收到以下错误消息:
没有端点适配器[public java.lang.String uk.co.company.product.identification.service.IdentificationServiceEndpoint.getIdentificationData(java.lang.String中)〕: 您的端点是使用@Endpoint注释的,还是实现了? 支持的接口,如MessageHandler或PayloadEndpoint?
我的智慧结束了,因为据我所知,一切都应该是......
SPRING CONFIG
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="uk.co.company.product.identification" />
<sws:annotation-driven />
<!-- Our test service bean -->
<bean id="IdentificationRequest"
class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"
lazy-init="true">
<property name="schemaCollection">
<bean
class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="inline" value="true" />
<property name="xsds">
<list>
<value>/schemas/identificationOperations.xsd</value>
</list>
</property>
</bean>
</property>
<property name="portTypeName" value="IdentificationService" />
<property name="serviceName" value="IdentificationServices" />
<property name="locationUri" value="/endpoints/" />
</bean>
</beans>
XSD
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.company.co.uk/product/identification/service"
targetNamespace="http://www.company.co.uk/product/identification/service"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="IdentificationRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="address" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="IdentificationResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="identificationData" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
ENDPOINT类
package uk.co.company.product.identification.service;
import org.springframework.beans.factory.annotation.Autowired;
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;
@Endpoint
public class IdentificationServiceEndpoint {
private static final String TARGET_NAMESPACE = "http://www.company.co.uk/product/identification/service";
@Autowired
private IdentificationService identificationService;
@PayloadRoot(localPart="IdentificationRequest", namespace=TARGET_NAMESPACE)
@ResponsePayload public String getIdentificationData(@RequestPayload String address){
return identificationService.getIdentificationData(address);
}
public void setIdentificationService(IdentificationService identificationService){
this.identificationService = identificationService;
}
}
生成的WSDL 这是我浏览到时生成的WSDL:
http://localhost:8080/IdentificationService/IdentificationRequest.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.company.co.uk/product/identification/service" xmlns:tns="http://www.company.co.uk/product/identification/service" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:sch="http://www.company.co.uk/product/identification/service" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.company.co.uk/product/identification/service" elementFormDefault="unqualified" attributeFormDefault="unqualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.company.co.uk/product/identification/service">
<xsd:element name="IdentificationRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="address" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="IdentificationResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="identificationData" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IdentificationRequest">
<wsdl:part name="IdentificationRequest" element="tns:IdentificationRequest"> </wsdl:part>
</wsdl:message>
<wsdl:message name="IdentificationResponse">
<wsdl:part name="IdentificationResponse" element="tns:IdentificationResponse"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="IdentificationService">
<wsdl:operation name="Identification">
<wsdl:input name="IdentificationRequest" message="tns:IdentificationRequest"> </wsdl:input>
<wsdl:output name="IdentificationResponse" message="tns:IdentificationResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="IdentificationServiceSoap11" type="tns:IdentificationService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="Identification">
<soap:operation soapAction=""/>
<wsdl:input name="IdentificationRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="IdentificationResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="IdentificationServices">
<wsdl:port name="IdentificationServiceSoap11" binding="tns:IdentificationServiceSoap11">
<soap:address location="http://localhost:8080/IdentificationService/endpoints/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
SOAP消息: 这些是我从SOAP-UI发送的SOAP消息以及我收到的消息。 端点是:
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://www.company.co.uk/product/identification/service">
<soapenv:Header/>
<soapenv:Body>
<ser:IdentificationRequest>
<address>test</address>
</ser:IdentificationRequest>
</soapenv:Body>
</soapenv:Envelope>
响应:
<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 java.lang.String uk.co.company.product.identification.service.IdentificationServiceEndpoint.getIdentificationData(java.lang.String)]: 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>
为了完整起见,这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples.service.service</groupId>
<artifactId>IdentificationService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- Generic properties -->
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Web -->
<jsp.version>2.2</jsp.version>
<jstl.version>1.2</jstl.version>
<servlet.version>2.5</servlet.version>
<!-- Spring -->
<spring-framework.version>3.2.3.RELEASE</spring-framework.version>
<spring.ws.version>2.0.0.RELEASE</spring.ws.version>
<!-- Hibernate / JPA -->
<hibernate.version>4.2.1.Final</hibernate.version>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
<!-- Context Path -->
<context.path>IdentificationService</context.path>
</properties>
<dependencies>
<!-- Spring MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- Spring WS -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<!-- Other Web dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Test Artifacts -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-framework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<clearOutputDir>false</clearOutputDir>
<outputDirectory>src/main/java</outputDirectory>
<schemaDirectory>src/main/webapp/schemas</schemaDirectory>
<includeSchema>**/*.xsd</includeSchema>
<enableIntrospection>false</enableIntrospection>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${context.path}</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:4)
您的方法签名已关闭,而不是String
,而是期望IdentificationRequest
和IdentificationResponse
作为返回类型。
@PayloadRoot(localPart="IdentificationRequest", namespace=TARGET_NAMESPACE)
@ResponsePayload
public IdentificationResponse getIdentificationData(@RequestPayload IdentificationRequest address){
String identification = identificationService.getIdentificationData(address.getAddress());
ObjectFactory factory = new ObjectFactory();
IdentificationResponse response = factory.createIdentificationResponse();
response.setIdentificationData(identification);
return response;
}
您的方法应该如上所示。
答案 1 :(得分:1)
有几个原因导致您看到此错误。 1.如果您正在查看Spring Web服务示例,那么您的jdom版本可能不正确。这就是pom应该是什么样的
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>2.0.2</version>
</dependency>
如果你的方法返回类型不正确,如上所述
如果您使用的是复杂类型,请确保您的bean已使用@XmlRootElement注释