如何在Spring引导应用程序上注册javax.jws.Webservice
我正在使用Spring Boot,我的Application.java如下所示:如何在Spring引导应用程序上注册javax.jws.Webservice,java,spring,jax-ws,apache-camel,spring-boot,Java,Spring,Jax Ws,Apache Camel,Spring Boot,我正在使用Spring Boot,我的Application.java如下所示: import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.sp
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.servlet.CamelHttpTransportServlet;
import org.apache.camel.spring.SpringCamelContext;
@ComponentScan
@EnableAutoConfiguration
public class Application {
private static final String CAMEL_URL_MAPPING = "/camel/*";
private static final String CAMEL_SERVLET_NAME = "CamelServlet";
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ServletRegistrationBean camelServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), CAMEL_URL_MAPPING);
registration.setName(CAMEL_SERVLET_NAME);
return registration;
}
@Bean
public SpringCamelContext camelContext(ApplicationContext applicationContext) throws Exception {
SpringCamelContext camelContext = new SpringCamelContext(applicationContext);
camelContext.addRoutes(routeBuilder());
return camelContext;
}
@Bean
public RouteBuilder routeBuilder() {
return new MyRouteBuilder();
}
}
RouteBuilder.java的定义如下:
import org.apache.camel.builder.RouteBuilder;
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// Access us using http://localhost:8080/camel/hello
from("servlet:///hello").transform().constant("Hello from Camel!");
// Trigger run right after startup. No Servlet request required.
from("timer://foo?fixedRate=true&period=10s").log("Camel timer triggered.");
}
}
一切正常-骆驼上下文已启动,我可以看到“Hello from Camel!”消息。现在我想让Camel绑定到WS,而不仅仅是简单的Servlet
我定义了以下Web服务:
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
@WebService(targetNamespace = "http://ws.mycompany.com/notification", name = "StatusNotificationService")
@XmlSeeAlso({ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class StatusNotificationServiceWS implements StatusNotificationServicePortType {
@Override
public void notify(@WebParam(partName = "parameter", name = "NotifyStatus", targetNamespace = "http://ws.mycompany.com/notification") NotifyStatus parameter) {
throw new RuntimeException("This method should not be called!");
}
}
如何使用ServletRegistrationBean注册该服务,并使用Apache Camel routes引用该服务?如果您只想发布该服务,可以使用来完成该工作。 但如果要将请求路由到驼峰路由,则需要使用设置CxfEndpoint来总结: 我通过向pom.xml添加以下依赖项来使用camel cxf:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel.version}</version>
</dependency>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<cxf:cxfEndpoint id="notificationsWS" address="localhost:8080/notificationsWS" serviceClass="org.company.StatusNotificationServiceWS">
</cxf:cxfEndpoint>
</beans>
from("cxf:bean:notificationsWS?dataFormat=PAYLOAD").wireTap("direct:myRouter")