当前位置: 代码迷 >> Java Web开发 >> AXIS 出错..郁闷很久..期待高手指点..
  详细解决方案

AXIS 出错..郁闷很久..期待高手指点..

热度:878   发布时间:2007-12-19 10:08:28.0
AXIS 出错..郁闷很久..期待高手指点..
Server.java

package com.outsource;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
public class Server {
    public Document doCreate()
    {
        List list = new ArrayList();
        A a = new A();
        a.setName("ABC");
        a.setPwd("123456");
        a.setSex("男");
        list.add(a);
        a = new A();
        a.setName("being");
        a.setPwd("123456");
        list.add(a);
        a = new A();
        a.setName("ZBY");
        a.setPwd("123456");
        a.setSex("BOY");
        list.add(a);
        Element Root = new Element("USERS");
        Document Doc = new Document(Root);
        Element Attribute = null;
        Element Center = null;
        for(int i=0;i<list.size();i++)
        {
            Center = new Element("USERS".substring(0, "USERS".length()-1));
            Root.addContent(Center);
            Field[] fd = list.get(i).getClass().getDeclaredFields();
            for(int j=0;j<fd.length;j++)
            {
                String fdname = fd[j].getName();
                StringBuffer buf=new StringBuffer();
                buf.append("get");
                buf.append(fdname.substring(0,1).toUpperCase());
                buf.append(fdname.substring(1));
                try{
                    Method method = list.get(i).getClass().getDeclaredMethod(buf.toString());
                    fdname = fdname.toLowerCase();
                    String ss = (method.invoke(list.get(i))==null?" ":method.invoke(list.get(i)).toString());
                    Attribute = new Element(fdname);
                    Attribute.setText(ss);
                    Center.addContent(Attribute);
                }catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
        return Doc;
    }
    public String test(){
        
        return "BEING.zhou";
    }
}

------------------------------------------------
server-config.wsdd
------------------------------------------------

<service name="Server" provider="java:RPC">
       <parameter name="className" value="com.outsource.Server"/>
       <parameter name="allowedMethods" value="*"/>

<!-- 具体某个方法说明 -->
       <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"   
       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       qname="ns:Document"
       serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
       type="java:org.jdom.Document"
       xmlns:ns="Server"/>
        
       <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"   
       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       qname="ns:DescendantIterator"
       serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
       type="java:org.jdom.DescendantIterator"      
       xmlns:ns="Server"/>
        
       <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"   
       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       qname="ns:DescendantIterator"
       serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"        
       type="java:org.jdom.DescendantIterator"      
       xmlns:ns="Server"/>        
        
        
       <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       qname="ns:Element"
       serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
       type="java:org.jdom.Element"
       xmlns:ns="Server"/>
        
       <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
       encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       qname="ns:Namespace"
       serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
       type="java:org.jdom.Namespace" xmlns:ns="Server"/>
</service>
------------------------------
web.xml
-----------------------------
<web-app>
  <display-name>Apache-Axis</display-name>
   
    <listener>
        <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    </listener>
   
  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AxisServlet
    </servlet-class>
  </servlet>

  <servlet>
    <servlet-name>AdminServlet</servlet-name>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AdminServlet
    </servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <display-name>SOAPMonitorService</display-name>
    <servlet-class>
        org.apache.axis.monitor.SOAPMonitorService
    </servlet-class>
    <init-param>
      <param-name>SOAPMonitorPort</param-name>
      <param-value>5001</param-value>
    </init-param>
    <load-on-startup>100</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
  </servlet-mapping>

<!-- uncomment this if you want the admin servlet -->
<!--
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
-->

    <session-config>
        <!-- Default to 5 minute session timeouts -->
        <session-timeout>5</session-timeout>
    </session-config>

    <!-- currently the W3C havent settled on a media type for WSDL;
    [url]http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft[/url]
    for now we go with the basic 'it's XML' response -->
  <mime-mapping>
    <extension>wsdl</extension>
     <mime-type>text/xml</mime-type>
  </mime-mapping>
  

  <mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
  </mime-mapping>

  <welcome-file-list id="WelcomeFileList">
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index</welcome-file>
    <welcome-file>index.jws</welcome-file>
  </welcome-file-list>

</web-app>

---------------------

调用
Client.java
---------------------
package com.outsource;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.jdom.Document;
import org.jdom.Element;
import com.sun.org.apache.xpath.internal.axes.DescendantIterator;
public class Client {

    public static void main(String args[])
    {
        try{
        String endpoint = "http://localhost:8080/AXIS/services/Server?wsdl";//指明服务所在位置
           Service  service = new Service();  //创建一个Service实例,注意是必须的!
           Call     call    = (Call) service.createCall();//创建Call实例,也是必须的!
         call.setTargetEndpointAddress( new java.net.URL(endpoint) );//为Call设置服务的位置
         QName qn = new QName("Server","Document");
         call.registerTypeMapping(Document.class, qn,    new BeanSerializerFactory(Document.class, qn),    new BeanDeserializerFactory(Document.class, qn));
         qn = new QName("Server","DescendantIterator");
         call.registerTypeMapping(DescendantIterator.class, qn,    new BeanSerializerFactory(DescendantIterator.class, qn),    new BeanDeserializerFactory(DescendantIterator.class, qn));
         qn = new QName("Server","Element");
         call.registerTypeMapping(Element.class, qn,    new BeanSerializerFactory(Element.class, qn),    new BeanDeserializerFactory(Element.class, qn));
//         qn = new QName("Server","DescendantIterator");
//         call.registerTypeMapping(Document.class, qn,    new BeanSerializerFactory(DescendantIterator.class, qn),    new BeanDeserializerFactory(DescendantIterator.class, qn));
            call.setOperationName("doCreate");//注意方法名与HelloWorld.java中一样!!
             Document res = (Document) call.invoke( new Object[] {} );//返回String,没有传入参数
//             String res = (String) call.invoke( new Object[] {} );//返回String,没有传入参数
            System.out.println( res );
        }catch(Exception e){e.printStackTrace();}
    }
}
-----------------------------

----------------------------出现问题
- Exception:
org.xml.sax.SAXException: No object was found for class type class java.lang.String
    at org.apache.axis.encoding.ConstructorTarget.set(ConstructorTarget.java:97)
    at org.apache.axis.encoding.DeserializerImpl.valueComplete(DeserializerImpl.java:249)
    at org.apache.axis.encoding.ser.ArrayDeserializer.valueComplete(ArrayDeserializer.java:583)
    at org.apache.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.java:509)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:171)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeserializer.java:154)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:345)
    at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
    at org.apache.axis.client.Call.invoke(Call.java:2467)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.outsource.Client.main(Client.java:32)
AxisFault
faultCode: {[url]http://schemas.xmlsoap.org/soap/envelope/[/url]}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: No object was found for class type class java.lang.String
faultActor:
faultNode:
faultDetail:
    {[url]http://xml.apache.org/axis/[/url]}stackTrace:org.xml.sax.SAXException: No object was found for class type class java.lang.String
    at org.apache.axis.encoding.ConstructorTarget.set(ConstructorTarget.java:97)
    at org.apache.axis.encoding.DeserializerImpl.valueComplete(DeserializerImpl.java:249)
    at org.apache.axis.encoding.ser.ArrayDeserializer.valueComplete(ArrayDeserializer.java:583)
    at org.apache.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.java:509)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:171)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeserializer.java:154)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:345)
    at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
    at org.apache.axis.client.Call.invoke(Call.java:2467)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.outsource.Client.main(Client.java:32)

    {[url]http://xml.apache.org/axis/[/url]}hostname:287d5450a85841f

org.xml.sax.SAXException: No object was found for class type class java.lang.String
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.client.Call.invoke(Call.java:2470)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.outsource.Client.main(Client.java:32)
Caused by: org.xml.sax.SAXException: No object was found for class type class java.lang.String
    at org.apache.axis.encoding.ConstructorTarget.set(ConstructorTarget.java:97)
    at org.apache.axis.encoding.DeserializerImpl.valueComplete(DeserializerImpl.java:249)
    at org.apache.axis.encoding.ser.ArrayDeserializer.valueComplete(ArrayDeserializer.java:583)
    at org.apache.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.java:509)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:171)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
    at org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeserializer.java:154)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:345)
    at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
    at org.apache.axis.client.Call.invoke(Call.java:2467)
    ... 3 more
-----------------------------------------

-----------------------------------------
期待解决..
MSN: zby0308@msn.com
谢谢...
搜索更多相关主题的帖子: AXIS  import  quot  java  

----------------解决方案--------------------------------------------------------
我想lz,可能是要做一个最简单的webservice,其实ws用apache的axis实现起来并不复杂,但是配置起来也不是很容易,我这里有个文档或者说是demo,lz可以留个email我发给你。
----------------解决方案--------------------------------------------------------
黄袖标同志!
谢谢....
我的Email:zby0209@163.com
感激不尽..............
----------------解决方案--------------------------------------------------------