作为一个了解JAX-WS和CXF的练习,我决定实现一个计算BMI的小服务。 它基于this tutorial。
我认为只使用我在xml端点定义中指定的地址,但实际上jboss也可以在其他地方使用它。
我可以在
获得相同的服务http://localhost:8080/BMI/BmiCalculatorService
和
http://localhost:8080/BMI/services/cxfBmi.
有人可以帮忙吗?
这是我的web.xml:
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
这是我的beans.xml:
<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="calcBMI"
implementor="com.company.bmi.services.BMICalculatorImpl"
address="/cxfBmi"/>
</beans>
界面定义:
package com.company.bmi.services;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface BMICalculator {
public double computeBMI(@WebParam(name="weight") double weight, @WebParam(name="height") double height) ;
}
服务的实施:
package com.company.bmi.services;
import javax.jws.WebService;
@WebService(endpointInterface="com.company.bmi.services.BMICalculator", serviceName="BmiCalculatorService")
public class BMICalculatorImpl implements BMICalculator {
@Override
public double computeBMI(double weight, double height) {
return weight / (height * height);
}
}
在Jboss的日志中,我看到我提到的第一个URL确实是一个设置为服务的已发布地址。然后它变为我在xml文件中指定的那个。事情是第一个地址仍然有效,我认为这是不正确的。
但是后来在日志中服务器也抱怨没有找到服务的观察者,所以我想知道这是不是会导致不良结果?
以下是日志示例:
10:29:39,326 INFO [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] (MSC service thread 1-5) Add Service
id=com.company.bmi.services.BMICalculatorImpl
address=http://localhost:8080/BMI/BmiCalculatorService
implementor=com.company.bmi.services.BMICalculatorImpl
invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker
serviceName={http://services.bmi.company.com/}BmiCalculatorService
portName={http://services.bmi.company.com/}BMICalculatorImplPort
wsdlLocation=null
mtomEnabled=false
10:29:39,441 INFO [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-5) Creating Service {http://services.bmi.company.com/}BmiCalculatorService from class com.company.bmi.services.BMICalculator
10:29:39,748 INFO [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-5) Setting the server's publish address to be http://localhost:8080/BMI/BmiCalculatorService
10:29:39,832 INFO [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-5) WSDL published to: file:/zimory/jboss/switchyard-as7-0.5/standalone/data/wsdl/BMICalculator-0.0.1-SNAPSHOT.war/BmiCalculatorService.wsdl
10:29:39,836 INFO [org.jboss.as.webservices] (MSC service thread 1-2) JBAS015539: Starting service jboss.ws.port-component-link
10:29:39,844 INFO [org.jboss.as.webservices] (MSC service thread 1-4) JBAS015539: Starting service jboss.ws.endpoint."BMICalculator-0.0.1-SNAPSHOT.war"."com.company.bmi.services.BMICalculatorImpl"
10:29:39,847 INFO [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-4) register: jboss.ws:context=BMI,endpoint=com.company.bmi.services.BMICalculatorImpl
10:29:39,849 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016008: Starting weld service for deployment BMICalculator-0.0.1-SNAPSHOT.war
10:29:40,077 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/BMI]] (MSC service thread 1-5) Initializing Spring root WebApplicationContext
10:29:40,078 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization started
10:29:40,091 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-5) Refreshing Root WebApplicationContext: startup date [Fri Mar 15 10:29:40 CET 2013]; root of context hierarchy
10:29:40,111 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from ServletContext resource [/WEB-INF/beans.xml]
10:29:40,138 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
10:29:40,152 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-soap.xml]
10:29:40,162 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]
10:29:40,415 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7cbdc6a3: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,calcBMI]; root of factory hierarchy
10:29:40,498 INFO [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-5) Creating Service {http://services.bmi.company.com/}BmiCalculatorService from class com.company.bmi.services.BMICalculator
10:29:40,724 INFO [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-5) Setting the server's publish address to be /cxfBmi
10:29:40,730 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization completed in 652 ms
10:29:40,763 INFO [org.jboss.web] (MSC service thread 1-5) JBAS018210: Registering web context: /BMI
10:29:40,874 INFO [org.jboss.as.server] (management-handler-thread - 2) JBAS018559: Deployed "BMICalculator-0.0.1-SNAPSHOT.war" [2013-03-15 10:29:40,895] Artifact BMICalculator:war: Artifact is deployed successfully
10:39:07,639 WARNING [org.apache.cxf.transport.servlet.ServletController] (http--127.0.0.1-8080-2) Can't find the the request for http://localhost:8080/BMI/services/cfxBmi/BmiCalculatorService's Observer
答案 0 :(得分:1)
地址http://localhost:8080/BMI/services/*
由显式CXFServlet
创建。
http://localhost:8080/BMI/BmiCalculatorService
由org.jboss.wsf.stack.cxf.metadata.MetadataBuilder
通过隐式注释扫描创建。{/ p>
请参阅How to disable scanning @WebService annotations in JBoss AS 7?进行治疗。