Below the dotted line is the method of someone else found on the network. I tried to use this method when faced with unexpected character '>' (Code 62) Expected '=', but it did not work. Later I found that, when this error occurs, restart (1) myeclipse or (2) tomcat or (3) computer to solve the problem. ---------------------------------------------------- Statement: the first time WebService is developed, the first time xfire is used, and the WebService is a beginner.
Objective: To share experiences and memos
Time: 2008-01-22
Error Description: an error is returned when WebService is called:
Java code
- Org. codehaus. xfire. fault. xfirefault: Unexpected character '>' (Code 62) Expected '='
org.codehaus.xfire.fault.XFireFault: Unexpected character '>' (code 62) expected '='
Solution: Add the following Java code to the Web. xml file of the WebService application:
- <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>
<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>
Detailed description:
Development Environment:
Server: tomcat5.0
JDK: jdk1.4.2
IDE: myeclicpse6.0.0 GA + eclipse3.3
Others: xfire1.2.6
Brief development description (the code is sayhello, which is not described here ):
1. Create a web service project through myeclipse
2. Use myeclipse to add WebService:
Service name: sayany
Service Interface: isayany
Service impl. Class: isayanyimpl
The generated web. XML is as follows: Java code
- <? 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. xfirepolicableservlet </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>
<?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 content is as follows: (for beginners, in the same directory as webroot under the project, myeclipse automatically generates a WebServices directory, services. XML in this directory) Java code
- <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>
<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. Directly publish to Tomcat through myeclipse;
4. Access http: // localhost/studywebservice/services/sayany? You can see an XML content in WSDL, which is not described here.
5. Compile the test program. The main method is as follows: Java code
- 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 ();
- }
- }
public static void main(String[] args) {String serviceURL = "http://localhost/studyWebService/services/SayAny";String datas = "";//serviceService 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 obtains the corresponding information,
Java code
- Datas = service. sayhello ("Jiang Shan ");
datas = service.sayHello("jiang shan");
Error:
The error is as follows: Java code
- Com. Jiang. Service. testadstatdata-cocould 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: cocould 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. streamcompute. throwunexpectedchar (streamcompute. 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
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
Solution This article says: add the pjl-comp-filter-1.4.6.jar and configure the filter in Web. xml.
Cause of error: This sentence has a problem:
Java code
- Client. setproperty (commonshttpmessagesender. gzip_enabled, Boolean. True );
client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED,Boolean.TRUE);
The gzip parameter is set during client calling, but the server does not use gzip to filter files!