Hi,
ich wollte gerade meinen ersten Webservice mit Spring-WS implementieren und auf dem Tomcat deployen. Das meiste hat auch wunderbar funktioniert. Tomcat schluckt den Webservice und in soapui erhalte ich eine Antwort, wenn ich den Service anspreche. Nur habe ich gerade festgestellt, dass mein Webservice meinen Request nicht parst (zumindest kommen die übergebenen Werte nicht in meiner Webservice-Methode an).
Die Requestklasse sieht so aus:
Das XML-Schema:
Die Webservice-Klasse:
Die web.xml:
Und die Spring-Konfiguration:
Wenn noch mehr Klassen oder ähnliches benötigt werden, bitte nachfragen. Ich bin für jede Hilfe dankbar.
Grüße,
Andreas
ich wollte gerade meinen ersten Webservice mit Spring-WS implementieren und auf dem Tomcat deployen. Das meiste hat auch wunderbar funktioniert. Tomcat schluckt den Webservice und in soapui erhalte ich eine Antwort, wenn ich den Service anspreche. Nur habe ich gerade festgestellt, dass mein Webservice meinen Request nicht parst (zumindest kommen die übergebenen Werte nicht in meiner Webservice-Methode an).
Die Requestklasse sieht so aus:
Java:
package de.andreasgrund.dsacomputer.webservices.culture.dta;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.log4j.Logger;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
})
@XmlRootElement(name = "GetCultureByNameRequest", namespace = "http://dsacomputer.de/culture")
public class GetCultureByNameRequest {
private static final Logger logger = Logger
.getLogger(GetCultureByNameRequest.class);
@XmlElement(name = "CultureName", required = true)
private String cultureName;
public String getCultureName() {
return cultureName;
}
public void setCultureName(String cultureName) {
logger.info("setCultureName mit " + cultureName + " aufgerufen");
this.cultureName = cultureName;
}
}
Java:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://dsacomputer.de/culture"
xmlns:tns="http://dsacomputer.de/Culture" elementFormDefault="qualified" xmlns:c="http://dsacomputer.de/culture">
<element name="GetCultureByNameRequest">
<complexType>
<sequence maxOccurs="1" minOccurs="1">
<element name="CultureName" type="string" />
</sequence>
</complexType>
</element>
<element name="GetCultureByNameResponse">
<complexType>
<sequence maxOccurs="unbounded" minOccurs="1">
<element name="cultures" type="c:culturesType"/>
</sequence>
</complexType>
</element>
<simpleType name="cultureNameType">
<restriction base="string">
<maxLength value="40" />
</restriction>
</simpleType>
<simpleType name="description">
<restriction base="string">
<maxLength value="2000" />
</restriction>
</simpleType>
<simpleType name="costs">
<restriction base="integer" />
</simpleType>
<complexType name="culturesType">
<sequence>
<element name="cultureName" type="c:cultureNameType" />
<element name="description" type="c:description" />
<element name="costs" type="c:costs" />
</sequence>
</complexType>
</schema>
Die Webservice-Klasse:
Java:
package de.andreasgrund.dsacomputer.webservices.culture.webservice.endpoint;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import de.andreasgrund.dsacomputer.webservices.culture.dta.GetCultureByNameRequest;
import de.andreasgrund.dsacomputer.webservices.culture.dta.GetCultureByNameResponse;
import de.andreasgrund.dsacomputer.webservices.culture.model.Culture;
@Endpoint
public class CultureServiceEndpoint {
private static final Logger logger = Logger
.getLogger(CultureServiceEndpoint.class);
private static final String NAMESPACE = "http://dsacomputer.de/culture";
private static final String LOCAL_PART_NAME = "GetCultureByNameRequest";
@PayloadRoot(localPart = LOCAL_PART_NAME, namespace = NAMESPACE)
public GetCultureByNameResponse getCultureByName(
GetCultureByNameRequest request) {
logger.info("start executing cultur by name request with name: "
+ request.getCultureName());
Culture culture = new Culture();
culture.setCultureName(request.getCultureName());
culture.setDescription("Dies ist eine Kultur aus dem Rollenspiel DSA");
culture.setCosts(100);
List<Culture> cultures = new ArrayList<Culture>();
cultures.add(culture);
GetCultureByNameResponse response = new GetCultureByNameResponse();
response.setCultures(cultures);
logger.info("End executing cultur by name request. Found culture: "
+ culture.toString());
return response;
}
}
Die web.xml:
Java:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SpringWsTutorial</display-name>
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>
org.springframework.ws.transport.http.MessageDispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/spring-ws-servlet.xml</param-value>
</init-param>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Und die Spring-Konfiguration:
Java:
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans [url]http://www.springframework.org/schema/beans/spring-beans-2.5.xsd[/url]
[url=http://www.springframework.org/schema/context]Index of /schema/context[/url] http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="de.andreasgrund.dsacomputer.webservices.culture" />
<bean id="culture"
class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schema" ref="schema" />
<property name="portTypeName" value="CultureResource" />
<property name="locationUri" value="/cultureService/" />
<property name="targetNamespace" value="http://dsacomputer.de/culture" />
</bean>
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
<property name="xsd" value="classpath:META-INF/schema/Culture.xsd" />
</bean>
<bean
class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" />
<bean
class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
<constructor-arg ref="marshaller" />
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>de.andreasgrund.dsacomputer.webservices.culture.dta.GetCultureByNameRequest</value>
<value>de.andreasgrund.dsacomputer.webservices.culture.dta.GetCultureByNameResponse</value>
</list>
</property>
</bean>
</beans>
Wenn noch mehr Klassen oder ähnliches benötigt werden, bitte nachfragen. Ich bin für jede Hilfe dankbar.
Grüße,
Andreas