سؤال

As an exercise to get to know something about JAX-WS and CXF I decided to implement a small service that calculates BMI. It is based on this tutorial.

I would assume that only the address I specify in the xml endpoint definition is used, but actually jboss also makes it available somewhere else.

I get the same service to be available both at

http://localhost:8080/BMI/BmiCalculatorService 

and at

http://localhost:8080/BMI/services/cxfBmi.

Can anyone help?

This is my 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>

And this is my 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>

The interface definition:

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) ;

}

And the implementation of the service:

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);
    }

}

In Jboss's log I see that indeed the first URL I mentioned is the one set as the published address for the service. Then it gets changed into the one I specified in the xml file. The thing is the first address still works, this is not correct in my opinion.

But later on in the log the server also complains about not finding the service's observer, so I wonder if this is what causes the undesirable result?

Here is the log sample:

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
هل كانت مفيدة؟

المحلول

The address http://localhost:8080/BMI/services/* is created by explicit CXFServlet.

While http://localhost:8080/BMI/BmiCalculatorService is created by org.jboss.wsf.stack.cxf.metadata.MetadataBuilder via implicit annotations scan.

See How to disable scanning @WebService annotations in JBoss AS 7? for cure.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top