Согласно официальной документации Apache CXF, мы создаем SOAP сервисов весной таким образом:
Класс конфигурации
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
@Configuration
public class WebServiceConfiguration {
private static final String BINDING_URI = "http://www.w3.org/2003/05/soap/bindings/HTTP/";
@Bean
public ServletRegistrationBean<CXFServlet> disServlet() {
return new ServletRegistrationBean<>(new CXFServlet(), "/soap-api/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
SpringBus bus = new SpringBus();
bus.setProperty("org.apache.cxf.stax.maxTextLength", 1024 * 1024 * 1024);
return bus;
}
@Bean
public Endpoint userServiceEndpoint(UserService userService) {
EndpointImpl endpoint = new EndpointImpl(springBus(), userService);
endpoint.setBindingUri(BINDING_URI);
endpoint.publish("/users");
return endpoint;
}
}
Сгенерировано из интерфейса WSDL SOAP:
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.3.2
* Generated source version: 2.2
*
*/
@WebService(name = "UserServiceSoap", targetNamespace = "http://User.no/webservices/")
@XmlSeeAlso({ObjectFactory.class})
public interface UserServiceSoap {
@WebMethod(operationName = "GetUser", action = "http://User.no/webservices/GetUser")
@WebResult(name = "GetUserResult", targetNamespace = "http://User.no/webservices/")
@RequestWrapper(localName = "UserServiceSoap", targetNamespace = "http://User.no/webservices/", className = "no.user.webservices.generated.UserServiceSoap")
@ResponseWrapper(localName = "UserServiceSoapResponse", targetNamespace = "http://User.no/webservices/", className = "no.user.webservices.generated.UserServiceSoapResponse")
public String getUser(@WebParam(name = "username", targetNamespace = "http://User.no/webservices/") String username);
}
Реализация услуги:
@Service
@WebService(
endpointInterface = "no.altinn.webservices.generated.UserServiceSoap",
serviceName = "UserServiceSoapService",
targetNamespace = "http://User.no/webservices/",
portName = "UserServiceSoapPort"
)
@BindingType("http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/")
public class UserService implements UserServiceSoap {
@Override
public String getUser(String requestUsername) {
//logic
}
}
Что я хочу?
Есть ли уже реализованный способ в конечную точку publi sh SOAP без создания bean-компонента в конфигурации Spring. Я хочу сделать это с аннотацией реализации сервиса, например (@SoapEndpoint):
@Service
@SoapEndpoint(bindingUri = "http://www.w3.org/2003/05/soap/bindings/HTTP/",
publish = "/users")
@WebService(
endpointInterface = "no.altinn.webservices.generated.UserServiceSoap",
serviceName = "UserServiceSoapService",
targetNamespace = "http://User.no/webservices/",
portName = "UserServiceSoapPort"
)
@BindingType("http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/")
public class UserService implements UserServiceSoap {
@Override
public String getUser(String requestUsername) {
//logic
}
}