zoukankan      html  css  js  c++  java
  • 每月博客-20170203

    又到了每月博客的时间了,转眼间已经是过了年回来上班了,给大家拜个年,祝大家新的一年工作顺利,身体健康!

    同时,也深切地感受到时光荏苒,回首去年发生的一幕幕,仿佛就在昨日。

    最近一月的博客内容主要写两个方面:1)与同事交流技术的一点心得;2)基于wsdl的自顶向下webservice开发学习。

    1)与同事的几点技术交流

    中间件,中间件是提供了一系列服务的软件,简化人们实施工程的复杂性,如weblogic。tomcat功能太过简单,就不能称之为中间件,只能叫轻量级的web容器。

    jndi,我们经常会在weblogic中看到jdbc的jndi名称,实际上是用jndi规范实现的jdbc数据源域名查找方法。

    jdbc,jdbc是一种思想,它定义了一组规范,具体地实现由各个数据库厂商自行完成,并提供相应的jar包,Java语言的流行性使得各个数据库厂商有充足的动力去实现基于jdbc的数据库驱动,我们使用java语言连接数据库时,都要首先加载相应的数据库驱动。

    在这里尤其要学会规范、思想的概念,这并不是什么高深的东西,关键是要理解清楚它为什么存在,归结起来,java的诸多技术都可以称为思想,从大的方面讲,java的面向对象也是一种思想。

    2)基于wsdl的自顶向下webservice开发

    必须要读懂wsdl,自己会编写wsdl。

    wsdl一开始一般会定义一组包名,接下来是element部分,该部分可以引用其它的xsd(xsd又可以引用其它的xsd);

    message是java服务实现类操作的输入输入参数,它由一个或多个element拼接而成;

    porttype是java web服务后台真正的实现类,它的方法是operation,输入输出参数对应message中的元素;

    binding将port操作绑定为soap消息;

    service的名字对应服务名,它的binding元素对应binding,名字任意,无特殊作用。

    同时阅读了一段具体的实例,来源于日常管理的系统的一个服务,如下:

    1. 客户端部分

    1.1客户端实现类

    package com.xxx.standard.limit;

    import java.net.URL;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.text.SimpleDateFormat;

    import java.util.Calendar;

    import java.util.Date;

     

    import javax.xml.namespace.QName;

     

    import cn.com.njcb.cacheservice.CacheService;

    import cn.com.njcb.cacheservice.CacheService_Service;

    import cn.com.njcb.cacheservice.message.standardcache.StandardCacheReponse;

    import cn.com.njcb.cacheservice.message.standardcache.StandardCacheRequest;

     

    import com.xxx.are.ARE;

    import com.xxx.task.ExecuteUnit;

     

    public class LoadLimit extends ExecuteUnit {

        private String URL = "";

        private String QNAME = "";

        private String QNAMEURL = "";

        private String TODAY = "";

        private String database = "";

        @Override

        public int execute() {

           transferUnitProperties();

           int message = 1;

           try{

               Connection conn = ARE.getDBConnection(this.database);

               /*删除当天实时限额数据*/

               PreparedStatement ps = conn.prepareStatement("delete from standard_value");

               ps.execute();

               ps.close();

               conn.commit();

               conn.close();

              

               URL url = new URL(this.URL);

               QName qname = new QName(this.QNAMEURL,this.QNAME);

              

               CacheService_Service service = new CacheService_Service(url,qname);//服务

               CacheService port = service.getCacheServicePort();//端口

               StandardCacheRequest req = new StandardCacheRequest();

               /*以下为报文头*/

               //以下为ESB报文头

               req.setSEQNO("LOAD00000001");//交易流水号

               req.setSERVICEID("");//交易号,ESB内部使用

               req.setCHANNELID("XE");//渠道代号 NXDXT-对公信贷系统

               req.setBANKCODE("9900");//机构号

               req.setUSERID("system");//操作员

               req.setAUTHID("");//授权操作员

               req.setTRANDATE(this.TODAY);//请求日期

               Date d = new Date();

               SimpleDateFormat dateformat = new SimpleDateFormat("HHmmssSSS");

               req.setTRANTIME(dateformat.format(d));//请求时间

               req.setAUTHCONTEXT("");//认证信息

               /*以下为报文体*/

               req.setCacheId("LOAD");

               StandardCacheReponse res = port.standardCache(req);

              

               String result = res.getResult();

               if("FAIL".equals(result)){

                  message = 2;

                  ARE.getLog().info("加载缓存失败:"+res.getReason());

               }else{

                  message = 1;

               }

              

           }catch (Exception e){

               e.printStackTrace();

               message = 2;

           }

          

           try {

               Thread.sleep(1000*60*5);

           } catch (InterruptedException e) {

              

               e.printStackTrace();

               message = 2;

           }

          

          

           return message;

        }

       

        public void setTODAY(String tODAY) {

           TODAY = tODAY;

           if(this.TODAY != null)

               this.TODAY = this.TODAY.substring(0,4)+"/"+this.TODAY.substring(4,6)+"/"+this.TODAY.substring(6,8);

        }

       

       

        public String getURL() {

           return URL;

        }

        public void setURL(String uRL) {

           URL = uRL;

        }

        public String getQNAME() {

           return QNAME;

        }

        public void setQNAME(String qNAME) {

           QNAME = qNAME;

        }

        public String getQNAMEURL() {

           return QNAMEURL;

        }

        public void setQNAMEURL(String qNAMEURL) {

           QNAMEURL = qNAMEURL;

        }

        public String getTODAY() {

           return TODAY;

        }

       

       

        public String getDatabase() {

           return database;

        }

     

        public void setDatabase(String database) {

           this.database = database;

        }

     

        public static void main(String[] args) {

           Calendar calendar = Calendar.getInstance();

           calendar.setTime(new Date());

           System.out.println(calendar.getTime());

           System.out.println(calendar.get(Calendar.MINUTE));

           calendar.set(Calendar.MINUTE,calendar.get(Calendar.MINUTE)+40);

           System.out.println(calendar.getTime());

        }

    }

    1.2客户端引入的jar包

    1. 服务端部分

    2.1 package cn.com.njcb.cacheservice;

    import javax.jws.WebMethod;

    import javax.jws.WebParam;

    import javax.jws.WebResult;

    import javax.jws.WebService;

    import javax.jws.soap.SOAPBinding;

    import cn.com.njcb.cacheservice.message.standardcache.StandardCacheReponse;

    import cn.com.njcb.cacheservice.message.standardcache.StandardCacheRequest;

    /**

     * This class was generated by the JAX-WS RI. JAX-WS RI 2.1.3-hudson-390-

     * Generated source version: 2.0

     *

     */

    @WebService(name = "CacheService", targetNamespace = "http://www.njcb.com.cn/CacheService/")

    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

    public interface CacheService {

    /**

     *

     * @param standardCacheRequest

     * @return returns

     *         cn.com.njcb.cacheservice.message.standardcache.StandardCacheReponse

     */

    @WebMethod

    @WebResult(name = "standardCacheResponse", targetNamespace = "http://www.njcb.com.cn/CacheService/message/", partName = "standardCacheResponse")

    public StandardCacheReponse standardCache(

                        @WebParam(name = "standardCacheRequest", targetNamespace = "http://www.njcb.com.cn/CacheService/message/", partName = "standardCacheRequest") StandardCacheRequest standardCacheRequest);

    }

    2.2 package cn.com.njcb.cacheservice;

    import java.text.SimpleDateFormat;

    import java.util.Calendar;

    import java.util.Date;

    import java.util.GregorianCalendar;

    import cn.com.njcb.cacheservice.message.standardcache.StandardCacheReponse;

    import cn.com.njcb.cacheservice.message.standardcache.StandardCacheRequest;

    import com.xxx.are.ARE;

    import com.xxx.are.log.Log;

    import com.xxx.are.util.StringFunction;

    import com.xxx.awe.util.Transaction;

    import com.xxx.limit.job.SynchronizLimitJob;

    import com.xxx.limit.service.InitLimitServlet;

    import com.xxx.limit.util.LimitUtil;

    @javax.jws.WebService(endpointInterface = "cn.com.njcb.cacheservice.CacheService", targetNamespace = "http://www.njcb.com.cn/CacheService/", serviceName = "CacheService", portName = "CacheServicePort")

    public class CacheServicePortImpl {

    private Log log = ARE.getLog();

    public StandardCacheReponse standardCache(StandardCacheRequest standardCacheRequest){

               this.log.info("重新加载缓存开始:【"+StringFunction.getTodayNow()+"】");

              

               /*创建响应对象。*/

               StandardCacheReponse reponse = new StandardCacheReponse();

                     /*填充响应对象头*/

                     reponse.setSEQNO("LOAD00000001");

                    

                     reponse.setSERVICEID(standardCacheRequest.getSERVICEID());

                       //设置交易日期

                     reponse.setTRANDATE(StringFunction.getTodayNow().substring(0,10));

                     Date d = new Date();

                     SimpleDateFormat dateformat = new SimpleDateFormat("HHmmssSSS");

                     reponse.setTRANTIME(dateformat.format(d));

                     reponse.setTRANSTATUS("");

                     reponse.setERRORMSG("");

                     reponse.setERRORCODE("");

                     Transaction Sqlca = null;

                     String sBizDate = null;

                     String sResult = "";

                    

                     try {

                               SynchronizLimitJob.TODAY = CacheServicePortImpl.getDateToLate(standardCacheRequest.getTRANDATE(),1);

                        LimitUtil.load();

                        reponse.setTRANSTATUS("COMPLETE");

                               reponse.setResult("1");

                               reponse.setReason("");

               } catch (Exception e) {

                        reponse.setTRANSTATUS("FAIL");

                         reponse.setERRORMSG("2");

                         reponse.setERRORCODE("加载缓存失败");

                               reponse.setResult("2");

                               reponse.setReason("加载缓存失败");

                        e.printStackTrace();

               }

              

               System.out.println(SynchronizLimitJob.TODAY);

                    

                     this.log.info("重新加载缓存完成【"+StringFunction.getTodayNow()+"】");

                     return reponse;

    }

    public static String getDateToLate(String sDate ,int i ){

               int year = Integer.parseInt(sDate.substring(0,4));

               int month = Integer.parseInt(sDate.substring(5,7));

               int day = Integer.parseInt(sDate.substring(8,10));

               Calendar calendar = new GregorianCalendar(year,month-1,day,0,0,0);

               calendar.add(Calendar.DAY_OF_MONTH, 1);

               java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy/MM/dd");

               return format.format(calendar.getTime());

    }

    public static void main(String[] args) {

               System.out.println(CacheServicePortImpl.getDateToLate("2011/12/31",1));

    }

    }

    1. Wsdl

    3.1

    3.2

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>

    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"

     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

     xmlns:tns="http://www.njcb.com.cn/CacheService/"

      xmlns:tns1="http://www.njcb.com.cn/CacheService/message/"

     xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"

     xmlns:xsd="http://www.w3.org/2001/XMLSchema"

     name="CreditLimitSOAPService"

     targetNamespace="http://www.njcb.com.cn/CacheService/">

     

     <types>

        <xsd:schema>

          <xsd:import namespace="http://www.njcb.com.cn/CacheService/message/"

                schemaLocation="Cache_message.xsd"/>

        </xsd:schema>

     </types>

     

      <message name="standardCacheRequest">

        <part element="tns1:standardCacheRequest" name="standardCacheRequest"/>

      </message>

      <message name="standardCacheReponse">

        <part element="tns1:standardCacheResponse" name="standardCacheResponse"/>

      </message>

     

        <portType name="CacheService">

            

        <operation name="standardCache">

            <input message="tns:standardCacheRequest"/>

            <output message="tns:standardCacheReponse"/>

        </operation>

        </portType>

        <binding name="CacheServicePortSoap" type="tns:CacheService">

        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

       

        <operation name="standardCache">

                <soap:operation soapAction=""/>

                <input>

                 <soap:body use="literal"/>

                </input>

                <output>

                 <soap:body use="literal"/>

                </output>

        </operation>

       

        </binding>

        <service name="CacheService">

        <port binding="tns:CacheServicePortSoap" name="CacheServicePort">

          <soap:address location="http://localhost:8080/standard/CacheService"/>

        </port>

      </service>

    </definitions>

  • 相关阅读:
    【Java基础】List迭代并修改时出现的ConcurrentModificationException问题
    【Java基础】Integer包装类的缓冲池问题
    【Java基础】基本类型的包装类作为参数传递是值传递还是引用传递
    【Java基础】关于String的总结
    Mac IDEA快捷键积累
    POJ1273 Drainage Ditches
    BZOJ2763 飞行路线
    NOIP2018 货币系统
    BZOJ2748 音量调节
    BZOJ1721 Ski Lift 缆车支柱
  • 原文地址:https://www.cnblogs.com/songtianbao/p/6362194.html
Copyright © 2011-2022 走看看