又到了每個月博客的時間了,轉眼間已是過了年回來上班了,給你們拜個年,祝你們新的一年工做順利,身體健康!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>