又到了每个月博客的时间了,转眼间已是过了年回来上班了,给你们拜个年,祝你们新的一年工做顺利,身体健康!java
同时,也深切地感觉到时光荏苒,回首去年发生的一幕幕,仿佛就在昨日。web
最近一月的博客内容主要写两个方面:1)与同事交流技术的一点心得;2)基于wsdl的自顶向下webservice开发学习。sql
1)与同事的几点技术交流数据库
中间件,中间件是提供了一系列服务的软件,简化人们实施工程的复杂性,如weblogic。tomcat功能太过简单,就不能称之为中间件,只能叫轻量级的web容器。缓存
jndi,咱们常常会在weblogic中看到jdbc的jndi名称,其实是用jndi规范实现的jdbc数据源域名查找方法。tomcat
jdbc,jdbc是一种思想,它定义了一组规范,具体地实现由各个数据库厂商自行完成,并提供相应的jar包,Java语言的流行性使得各个数据库厂商有充足的动力去实现基于jdbc的数据库驱动,咱们使用java语言链接数据库时,都要首先加载相应的数据库驱动。ide
在这里尤为要学会规范、思想的概念,这并非什么高深的东西,关键是要理解清楚它为何存在,归结起来,java的诸多技术均可以称为思想,从大的方面讲,java的面向对象也是一种思想。学习
2)基于wsdl的自顶向下webservice开发this
必需要读懂wsdl,本身会编写wsdl。url
wsdl一开始通常会定义一组包名,接下来是element部分,该部分能够引用其它的xsd(xsd又能够引用其它的xsd);
message是java服务实现类操做的输入输入参数,它由一个或多个element拼接而成;
porttype是java web服务后台真正的实现类,它的方法是operation,输入输出参数对应message中的元素;
binding将port操做绑定为soap消息;
service的名字对应服务名,它的binding元素对应binding,名字任意,无特殊做用。
同时阅读了一段具体的实例,来源于平常管理的系统的一个服务,以下:
1.1客户端实现类
package com.amarsoft.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.amarsoft.are.ARE;
import com.amarsoft.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包
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.amarsoft.are.ARE;
import com.amarsoft.are.log.Log;
import com.amarsoft.are.util.StringFunction;
import com.amarsoft.awe.util.Transaction;
import com.amarsoft.limit.job.SynchronizLimitJob;
import com.amarsoft.limit.service.InitLimitServlet;
import com.amarsoft.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));
}
}
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>