【JAVA】通过CXF开发webservice

在tomcat作为容器发布webservice服务前,我们先来看一个简单的不通过容器即可发布服务的例子

package com.tree.webservice;

import javax.jws.WebService;

@WebService
public interface HelloWorld {

	public String sayHello(String content);
	
}

package com.tree.webservice.impl;

import javax.jws.WebService;

import com.tree.webservice.HelloWorld;

@WebService(endpointInterface="com.tree.webservice.HelloWorld")
public class HelloWorldImpl implements HelloWorld {

	@Override
	public String sayHello(String content) {
		// TODO Auto-generated method stub
		return "Hello "+content;
	}

}

package com.tree.webservice.publish;

import javax.xml.ws.Endpoint;

import com.tree.webservice.HelloWorld;
import com.tree.webservice.impl.HelloWorldImpl;

public class PublishService {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Service is begin ...");
		HelloWorld hw = new HelloWorldImpl();
		Endpoint.publish("http://localhost:8080/hw", hw);
		System.out.println("Server is OK ...");
	}

}

【JAVA】通过CXF开发webservice_第1张图片

下面再来看如何调用该发布的服务

package com.tree.webservice.publish;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.tree.webservice.HelloWorld;

public class CallWs {

	public static void main(String args[]) {
		System.out.println("Begin to call the service ...");
		JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();  
        factoryBean.setServiceClass(HelloWorld.class);  
        factoryBean.setAddress("http://localhost:8080/hw");  
          
        HelloWorld hwService = (HelloWorld)factoryBean.create();  
        String result = hwService.sayHello(" chiweitree");
        System.out.println(result); 
	}
	
}

控制台输出

Begin to call the service ...
2014-09-16 09:20:00,358 - org.apache.cxf.common.logging.LogUtils -0    [main] DEBUG  - Using org.apache.cxf.common.logging.Log4jLogger for logging.
2014-09-16 09:20:00,842 - org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean -484  [main] INFO   - Creating Service {http://webservice.tree.com/}HelloWorldService from class com.tree.webservice.HelloWorld
2014-09-16 09:20:01,418 - org.apache.cxf.jaxb.JAXBDataBinding -1060 [main] DEBUG  - Created JAXBContext "jar:file:/home/hadoop/mydisk/maven_repo/com/sun/xml/bind/jaxb-impl/2.2.7/jaxb-impl-2.2.7.jar!/com/sun/xml/bind/v2/runtime/JAXBContextImpl.class Build-Id: 2.2.7
Classes known to this context:
  [B
  boolean
  byte
  char
  com.sun.xml.bind.api.CompositeStructure
  com.tree.webservice.jaxws_asm.SayHello
  com.tree.webservice.jaxws_asm.SayHelloResponse
  double
  float
  int
  java.awt.Image
  java.io.File
  java.lang.Boolean
  java.lang.Byte
  java.lang.Character
  java.lang.Class
  java.lang.Double
  java.lang.Float
  java.lang.Integer
  java.lang.Long
  java.lang.Object
  java.lang.Short
  java.lang.String
  java.lang.Void
  java.math.BigDecimal
  java.math.BigInteger
  java.net.URI
  java.net.URL
  java.util.Calendar
  java.util.Date
  java.util.GregorianCalendar
  java.util.UUID
  javax.activation.DataHandler
  javax.xml.bind.JAXBElement
  javax.xml.datatype.Duration
  javax.xml.datatype.XMLGregorianCalendar
  javax.xml.namespace.QName
  javax.xml.transform.Source
  long
  short
  void
" with classes [class com.tree.webservice.jaxws_asm.SayHello, class com.tree.webservice.jaxws_asm.SayHelloResponse].
2014-09-16 09:20:01,790 - org.apache.cxf.resource.DefaultResourceManager -1432 [main] DEBUG  - resolving resource  type 
2014-09-16 09:20:01,790 - org.apache.cxf.resource.DefaultResourceManager -1432 [main] DEBUG  - resolving resource  type 
2014-09-16 09:20:02,115 - org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder -1757 [main] DEBUG  - building handler chain
2014-09-16 09:20:02,115 - org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder -1757 [main] DEBUG  - Checking for HandlerChain annotation on com.tree.webservice.HelloWorld
2014-09-16 09:20:02,115 - org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder -1757 [main] DEBUG  - no HandlerChain annotation on interface com.tree.webservice.HelloWorld
2014-09-16 09:20:02,131 - org.apache.cxf.endpoint.ClientImpl -1773 [main] DEBUG  - Invoke, operation info: [BindingOperationInfo: {http://webservice.tree.com/}sayHello], params: [ chiweitree]
2014-09-16 09:20:02,133 - org.apache.cxf.endpoint.ClientImpl -1775 [main] DEBUG  - set requestContext to message be{java.lang.reflect.Method=public abstract java.lang.String com.tree.webservice.HelloWorld.sayHello(java.lang.String), org.apache.cxf.jaxws.context.WrappedMessageContext.SCOPES={org.apache.cxf.message.Message.ENDPOINT_ADDRESS=APPLICATION}, org.apache.cxf.message.Message.ENDPOINT_ADDRESS=http://localhost:8080/hw}
2014-09-16 09:20:02,137 - org.apache.cxf.endpoint.ClientImpl -1779 [main] DEBUG  - Interceptors contributed by bus: [org.apache.cxf.ws.policy.PolicyOutInterceptor@6c313657]
2014-09-16 09:20:02,141 - org.apache.cxf.endpoint.ClientImpl -1783 [main] DEBUG  - Interceptors contributed by client: []
2014-09-16 09:20:02,141 - org.apache.cxf.endpoint.ClientImpl -1783 [main] DEBUG  - Interceptors contributed by endpoint: [org.apache.cxf.interceptor.MessageSenderInterceptor@12e6c13f, org.apache.cxf.jaxws.interceptors.SwAOutInterceptor@6b9918ca, org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor@102aacf6, org.apache.cxf.jaxws.interceptors.HolderOutInterceptor@61c152c4]
2014-09-16 09:20:02,141 - org.apache.cxf.endpoint.ClientImpl -1783 [main] DEBUG  - Interceptors contributed by binding: [org.apache.cxf.interceptor.AttachmentOutInterceptor@5b20f3ff, org.apache.cxf.interceptor.StaxOutInterceptor@50731916, org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor@34741c9d, org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor@3302a252, org.apache.cxf.wsdl.interceptors.BareOutInterceptor@71eecfa7, org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor@75831760, org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor@7173dbe5]
2014-09-16 09:20:02,141 - org.apache.cxf.endpoint.ClientImpl -1783 [main] DEBUG  - Interceptors contributed by databinding: []
2014-09-16 09:20:02,152 - org.apache.cxf.phase.PhaseInterceptorChain -1794 [main] DEBUG  - Adding interceptor org.apache.cxf.ws.policy.PolicyOutInterceptor@6c313657 to phase setup
2014-09-16 09:20:02,159 - org.apache.cxf.phase.PhaseInterceptorChain -1801 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.MessageSenderInterceptor@12e6c13f to phase prepare-send
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxws.interceptors.SwAOutInterceptor@6b9918ca to phase pre-logical
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor@102aacf6 to phase pre-logical
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxws.interceptors.HolderOutInterceptor@61c152c4 to phase pre-logical
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.AttachmentOutInterceptor@5b20f3ff to phase pre-stream
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.StaxOutInterceptor@50731916 to phase pre-stream
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor@34741c9d to phase pre-logical
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor@3302a252 to phase marshal
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.wsdl.interceptors.BareOutInterceptor@71eecfa7 to phase marshal
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor@75831760 to phase post-logical
2014-09-16 09:20:02,160 - org.apache.cxf.phase.PhaseInterceptorChain -1802 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor@7173dbe5 to phase write
2014-09-16 09:20:02,317 - org.apache.cxf.transport.http.HTTPConduit -1959 [main] DEBUG  - Conduit '{http://webservice.tree.com/}HelloWorldPort.http-conduit' has been (re)configured for plain http.
2014-09-16 09:20:02,323 - org.apache.cxf.transport.http.HTTPConduit -1965 [main] DEBUG  - No Trust Decider configured for Conduit '{http://webservice.tree.com/}HelloWorldPort.http-conduit'
2014-09-16 09:20:02,323 - org.apache.cxf.transport.http.HTTPConduit -1965 [main] DEBUG  - No Auth Supplier configured for Conduit '{http://webservice.tree.com/}HelloWorldPort.http-conduit'
2014-09-16 09:20:02,323 - org.apache.cxf.transport.http.HTTPConduit -1965 [main] DEBUG  - Conduit '{http://webservice.tree.com/}HelloWorldPort.http-conduit' has been configured for plain http.
2014-09-16 09:20:02,323 - org.apache.cxf.transport.http.HTTPConduit -1965 [main] DEBUG  - registering incoming observer: org.apache.cxf.endpoint.ClientImpl@76e68f59
2014-09-16 09:20:02,324 - org.apache.cxf.phase.PhaseInterceptorChain -1966 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@6c5094ec was created. Current flow:
  setup [PolicyOutInterceptor]
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [WrappedOutInterceptor, BareOutInterceptor]

2014-09-16 09:20:02,324 - org.apache.cxf.phase.PhaseInterceptorChain -1966 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.ws.policy.PolicyOutInterceptor@6c313657
2014-09-16 09:20:02,325 - org.apache.cxf.phase.PhaseInterceptorChain -1967 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.HolderOutInterceptor@61c152c4
2014-09-16 09:20:02,327 - org.apache.cxf.jaxws.interceptors.HolderOutInterceptor -1969 [main] DEBUG  - op: [OperationInfo: {http://webservice.tree.com/}sayHello]
2014-09-16 09:20:02,328 - org.apache.cxf.jaxws.interceptors.HolderOutInterceptor -1970 [main] DEBUG  - op.hasOutput(): true
2014-09-16 09:20:02,328 - org.apache.cxf.jaxws.interceptors.HolderOutInterceptor -1970 [main] DEBUG  - op.getOutput().size(): 1
2014-09-16 09:20:02,328 - org.apache.cxf.phase.PhaseInterceptorChain -1970 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.SwAOutInterceptor@6b9918ca
2014-09-16 09:20:02,329 - org.apache.cxf.phase.PhaseInterceptorChain -1971 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor@102aacf6
2014-09-16 09:20:02,346 - org.apache.cxf.phase.PhaseInterceptorChain -1988 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapHeaderOutFilterInterceptor@34741c9d
2014-09-16 09:20:02,351 - org.apache.cxf.phase.PhaseInterceptorChain -1993 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor@75831760
2014-09-16 09:20:02,351 - org.apache.cxf.phase.PhaseInterceptorChain -1993 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor@12e6c13f
2014-09-16 09:20:02,395 - org.apache.cxf.phase.PhaseInterceptorChain -2037 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@c63679a to phase prepare-send-ending
2014-09-16 09:20:02,411 - org.apache.cxf.phase.PhaseInterceptorChain -2053 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@6c5094ec was modified. Current flow:
  setup [PolicyOutInterceptor]
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [WrappedOutInterceptor, BareOutInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]

2014-09-16 09:20:02,411 - org.apache.cxf.phase.PhaseInterceptorChain -2053 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.AttachmentOutInterceptor@5b20f3ff
2014-09-16 09:20:02,432 - org.apache.cxf.phase.PhaseInterceptorChain -2074 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.StaxOutInterceptor@50731916
2014-09-16 09:20:02,548 - org.apache.cxf.phase.PhaseInterceptorChain -2190 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.StaxOutEndingInterceptor@464232fb to phase pre-stream-ending
2014-09-16 09:20:02,549 - org.apache.cxf.phase.PhaseInterceptorChain -2191 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@6c5094ec was modified. Current flow:
  setup [PolicyOutInterceptor]
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [WrappedOutInterceptor, BareOutInterceptor]
  pre-stream-ending [StaxOutEndingInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]

2014-09-16 09:20:02,549 - org.apache.cxf.phase.PhaseInterceptorChain -2191 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor@7173dbe5
2014-09-16 09:20:02,552 - org.apache.cxf.phase.PhaseInterceptorChain -2194 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor@27763e5f to phase write-ending
2014-09-16 09:20:02,559 - org.apache.cxf.phase.PhaseInterceptorChain -2201 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@6c5094ec was modified. Current flow:
  setup [PolicyOutInterceptor]
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor]
  pre-stream [AttachmentOutInterceptor, StaxOutInterceptor]
  write [SoapOutInterceptor]
  marshal [WrappedOutInterceptor, BareOutInterceptor]
  write-ending [SoapOutEndingInterceptor]
  pre-stream-ending [StaxOutEndingInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]

2014-09-16 09:20:02,562 - org.apache.cxf.phase.PhaseInterceptorChain -2204 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.wsdl.interceptors.WrappedOutInterceptor@3302a252
2014-09-16 09:20:02,562 - org.apache.cxf.phase.PhaseInterceptorChain -2204 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.wsdl.interceptors.BareOutInterceptor@71eecfa7
2014-09-16 09:20:02,584 - org.apache.cxf.phase.PhaseInterceptorChain -2226 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor@27763e5f
2014-09-16 09:20:02,585 - org.apache.cxf.phase.PhaseInterceptorChain -2227 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.StaxOutEndingInterceptor@464232fb
2014-09-16 09:20:02,589 - org.apache.cxf.phase.PhaseInterceptorChain -2231 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@c63679a
2014-09-16 09:20:02,590 - org.apache.cxf.transport.http.Headers -2232 [main] DEBUG  - Accept: */*
2014-09-16 09:20:02,590 - org.apache.cxf.transport.http.Headers -2232 [main] DEBUG  - SOAPAction: ""
2014-09-16 09:20:02,590 - org.apache.cxf.transport.http.HTTPConduit -2232 [main] DEBUG  - No Trust Decider for Conduit '{http://webservice.tree.com/}HelloWorldPort.http-conduit'. An afirmative Trust Decision is assumed.
2014-09-16 09:20:02,650 - org.apache.cxf.transport.http.HTTPConduit -2292 [main] DEBUG  - Sending POST Message with Headers to http://localhost:8080/hw Conduit :{http://webservice.tree.com/}HelloWorldPort.http-conduit

2014-09-16 09:20:02,768 - org.apache.cxf.endpoint.ClientImpl -2410 [main] DEBUG  - Interceptors contributed by bus: [org.apache.cxf.ws.policy.PolicyInInterceptor@507a2840]
2014-09-16 09:20:02,774 - org.apache.cxf.endpoint.ClientImpl -2416 [main] DEBUG  - Interceptors contributed by client: []
2014-09-16 09:20:02,776 - org.apache.cxf.endpoint.ClientImpl -2418 [main] DEBUG  - Interceptors contributed by endpoint: [org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor@3e8ab07, org.apache.cxf.jaxws.interceptors.HolderInInterceptor@20345a92, org.apache.cxf.jaxws.interceptors.SwAInInterceptor@4d2637c2, org.apache.cxf.frontend.WSDLGetInterceptor@816c920]
2014-09-16 09:20:02,777 - org.apache.cxf.endpoint.ClientImpl -2419 [main] DEBUG  - Interceptors contributed by binding: [org.apache.cxf.interceptor.AttachmentInInterceptor@fee5806, org.apache.cxf.interceptor.StaxInInterceptor@68d4fa15, org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor@766eae77, org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor@5c80435f, org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor@68c7416a, org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor@7197cbe3, org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor@24cade58, org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor@2cb7647, org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor@7bc230bf]
2014-09-16 09:20:02,777 - org.apache.cxf.endpoint.ClientImpl -2419 [main] DEBUG  - Interceptors contributed by databinging: [org.apache.cxf.jaxb.attachment.JAXBAttachmentSchemaValidationHack@a0e8b13]
2014-09-16 09:20:02,777 - org.apache.cxf.phase.PhaseInterceptorChain -2419 [main] DEBUG  - Adding interceptor org.apache.cxf.ws.policy.PolicyInInterceptor@507a2840 to phase receive
2014-09-16 09:20:02,778 - org.apache.cxf.phase.PhaseInterceptorChain -2420 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor@3e8ab07 to phase post-logical
2014-09-16 09:20:02,778 - org.apache.cxf.phase.PhaseInterceptorChain -2420 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxws.interceptors.HolderInInterceptor@20345a92 to phase pre-invoke
2014-09-16 09:20:02,778 - org.apache.cxf.phase.PhaseInterceptorChain -2420 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxws.interceptors.SwAInInterceptor@4d2637c2 to phase pre-invoke
2014-09-16 09:20:02,779 - org.apache.cxf.phase.PhaseInterceptorChain -2421 [main] DEBUG  - Adding interceptor org.apache.cxf.frontend.WSDLGetInterceptor@816c920 to phase read
2014-09-16 09:20:02,779 - org.apache.cxf.phase.PhaseInterceptorChain -2421 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.AttachmentInInterceptor@fee5806 to phase receive
2014-09-16 09:20:02,779 - org.apache.cxf.phase.PhaseInterceptorChain -2421 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.StaxInInterceptor@68d4fa15 to phase post-stream
2014-09-16 09:20:02,779 - org.apache.cxf.phase.PhaseInterceptorChain -2421 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor@766eae77 to phase read
2014-09-16 09:20:02,779 - org.apache.cxf.phase.PhaseInterceptorChain -2421 [main] DEBUG  - Adding interceptor org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor@5c80435f to phase unmarshal
2014-09-16 09:20:02,780 - org.apache.cxf.phase.PhaseInterceptorChain -2422 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor@68c7416a to phase unmarshal
2014-09-16 09:20:02,782 - org.apache.cxf.phase.PhaseInterceptorChain -2424 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor@7197cbe3 to phase read
2014-09-16 09:20:02,782 - org.apache.cxf.phase.PhaseInterceptorChain -2424 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor@24cade58 to phase read
2014-09-16 09:20:02,782 - org.apache.cxf.phase.PhaseInterceptorChain -2424 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor@2cb7647 to phase post-protocol
2014-09-16 09:20:02,782 - org.apache.cxf.phase.PhaseInterceptorChain -2424 [main] DEBUG  - Adding interceptor org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor@7bc230bf to phase pre-protocol
2014-09-16 09:20:02,783 - org.apache.cxf.phase.PhaseInterceptorChain -2425 [main] DEBUG  - Adding interceptor org.apache.cxf.jaxb.attachment.JAXBAttachmentSchemaValidationHack@a0e8b13 to phase post-protocol
2014-09-16 09:20:02,783 - org.apache.cxf.phase.PhaseInterceptorChain -2425 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@40cc918d was created. Current flow:
  receive [PolicyInInterceptor, AttachmentInInterceptor]
  post-stream [StaxInInterceptor]
  read [WSDLGetInterceptor, ReadHeadersInterceptor, SoapActionInInterceptor, StartBodyInterceptor]
  pre-protocol [MustUnderstandInterceptor]
  post-protocol [CheckFaultInterceptor, JAXBAttachmentSchemaValidationHack]
  unmarshal [DocLiteralInInterceptor, SoapHeaderInterceptor]
  post-logical [WrapperClassInInterceptor]
  pre-invoke [SwAInInterceptor, HolderInInterceptor]

2014-09-16 09:20:02,783 - org.apache.cxf.phase.PhaseInterceptorChain -2425 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.ws.policy.PolicyInInterceptor@507a2840
2014-09-16 09:20:02,807 - org.apache.cxf.phase.PhaseInterceptorChain -2449 [main] DEBUG  - Adding interceptor org.apache.cxf.ws.policy.PolicyVerificationInInterceptor@5d62b0c to phase pre-invoke
2014-09-16 09:20:02,808 - org.apache.cxf.phase.PhaseInterceptorChain -2450 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@40cc918d was modified. Current flow:
  receive [PolicyInInterceptor, AttachmentInInterceptor]
  post-stream [StaxInInterceptor]
  read [WSDLGetInterceptor, ReadHeadersInterceptor, SoapActionInInterceptor, StartBodyInterceptor]
  pre-protocol [MustUnderstandInterceptor]
  post-protocol [CheckFaultInterceptor, JAXBAttachmentSchemaValidationHack]
  unmarshal [DocLiteralInInterceptor, SoapHeaderInterceptor]
  post-logical [WrapperClassInInterceptor]
  pre-invoke [SwAInInterceptor, HolderInInterceptor, PolicyVerificationInInterceptor]

2014-09-16 09:20:02,808 - org.apache.cxf.phase.PhaseInterceptorChain -2450 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.AttachmentInInterceptor@fee5806
2014-09-16 09:20:02,808 - org.apache.cxf.phase.PhaseInterceptorChain -2450 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.StaxInInterceptor@68d4fa15
2014-09-16 09:20:02,867 - org.apache.cxf.phase.PhaseInterceptorChain -2509 [main] DEBUG  - Adding interceptor org.apache.cxf.interceptor.StaxInEndingInterceptor@67c6cf7f to phase pre-invoke
2014-09-16 09:20:02,877 - org.apache.cxf.phase.PhaseInterceptorChain -2519 [main] DEBUG  - Chain org.apache.cxf.phase.PhaseInterceptorChain@40cc918d was modified. Current flow:
  receive [PolicyInInterceptor, AttachmentInInterceptor]
  post-stream [StaxInInterceptor]
  read [WSDLGetInterceptor, ReadHeadersInterceptor, SoapActionInInterceptor, StartBodyInterceptor]
  pre-protocol [MustUnderstandInterceptor]
  post-protocol [CheckFaultInterceptor, JAXBAttachmentSchemaValidationHack]
  unmarshal [DocLiteralInInterceptor, SoapHeaderInterceptor]
  post-logical [WrapperClassInInterceptor]
  pre-invoke [StaxInEndingInterceptor, SwAInInterceptor, HolderInInterceptor, PolicyVerificationInInterceptor]

2014-09-16 09:20:02,878 - org.apache.cxf.phase.PhaseInterceptorChain -2520 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.frontend.WSDLGetInterceptor@816c920
2014-09-16 09:20:02,879 - org.apache.cxf.phase.PhaseInterceptorChain -2521 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor@7197cbe3
2014-09-16 09:20:02,888 - org.apache.cxf.phase.PhaseInterceptorChain -2530 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor@766eae77
2014-09-16 09:20:02,892 - org.apache.cxf.phase.PhaseInterceptorChain -2534 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor@24cade58
2014-09-16 09:20:02,892 - org.apache.cxf.phase.PhaseInterceptorChain -2534 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor@7bc230bf
2014-09-16 09:20:02,893 - org.apache.cxf.phase.PhaseInterceptorChain -2535 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor@2cb7647
2014-09-16 09:20:02,893 - org.apache.cxf.phase.PhaseInterceptorChain -2535 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxb.attachment.JAXBAttachmentSchemaValidationHack@a0e8b13
2014-09-16 09:20:02,894 - org.apache.cxf.phase.PhaseInterceptorChain -2536 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor@5c80435f
2014-09-16 09:20:02,943 - org.apache.cxf.phase.PhaseInterceptorChain -2585 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor@68c7416a
2014-09-16 09:20:02,945 - org.apache.cxf.phase.PhaseInterceptorChain -2587 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor@3e8ab07
2014-09-16 09:20:02,960 - org.apache.cxf.phase.PhaseInterceptorChain -2602 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.interceptor.StaxInEndingInterceptor@67c6cf7f
2014-09-16 09:20:02,960 - org.apache.cxf.phase.PhaseInterceptorChain -2602 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.SwAInInterceptor@4d2637c2
2014-09-16 09:20:02,960 - org.apache.cxf.phase.PhaseInterceptorChain -2602 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.jaxws.interceptors.HolderInInterceptor@20345a92
2014-09-16 09:20:02,960 - org.apache.cxf.phase.PhaseInterceptorChain -2602 [main] DEBUG  - Invoking handleMessage on interceptor org.apache.cxf.ws.policy.PolicyVerificationInInterceptor@5d62b0c
2014-09-16 09:20:02,960 - org.apache.cxf.ws.policy.PolicyVerificationInInterceptor -2602 [main] DEBUG  - Verified policies for inbound message.
Hello  chiweitree


但是其实在实际项目中,并不希望webservice和应用是分开的,希望它们在同一个容器中,比如tomcat,这样我们就通过WEB来部署webservice服务了

首先来配置web.xml,定义CXFServlet等等



	Archetype Created Web Application
	    
        CXFService    
        org.apache.cxf.transport.servlet.CXFServlet    
        
    
        
        CXFService    
        /ws/*    
      

	
		contextConfigLocation
		classpath*:spring/spring-*.xml
	
	
		org.springframework.web.context.ContextLoaderListener
	
	
在来定义spring-ws.xml

  
        
      
      
    
    
    
	
		
			
		
	    
          
  
启动tomcat服务器

这时候注意访问地址

ip:port/项目名/url-pattern in web.xml/address?wsdl

http://localhost:8080/demo.web/ws/hw?wsdl

This XML file does not appear to have any style information associated with it. The document tree is shown below.




















发布成功

同样用前面的调用实例调用一次试试即可。



你可能感兴趣的:(Java,webservice)