当前位置:编程学习 > JAVA >>

求解释下面这组代码为何出粗

使用axis2的AXIOM编写一个LZW编码器和解码器,关键问题在于用客户端访问服务端的时候报错。
服务端代码:
package XMLZW;
import java.util.*;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import javax.xml.stream.events.Characters;
public class newLZWcode 
{
public OMElement runLZWcode(OMElement e)
{
e.build();
        String rootName = e.getLocalName();
        System.out.println("Reading "+rootName+" element");
        OMElement childElement = e.getFirstElement();
        String parametor = childElement.getText();
LZW l=new LZW();
String codes=l.Coding(parametor);
System.out.println(codes);
OMFactory fac = OMAbstractFactory.getOMFactory();
     OMNamespace omns=fac.createOMNamespace("http://XMLZW","Title");
     OMElement result=fac.createOMElement("result",omns);
     result.setText(codes);
return result;
}
public OMElement runLZWdecode(OMElement e)
{
e.build();
        String rootName = e.getLocalName();
        System.out.println("Reading "+rootName+" element");
        OMElement childElement = e.getFirstElement();
        String parametor = childElement.getText();
LZW l=new LZW();
String codes=l.decoding(parametor);
System.out.println(codes);
OMFactory fac = OMAbstractFactory.getOMFactory();
     OMNamespace omns=fac.createOMNamespace("http://XMLZW","Title");
     OMElement result=fac.createOMElement("result",omns);
     result.setText(codes);
return result;
}
}
class LZW
{
Hashtable dictionarycd=new Hashtable();
Hashtable dictionarydcd=new Hashtable();
int num=0;
LZW()
{
for(int i=0;i<26;++i)
{
dictionarycd.put(((Character)((char)('a'+i))).toString(),++num);
dictionarydcd.put(num, ((Character)((char)('a'+i))).toString());
}
dictionarycd.put(' ',++num);
dictionarydcd.put(num,' ');
}
String Coding(String s)
{
String result=new String();
char[] c=s.toCharArray();
String temp=new String();
for(int i=0;i<s.length();++i)
{
temp=temp+c[i];
Object o=dictionarycd.get(temp);
if(o!=null)
continue;
else
{
dictionarycd.put(temp, ++num);
dictionarydcd.put(num, temp);
result+=Integer.valueOf(dictionarycd.get(temp.substring(0, temp.length()-1)).toString()).toString()+" ";
temp=((Character)((char)(c[i]))).toString();
}
}
result+=Integer.valueOf(dictionarycd.get(temp).toString()).toString()+" ";
return result;
}
String decoding(String s)
{
String result=new String();
char[] c=s.toCharArray();
String temp=new String();
for(int i=0;i<c.length;++i)
{
if(c[i]!=' ')
temp+=c[i];
else
{
int code=Integer.valueOf(temp);
result+=dictionarydcd.get(code).toString();
temp="";
}
}
return result;
}
}

客户端代码
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.axiom.om.OMAbstractFactory; 
import org.apache.axiom.om.OMElement; 
import org.apache.axiom.om.OMFactory; 
import org.apache.axiom.om.OMNamespace; 
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.jdom.output.XMLOutputter;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

import java.io.FileOutputStream;
import java.util.List;

public class test1


      public static void main(String[] args)
      {
             try
             {
              EndpointReference targetEPR =
              new EndpointReference("http://localhost:8080/axis2/services/XMLZW");
              ServiceClient client=new ServiceClient();
              Options options=new Options();
              options.setTo(targetEPR);
              options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
              client.setOptions(options);
              OMElement res=client.sendReceive(setString("runLZWcode","hellow"));
              System.out.println(res.getFirstElement().getText());
             }
             catch(Exception e)
             {}
    } 
    static OMElement setString(String function,String test)
    {
     OMFactory fac = OMAbstractFactory.getOMFactory();
     OMNamespace omns=fac.createOMNamespace("http://XMLZW","Title");
     OMElement method=fac.createOMElement(function,omns);
     OMElement parament=fac.createOMElement(test,omns);
     parament.addChild(fac.createOMText(parament,test));
     method.addChild(parament);
     return method;
    }



services.xml代码
<service name="XMLZW">
    <description>
        Web Service
    </description>
    <parameter name="ServiceClass">
        XMLZW.newLZWcode  
    </parameter>
    <operation name="runLZWcode">
        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </operation>
    <operation name="runLZWdecode">
        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </operation>
</service> Java --------------------编程问答-------------------- 除
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,