5

I'trying to create simple WS project in Spring and Spring WS without any XSD. Deploy on jetty. Is possible to populate WS endpoint and generate WSDL only from java classes (no static XSD or WSDL - I went throught many tutorials but all requiered).

For any help, hint or link highly appreciated.

I have something like this:

1) Request

@XmlRootElement
public class MessageWSRequest {

@XmlElement
private String message;

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}
}

2) Endpoint

@Endpoint
public class MessageWS {
@PayloadRoot(namespace = "http://message.com/ws/message" ,localPart="MessageWSRequest")
public String handleMathServiceRequest(@RequestPayload MessageWSRequest messageWSRequest) {
    return "ok";
}
}

3) springContext.xml

<sws:annotation-driven/>
<context:component-scan base-package="com.ws.message"/>

4) web.xml

<servlet>
    <servlet-name>webservices</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>transformWsdlLocations</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>webservices</servlet-name>
    <url-pattern>*.wsdl</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>webservices</servlet-name>
    <url-pattern>/endpoints/*</url-pattern>
</servlet-mapping>

Now I would expect URL like this localhost:8080/messageTest/endpoints/MessageWS.wsdl with generated WSDL.

Did I miss some configuration or so?

Thanks all

user3070136
  • 121
  • 1
  • 6

2 Answers2

6

Ok, next day a clear mind revelead me this fact: Spring WS offers "only" contract-first, starting from an XSD Schema

I'll use CXF instead: Apache CXF offers both contract-last (starting with Java) and Contract-first (starting with the WSDL) approaches.

user3070136
  • 121
  • 1
  • 6
  • Which won't work either. They all require an XSD. How you get that XSD (generate it from your java code or create it by hand) doesn't matter. You can use your classes to generate an xsd, which in turn can be used by Spring WS to create the wsdl. This has nothing to do with contract-first or contract-last but the fact that an XSD is the contract for a web service. – M. Deinum Jun 21 '15 at 09:29
  • CXF (and more generally any JAX-WS implementation) automatically generates the XSD for code first services. – Andreas Veithen Jun 21 '15 at 16:34
0

As you have noted, Spring WS is designed for contract first services. However I think that you can still achieve what you want to do if you generate the XSD during the build process from your annotated classes. Here is one way to do that:

Generating XSD schemas from JAXB types in Maven?

Community
  • 1
  • 1
Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • Thanks for this. It's slightly better but still needs some additional rutine. But it's because contract-first approach. – user3070136 Jun 27 '15 at 15:42