首页 新闻 搜索 专区 学院

服务端如何解析从客户端传入的参数,客户端只有一个参数,但是这个参数里包含了很多参数。

0
悬赏园豆:30 [已关闭问题] 关闭于 2016-10-26 08:38

/*
* BiddingfailureServerSkeleton.java
*
* This file was auto-generated from WSDL
* by the Apache Axis2 version: 1.4 Built on : Apr 26, 2008 (06:24:30 EDT)
*/
package cn.com.bmcc.www.xmlns.biddingfailure_supply.biddingfailure.biddingfailureservice;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URL;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;

import oracle.jdbc.OracleTypes;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;

import sun.text.resources.FormatData;

import com.liferay.portal.SystemException;
import com.pccw.bmcc.core.utils.XmlTools;


/**
* BiddingfailureServerSkeleton java skeleton for the axisService
*/
public class BiddingfailureServerSkeleton{
private static Log log = LogFactory.getLog(BiddingfailureServerSkeleton.class);


/**
* Auto generated method signature
*
* @param biddingfailure
*/

public cn.com.bmcc.www.xmlns.biddingfailure_supply.biddingfailure.biddingfailureservice.BiddingfailureResponse Biddingfailure
(
cn.com.bmcc.www.xmlns.biddingfailure_supply.biddingfailure.biddingfailureservice.Biddingfailure biddingfailure)
{
log.info("in> Biddingfailure");
Connection con = null;
CallableStatement cs = null;
ResultSet rs = null;
BiddingfailureResponse res = null;
//解析req传过来的参数
String in0 = biddingfailure.getIn0();//传入的参数
String xmlsString=XmlTools.getFromBase64(in0);

log.info("传入参数[in0:"+in0+"]");
// 2、根据req中解析出来的参数到数据库中查询数据
String callBiddingString = "{call msm_esproject_pkg.bidding_failure(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
try {
con = DriverManager.getConnection(
getPropertiesValue("SPM_DB_URL"),
getPropertiesValue("SPM_USER"),
getPropertiesValue("SPM_PWD"));
System.out.println("数据库连接成功!");
} catch (SQLException e) {
System.out.println("数据库连接失败!");
e.printStackTrace();
}
cs = con.prepareCall(callBiddingString);
cs.setString("in0", in0);//传参数
cs.setString("P_PROJECTID",xmlsString);
cs.setString("P_ORIGINAL_PROJECTID",xmlsString);
cs.setString("P_PURCHASETYPE",xmlsString);
cs.setString("P_FAILURE_TYPE",xmlsString);
cs.registerOutParameter("P_RESULT_FLAG", OracleTypes.VARCHAR);
cs.registerOutParameter("P_RESULT_TEXT", OracleTypes.VARCHAR);
cs.registerOutParameter("P_RESULT_TYPE", OracleTypes.VARCHAR);
cs.registerOutParameter("P_ERR_ID", OracleTypes.VARCHAR);
cs.registerOutParameter("P_ERR_LEVEL", OracleTypes.NUMBER);
cs.registerOutParameter("P_ERR_TEXT", OracleTypes.VARCHAR);
cs.execute();
String RESULT_FLAG = cs.getString("P_RESULT_FLAG");
String RESULT_TEXT = cs.getString("P_RESULT_TEXT");
String RESULT_TYPE = cs.getString("P_RESULT_TYPE");
String ERR_ID = cs.getString("P_ERR_ID");
Long ERR_LEVEL = cs.getLong("P_ERR_LEVEL");
String ERR_TEXT = cs.getString("P_ERR_TEXT");
//rs = (ResultSet) cs.getObject("P_att_list");



//拼接xml字符串
StringBuffer sb = new StringBuffer();
sb.append(XmlTools.createXmlDocument());//创建一个文档声明
sb.append(XmlTools.beginNode());//开始节点
sb.append(XmlTools.property("RESULT_FLAG",RESULT_FLAG));
sb.append(XmlTools.property("RESULT_TEXT",RESULT_TEXT));
sb.append(XmlTools.property("RESULT_TYPE",RESULT_TYPE));
sb.append(XmlTools.beginList());
sb.append(XmlTools.beginERR_ITEM());
sb.append(XmlTools.property("ERR_ID",ERR_ID));
sb.append(XmlTools.property("ERR_LEVEL",ERR_LEVEL));
sb.append(XmlTools.property("ERR_TEXT",ERR_TEXT));
sb.append(XmlTools.endERR_ITEM());
sb.append(XmlTools.endList());
sb.append(XmlTools.endNode());//结束节点


res = new BiddingfailureResponse();
res.setOut(sb.toString());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rs != null){
try {
rs.close();
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (cs != null) {
try {
cs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return res;

}

private String getPropertiesValue(String propertiesKey) {
Properties p = new Properties();
InputStream is = null;
String value = "";
ClassLoader classLoader = BiddingfailureServerSkeleton.class.getClassLoader();
URL url = classLoader.getResource("portal-pccw-axis.properties");
log.info("url-----"+url);
if(url != null){
try {
is = url.openStream();
p.load(is);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
value = p.getProperty(propertiesKey);
return value;
}

/**
* 处理返回的信息
* @param returnInfo
* @throws SystemException
*/
public static void handleReturnInfo(String returnInfo,String workdocSize,String attachmentSize) throws SystemException{

StringReader xmlReader = new StringReader(returnInfo);
/** **创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入 */
InputSource xmlSource = new InputSource(xmlReader);
/** *创建一个SAXBuilder* */
SAXBuilder builder = new SAXBuilder();
/** *通过输入源SAX构造一个Document** */
try {
org.jdom.Document doc = builder.build(xmlSource);
Element root = doc.getRootElement();
//得到根元素所有子元素的集合
List FAILPROJECT = root.getChildren();
//List PRODUCTINFOS = root.getChildren();
//List PRODUCTINFO = root.getChildren();

Element et=null;
String PROJECTID=null;
String PROJECTCODE=null;
String ORIGINAL_PROJECTID=null;
Long PURCHASETYPE = null;
Long FAILURE_TYPE = null;
String FAILUREMARK_TIME = null;
String FAILUREPROCESSING_TIME = null;
String MATERIAL_CODE = null;
Long FAILUERNUMDER_MATERIAL = null;
String REASON = null;
Long RESERVESTR1 = null;
String RESERVESTR2 = null;
for(int i=0;i<FAILPROJECT.size();i++){
et=(Element)FAILPROJECT.get(i);
String name = et.getName();
if("Success".equals(name)){
FAILPROJECT = et.getChildren("FAILPROJECT");
PROJECTID = et.getChildText("PROJECTID");
PROJECTCODE = et.getChildText("PROJECTCODE");
ORIGINAL_PROJECTID = et.getChildText("ORIGINAL_PROJECTID");
PURCHASETYPE = Long.parseLong(et.getChildText("PURCHASETYPE"));
FAILURE_TYPE = Long.parseLong(et.getChildText("FAILURE_TYPE"));
FAILUREMARK_TIME =et.getChildText("FAILUREMARK_TIME");
FAILUREPROCESSING_TIME = et.getChildText("FAILUREPROCESSING_TIME");
//PRODUCTINFOS = et.getChildren("PRODUCTINFOS");
//PRODUCTINFO = et.getChildren("PRODUCTINFO");
MATERIAL_CODE = et.getChildText("MATERIAL_CODE");
FAILUERNUMDER_MATERIAL = Long.parseLong(et.getChildText("FAILUERNUMDER_MATERIAL"));
REASON = et.getChildText("REASON");
RESERVESTR1 = Long.parseLong(et.getChildText("RESERVESTR1"));
RESERVESTR2 = et.getChildText("RESERVESTR2");
}
if("Error".equals(name)){
FAILPROJECT = et.getChildren("FAILPROJECT");
PROJECTID = et.getChildText("PROJECTID");
PROJECTCODE = et.getChildText("PROJECTCODE");
ORIGINAL_PROJECTID = et.getChildText("ORIGINAL_PROJECTID");
PURCHASETYPE = Long.parseLong(et.getChildText("PURCHASETYPE"));
FAILURE_TYPE = Long.parseLong(et.getChildText("FAILURE_TYPE"));
FAILUREMARK_TIME = et.getChildText("FAILUREMARK_TIME");
FAILUREPROCESSING_TIME = et.getChildText("FAILUREPROCESSING_TIME");
//PRODUCTINFOS = et.getChildren("PRODUCTINFOS");
//PRODUCTINFO = et.getChildren("PRODUCTINFO");
MATERIAL_CODE = et.getChildText("MATERIAL_CODE");
FAILUERNUMDER_MATERIAL = Long.parseLong(et.getChildText("FAILUERNUMDER_MATERIAL"));
REASON = et.getChildText("REASON");
RESERVESTR1 = Long.parseLong(et.getChildText("RESERVESTR1"));
RESERVESTR2 = et.getChildText("RESERVESTR2");
}

}

} catch (Exception e) {


e.printStackTrace();

}
}

}

 

咫尺~天涯的主页 咫尺~天涯 | 初学一级 | 园豆:8
提问于:2016-10-25 12:58
< >
分享
所有回答(4)
0

先去学学粘贴代码吧

~扎克伯格 | 园豆:1842 (小虾三级) | 2016-10-25 13:48
0

把代码格式化好啊

 

田麦成 | 园豆:1984 (小虾三级) | 2016-10-25 14:27
0

你真是可以,上来一堆,谁有心思看,遇到事情多自己想办法,不是代码一甩。就在那里闲着了

逆天蓝 | 园豆:147 (初学一级) | 2016-10-25 18:26
0

问公司大神解决了

咫尺~天涯 | 园豆:8 (初学一级) | 2016-10-26 08:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册