Axis 中调用org.apache.axis.enum.Style.RPC时老报错

本文介绍了如何解决在使用Axis1.4版本的WebService项目时,由于JDK1.6版本与enum关键字冲突导致的报错问题。通过将代码中的enum类型替换为字符串获取方式,以及引入相应的导入语句,成功解决了项目编译问题。

最近在修改一个Web Service项目,该项目是用Axis 1.X 版本写的。当我调试该项目时,发现代码中凡是出现“oper.setStyle(org.apache.axis.enum.Style.RPC);”和“oper.setUse(org.apache.axis.enum.Use.ENCODED);”的地方MyEclipse都对其进行了报错。经网上查实,得出分析结果如下:

    问题原因: 在JDK 1.5及其以上版本中,enum都会被JDK认为是系统关键字,不能作为自定义变量使用。而我的JDK是1.6版本的,因此项目在编译时始终无法通过。

    准备工作:到网站”http://www.apache.org/dist/ws/axis/1_4/“中下载Axis 1.4,并将重要的*.jar文件导入到项目中去。

    解决办法:1、将代码“oper.setStyle(org.apache.axis.enum.Style.RPC);”修改为”oper.setStyle(Style.getStyle("rpc"));“;2、将代码“oper.setUse(org.apache.axis.enum.Use.ENCODED);”修改为“oper.setUse(Use.getUse("encoded")); ”;3、添加代码”import org.apache.axis.constants.Style;
import org.apache.axis.constants.Use;“

package com.hongyousoft.bigdata.bjxny.utils.ccusManage; import net.sf.json.JSONObject; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import org.apache.axis.message.SOAPHeaderElement; import javax.xml.namespace.QName; public class InvokeService { public static Object invoke(String url, String methodName, Object[] parameterValue, String returnType, String username, String password) { JSONObject obj = new JSONObject(); //创建服务 Service service = new Service(); try { //创建Call Call call = (Call) service.createCall(); ///设置地址 call.setTargetEndpointAddress(new java.net.URL(url)); //设置命名空间和方法名 QName qname = new QName("http://webserviceinterface.dataservice.org", methodName); call.setOperationName(qname); //添加参数列表 for (int i = 0; i < parameterValue.length; i++) { call.addParameter(new QName("parameter"), XMLType.XSD_ANYTYPE, javax.xml.rpc.ParameterMode.IN); } //身份验证 SOAPHeaderElement header = new SOAPHeaderElement("", "AuthenticationToken"); header.setPrefix(""); header.addChildElement("Username").addTextNode(username); header.addChildElement("Password").addTextNode(password); call.addHeader(header); //设置返回值类型 call.setReturnType(new QName("http://www.w3.org/2001/XMLSchema", returnType)); // 设置参数值来调用方法 return call.invoke(parameterValue); } catch (Exception e) { e.printStackTrace(); String exceptionInfo = e.toString(); if (exceptionInfo.indexOf("Not enough message parts were received for the operation.") > -1) { obj.put("code", "error"); obj.put("message", "传递参数不足"); return obj; } else if (exceptionInfo.indexOf("java.lang.IndexOutOfBoundsException") > -1) { obj.put("code", "error"); obj.put("message", "传递参数过多"); return obj; } else if (exceptionInfo.indexOf("请求必须包含身份验证信息") > -1) { obj.put("code", "error"); obj.put("message", "请求必须包含身份验证信息"); return obj; } else if (exceptionInfo.indexOf("非法的用户名或密码") > -1) { obj.put("code", "error"); obj.put("message", "账号或密码错误"); return obj; } else if (exceptionInfo.indexOf("用户ip已绑定") > -1) { obj.put("code", "error"); obj.put("message", "非法IP请求"); return obj; } else if (exceptionInfo.indexOf("系统出现异常") > -1) { obj.put("code", "error"); obj.put("message", "服务端系统出现异常"); return obj; } else if (exceptionInfo.indexOf("请在授权的间段内调用服务") > -1) { obj.put("code", "error"); obj.put("message", "请在授权的间段内调用服务"); return obj; } else if (exceptionInfo.indexOf("该用户已锁定") > -1) { obj.put("code", "error"); obj.put("message", "该用户已锁定"); return obj; } else if (exceptionInfo.indexOf("访问的服务不存在") > -1) { obj.put("code", "error"); obj.put("message", "访问的服务不存在"); return obj; } else if (exceptionInfo.indexOf("访问的服务方法不存在") > -1) { obj.put("code", "error"); obj.put("message", "访问的服务方法不存在"); return obj; } else if (exceptionInfo.indexOf("java.net.ConnectException: Connection refused") > -1) { obj.put("code", "error"); obj.put("message", "接口服务连接超"); return obj; } } return null; } }
最新发布
11-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值