`
- 浏览:
35745 次
- 性别:
- 来自:
深圳
-
- public class FeatureXmlExportServlet extends HttpPostServlet {
-
-
-
- private static final long serialVersionUID = -6732796071756836554L;
-
- @Override
- protected void doGet(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- this.doPost(request, response);
- }
-
- @Override
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
-
- try {
- request.setCharacterEncoding("UTF-8");
- response.setCharacterEncoding("UTF-8");
- String version = request.getParameter("version");
- String tdt = request.getParameter("tdtname");
- tdt = new String(tdt.getBytes("UTF-8"), "UTF-8");
- String tdtName = this.getTDTValue(tdt);
-
- String fileName = "character";
-
- fileName = new String(fileName.getBytes("UTF-8"), "UTF-8");
-
- response.setHeader("Content-disposition",
- "attachment; filename=" + fileName + ".xml");
-
- response.setHeader("Pragma", "public");
-
- response.setHeader("Cache-Control", "must-revalidate");
-
- response.setDateHeader("Expires", 0);
-
- response.setContentType("text/csv; charset=UTF-8");
-
-
-
-
-
- String webInfPath = Utility.getWebInfPath() ;
- File file = new File(webInfPath + File.separator + tdt + "-"
- + version);
- if (file.exists()) {
- Document doc = getXmlDocument(file.getPath());
- doc.write(response.getWriter());
- } else {
- SelfDefineImportExport ie = new SelfDefineImportExport();
- Document doc = DocumentHelper.createDocument();
-
- ie.creatXML(doc, version, tdtName);
-
- save(doc,file.getPath());
- doc.write(response.getWriter());
- }
-
- ToolSpyLogger.init("iFree");
- ToolSpyLogger.log("E3-View","特性树Web服务接口");
- ToolSpyLogger.release();
- response.getWriter().flush();
- } catch (Exception e) {
- e.printStackTrace();
- this.doResponse(response, new GeneralHttpResponse(
- ResponseResult.FAILURE, "没有找到相关内容"));
- }
-
- }
-
- public static Document getXmlDocument(String fileName)
- {
- Document document = null;
- try {
- String xml = readTxt(fileName);
- document = DocumentHelper.parseText(xml);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return document;
- }
-
- public static String readTxt(String txtPath) {
- String content = " ";
- try {
- InputStream is = new FileInputStream( new File(txtPath) );
- BufferedReader buffReader = new BufferedReader(new InputStreamReader(is,"utf-8"));
- content = buffReader.readLine();
- String line;
- try
- {
- while ((line = buffReader.readLine()) != null)
- {
- if (line.equals(""))
- continue;
- else
- content += line + "\r\n";
- }
- } catch (IOException e) {
- e.printStackTrace();
- System.out.println("Error reading file");
- }
- buffReader.close();
- is.close();
- } catch (FileNotFoundException e) {
- System.out.println("file is not exist,can't read...");
- } catch (IOException e) {
- e.printStackTrace();
- }
- return content;
- }
-
-
- public static void save(Document document,String fileName)
- {
- try
- {
- FileOutputStream mOutputStream = new FileOutputStream(fileName);
- OutputFormat fmt = new OutputFormat(document.asXML());
- fmt.setTrimText(true);
- fmt.setPadText(true);
- fmt.setIndent(true);
- fmt.setIndentSize(0);
- fmt.setNewlines(true);
- fmt.setEncoding("utf-8");
-
- XMLWriter writer = new XMLWriter( mOutputStream, fmt );
- writer.write(document);
- mOutputStream.flush();
- mOutputStream.close();
- }catch (IOException e)
- {
- e.printStackTrace();
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
- }
- @SuppressWarnings("deprecation")
- private String getTDTValue(String tdt){
- Connection con = null;
- Statement state = null;
- String tdtKey=null;
- Session session = HibernateSessionFactory.getSession();
- try {
- con = session.connection();
- con.setAutoCommit(true);
- session.beginTransaction();
-
- String sq="select dict_value from e3_dict_table where dict_describe='" + tdt + "' and dict_type_id = 'FEATURE_TDT'" ;
- state = con.createStatement();
- ResultSet result = state.executeQuery(sq);
- while(result.next()){
- tdtKey=result.getString("DICT_VALUE");
- }
- con.commit();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- try {
- if(state != null)
- state.close();
- if(con != null)
- HibernateSessionFactory.closeSession();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return tdtKey;
- }
-
- }public class HttpFeatureTree {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public boolean sendStrOfPost(String urlStr, String contentStr, String charset, StringBuffer sResult) {
- boolean bResult = false;
- String charsetName = charset;
- URL url = null;
- HttpURLConnection httpConnection = null;
- InputStream httpIS = null;
- java.io.BufferedReader http_reader = null;
- try {
- url = new URL(urlStr);
- httpConnection = (HttpURLConnection) url.openConnection();
-
-
- httpConnection.setConnectTimeout(10000);
-
- httpConnection.setReadTimeout(10000);
-
- httpConnection.setRequestMethod("POST");
- httpConnection.setDoOutput(true);
- httpConnection.setRequestProperty("Content-Length", String.valueOf(contentStr.getBytes().length));
- PrintWriter out = null;
- out = new PrintWriter(new OutputStreamWriter(httpConnection.getOutputStream(), charsetName));
-
- out.print(contentStr);
- out.flush();
- out.close();
- int responseCode = httpConnection.getResponseCode();
- if (responseCode == HttpURLConnection.HTTP_OK) {
-
- bResult = true;
-
-
- httpIS = httpConnection.getInputStream();
- http_reader = new java.io.BufferedReader(new java.io.InputStreamReader(httpIS, charsetName));
- String line = null;
- while ((line = http_reader.readLine()) != null) {
- if (sResult.length() > 0) {
- sResult.append("\n");
- }
- sResult.append(line);
- }
-
- } else {
-
- }
- } catch (IOException e) {
-
- }
- finally {
- try {
- if (http_reader != null)
- http_reader.close();
- if (httpIS != null)
- httpIS.close();
- if (httpConnection != null)
- httpConnection.disconnect();
- } catch (IOException e) {
-
- }
- }
-
- return bResult;
- }
-
- public static void main(String[] args)
- {
- HttpFeatureTree http = new HttpFeatureTree();
- StringBuffer sResult = new StringBuffer();
- String str ="http://e3/GetFeatureTDTServlet?version=U2000V1R7C00";
- str = str.replaceAll(" ", "%20");
- http.sendStrOfPost(str, "", "utf-8", sResult);
-
- String s=sResult.toString();
- System.out.print(s);
-
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
C0128国家政务服务平台政务服务数据服务接口要求
本部分为SZDB Z 17 2008 的第10部分 业务流程服务接口规范">SZDB Z 17 2008《深圳市电子政务应用服务规范》目前分为10 个部分: 第1 部分《总则》 第2 部分《应用系统分类及代码规范》 第3 部分《应用系统描述规范...
GB61850-7-2_抽象通讯服务接口
使用C#创建webservice服务,并使用服务接口得到C#动态库。然后可以使用C++程序调用
深圳市电子政务应用服务规范 第7部分:访问控制服务接口规范
标准:GM∕T 0019-2012 通用密码服务接口规范.pdf
Q/GDW_622-2011《电力系统简单服务接口规范》及编制说明. 电力系统简单服务接口规范是在WSDL语言的基础上,针对WSDL在以XML方式进行描述时的效率缺陷所发展出来的一种新型高效的服务描述语言
smb文件服务器接口及实现例子,实现资源的分流,减轻数据库的压力。
该部分定义了业务流程服务的基本概念,...了流程服务提供的服务接口,包括流程模型服务接口、流程实例服务接口、应用调用服务接口、流程互 操作服务接口、流程管理服务接口五部分内容,为应用系统提供统一的流程服务
手机短信服务接口合作协议原理与分析,做手机开发应该要了解的一本资料。
该部分规定了单点登录服务接口,定义了单点登录票据的模式。适用于需做单点登录整合的应用系统。
地基增强服务接口控制文件1.0
该部分规定了电子政务应用系统中组织身份各种实体的操作接口、实体间关系的操作接口和实体查 询接口,规定了组织身份服务的服务注册接口、同其它系统的数据同步接口
服务器接口文档,规范,完整,事例,,,可查看http://blog.csdn.net/qq_36467463/article/details/79106409
深圳市电子政务应用服务规范 第6部分:组织身份服务接口规范
深圳市电子政务应用服务规范 第8部分:单点登录服务接口规范
LY/T 2177-2013 林业信息服务接口规范
GMT 0019-2012 通用密码服务接口规范.pdf
CHT 9027-2018 数字城市地理信息公共平台服务接口