XFire Unexpected character '>' (code 62) expected '='

虚线以下内容是网络上找到的他人的方法,自己面临 Unexpected character '>' (code 62) expected '=' 时尝试使用此法,但却不见效,后来发现,每当出现此错误,重新启动 (1)MyEclipse 或 (2) Tomcat 或  (3) 计算机 ( Computer)可 解决此问题。
------------------------------------------------------
声明:第一次开发WebService,第一次使用XFire,WebService方面的新手
目的:分享经验、备忘
时间:2008-01-22
错误说明:在调用WebService的时候报错:
Java代码
  1. org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='  
org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='

解决方案:在webService应用的web.xml中加入:
Java代码
  1.    <filter>   
  2.     <filter-name>CompressingFilter</filter-name>   
  3.     <filter-class>   
  4.         com.planetj.servlet.filter.compression.CompressingFilter   
  5.     </filter-class>   
  6.     <init-param>   
  7.         <param-name>debug</param-name>   
  8.         <param-value>false</param-value>   
  9.     </init-param>   
  10.     <init-param>   
  11.         <param-name>statsEnabled</param-name>   
  12.         <param-value>true</param-value>   
  13.     </init-param>   
  14. </filter>   
  15. <filter-mapping>   
  16.     <filter-name>CompressingFilter</filter-name>   
  17.     <url-pattern>/services/*</url-pattern>   
  18. </filter-mapping>  
    <filter>

		<filter-name>CompressingFilter</filter-name>

		<filter-class>

			com.planetj.servlet.filter.compression.CompressingFilter

		</filter-class>

		<init-param>

			<param-name>debug</param-name>

			<param-value>false</param-value>

		</init-param>

		<init-param>

			<param-name>statsEnabled</param-name>

			<param-value>true</param-value>

		</init-param>

	</filter>

	<filter-mapping>

		<filter-name>CompressingFilter</filter-name>

		<url-pattern>/services/*</url-pattern>

	</filter-mapping>



详细说明:
开发环境:
    服务器:Tomcat5.0
   JDK:  JDK1.4.2
   IDE:  MyEclicpse6.0.0 GA+Eclipse3.3
   其他:  XFire1.2.6
开发简要说明(代码就是SayHello,这里不再说明):
1、通过MyEclipse建立Web Service Project
2、通过MyEclipse新增WebService:
     service name:SayAny
    Service Interface: ISayAny
    Service Impl. class:  ISayAnyImpl
生成的Web.xml如下:
Java代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">   
  3.   <servlet>    
  4.     <servlet-name>XFireServlet</servlet-name>   
  5.     <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>   
  6.     <load-on-startup>0</load-on-startup>   
  7.   </servlet>   
  8.   <servlet-mapping>   
  9.     <servlet-name>XFireServlet</servlet-name>   
  10.     <url-pattern>/services/*</url-pattern>   
  11.   </servlet-mapping>   
  12.   <welcome-file-list>   
  13.     <welcome-file>index.jsp</welcome-file>   
  14.   </welcome-file-list>   
  15. </web-app>  
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <servlet> 

    <servlet-name>XFireServlet</servlet-name>

    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>

    <load-on-startup>0</load-on-startup>

  </servlet>

  <servlet-mapping>

    <servlet-name>XFireServlet</servlet-name>

    <url-pattern>/services/*</url-pattern>

  </servlet-mapping>

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>



services.xml内容如下:(新手说明:在项目下与WebRoot同级目录下,myEclipse自动生成一个WebServices目录,services.xml在此目录中)
Java代码
  1. <beans xmlns="http://xfire.codehaus.org/config/1.0">   
  2. <service>   
  3. <name>SayAny</name>   
  4. <serviceClass>com.jiang.service.ISayAny</serviceClass>   
  5. <implementationClass>com.jiang.service.SayAnyImpl</implementationClass>   
  6. <style>wrapped</style>   
  7. <use>literal</use>   
  8. <scope>application</scope>   
  9. </service>   
  10. </beans>  
<beans xmlns="http://xfire.codehaus.org/config/1.0">

<service>

<name>SayAny</name>

<serviceClass>com.jiang.service.ISayAny</serviceClass>

<implementationClass>com.jiang.service.SayAnyImpl</implementationClass>

<style>wrapped</style>

<use>literal</use>

<scope>application</scope>

</service>

</beans>



3、直接通过MyEclipse发布到Tomcat上;
4、访问http://localhost/studyWebService/services/SayAny?wsdl可以成功看到一个XML内容,里面内容不在此说明
5、编写测试程序,main方法如下:
Java代码
  1. public static void main(String[] args) {   
  2.     String serviceURL = "http://localhost/studyWebService/services/SayAny";   
  3.        
  4.     String datas = "";   
  5.     //service   
  6.     Service serviceModel = new ObjectServiceFactory().create(   
  7.             ISayAny.classnull""null);   
  8.   
  9.     XFireProxyFactory serviceFactory = new XFireProxyFactory();   
  10.     try {   
  11.         ISayAny service = (ISayAny) serviceFactory.create(   
  12.                 serviceModel, serviceURL);   
  13.         Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();   
  14.         client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED,   
  15.                 Boolean.TRUE);   
  16.         client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");   
  17.         datas = service.sayHello("jiang shan");   
  18.         System.out.println(datas);   
  19.            
  20.     } catch (Exception e) {   
  21.         e.printStackTrace();   
  22.     }   
  23. }  
	public static void main(String[] args) {

		String serviceURL = "http://localhost/studyWebService/services/SayAny";

		

		String datas = "";

		//service

		Service serviceModel = new ObjectServiceFactory().create(

				ISayAny.class, null, "", null);



		XFireProxyFactory serviceFactory = new XFireProxyFactory();

		try {

			ISayAny service = (ISayAny) serviceFactory.create(

					serviceModel, serviceURL);

			Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();

			client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED,

					Boolean.TRUE);

			client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");

			datas = service.sayHello("jiang shan");

			System.out.println(datas);

			

		} catch (Exception e) {

			e.printStackTrace();

		}

	}



WebServer获得相应,但在
Java代码
  1. datas = service.sayHello("jiang shan");  
datas = service.sayHello("jiang shan");
报错:
错误如下:
Java代码
  1.   
  2. com.jiang.service.TestAdStatData  - Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='  
  3.  at [row,col {unknown-source}]: [1,708]   
  4. org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='  
  5.  at [row,col {unknown-source}]: [1,708]   
  6. org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='  
  7.  at [row,col {unknown-source}]: [1,708]   
  8.     at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)   
  9.     at org.codehaus.xfire.client.Client.onReceive(Client.java:391)   
  10.     at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)   
  11.     at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)   
  12.     at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)   
  13.     at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)   
  14.     at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:75)   
  15.     at org.codehaus.xfire.client.Client.invoke(Client.java:335)   
  16.     at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)   
  17.     at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)   
  18.     at $Proxy0.getAdDataByUidAndPosId(Unknown Source)   
  19.     at com.jiang.service.TestAdStatData.main(TestAdStatData.java:37)   
  20. Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '>' (code 62) expected '='  
  21.  at [row,col {unknown-source}]: [1,708]   
  22.     at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:623)   
  23.     at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:2999)   
  24.     at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2934)   
  25.     at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2846)   
  26.     at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1019)   
  27.     at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:44)   
  28.     at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)   
  29.     at org.codehaus.xfire.client.Client.onReceive(Client.java:387)   
  30.     ... 10 more  
com.jiang.service.TestAdStatData  - Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='

 at [row,col {unknown-source}]: [1,708]

org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='

 at [row,col {unknown-source}]: [1,708]

org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='

 at [row,col {unknown-source}]: [1,708]

	at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)

	at org.codehaus.xfire.client.Client.onReceive(Client.java:391)

	at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)

	at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)

	at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)

	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)

	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:75)

	at org.codehaus.xfire.client.Client.invoke(Client.java:335)

	at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)

	at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)

	at $Proxy0.getAdDataByUidAndPosId(Unknown Source)

	at com.jiang.service.TestAdStatData.main(TestAdStatData.java:37)

Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '>' (code 62) expected '='

 at [row,col {unknown-source}]: [1,708]

	at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:623)

	at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:2999)

	at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2934)

	at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2846)

	at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1019)

	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:44)

	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)

	at org.codehaus.xfire.client.Client.onReceive(Client.java:387)

	... 10 more



解决方案本文上面所说:加入pjl-comp-filter-1.4.6.jar,并在Web.xml中配置filter即可。

出错原因:这句有问题:
Java代码
  1. client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED,Boolean.TRUE);  
client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED,Boolean.TRUE);

客户端调用时设置了GZIP参数,但Server端没有用GZIP过滤文件!

你可能感兴趣的:(character)