posts - 28, comments - 27, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          首先下載soap,把soap.war放到tomcat/webapp/目錄下,在classpath下面加入soap.jar、mail.jar和 activation.jar,然后創(chuàng)建一個(gè)Service和Client,把Service.class放到 tomcat/webapp/soap/WEB-INF/classes目錄下,然后把mail.jar和activation.jar放到 tomcat/webapp/soap/WEB-INF/lib下面,并寫一個(gè)配置文件用于部署服務(wù)。

          <isd:service
          ?? xmlns:isd="http://xml.apache.org/xml-soap/deployment"
          ?? id="urn:service" checkMustUnderstands="true">
          ????? <isd:provider type="java" scope="Request" methods="setAlarm">
          ????? <isd:java class="work.Service" static="false"/>
          ?? </isd:provider>
          </isd:service>


          上面的work.Service是類的全名,setAlarm是提供的服務(wù)名,urn:service是URI。再寫一個(gè)腳本來調(diào)用配置文件部署服務(wù)

          java org.apache.soap.server.ServiceManagerClient
          http://localhost:8080/soap/servlet/rpcrouter deploy deploy.xml

          啟動(dòng)Tomcat之后,啟動(dòng)腳本,然后執(zhí)行Client代碼就可以了,Client的主體代碼很簡(jiǎn)單,代碼里面就不加入注釋了。
          ??
          ??? Call call = new Call ();
          ??? call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
          ??? call.setTargetObjectURI ("urn:service");
          ??? call.setMethodName ("setAlarm");
          ??? Parameter param = new Parameter("alarm", String.class, alarm, Constants.NS_URI_SOAP_ENC);
          ??? Vector paramList = new Vector();
          ??? paramList.addElement(param);
          ??? call.setParams (paramList);
          ??? URL url = new URL ("http://localhost:8080/soap/servlet/rpcrouter");
          ??? Response resp = call.invoke (url, "");
          ??? if (!resp.generatedFault()) {
          ????? // Extract Return value
          ????? Parameter result = resp.getReturnValue ();
          ????? String greeting = (String) result.getValue();
          ????? return greeting;
          ??? }
          ??? else {
          ????? //? Extract Fault Code and String
          ????? Fault f = resp.getFault();
          ????? String faultCode = f.getFaultCode();
          ????? String faultString = f.getFaultString();
          ????? System.err.println("Fault Occurred (details follow):");
          ????? System.err.println("Fault Code:? "+faultCode);
          ????? System.err.println("Fault String:? "+faultString);
          ????? return new String ("Fault Occurred.? No greeting for you!");
          ??? }

          posted @ 2006-09-18 15:06 小小涼粉 閱讀(370) | 評(píng)論 (0)編輯 收藏

          昨天寫完程序并部署Service之后,一直都在拋出接口不匹配的異常,于是我就寫了個(gè)簡(jiǎn)單的接口,只傳入一個(gè)String類型的參數(shù),結(jié)果運(yùn)行正常。然后我又寫了個(gè)只傳入Integer類型參數(shù)的接口,果不出所料,又發(fā)生了接口不匹配的異常。接下來我就開始改Client端代碼:

          params.addElement(new Parameter("eventStatus",Integer.class, new Integer(1), null));
          params.addElement(new Parameter("eventStatus",int.class, new Integer(1), null));
          params.addElement(new Parameter("eventStatus",int.class, 1, null));
          params.addElement(new Parameter("eventStatus",Intege.class, 1, null));
          結(jié)果統(tǒng)統(tǒng)失敗,弄的我都要抓狂了。

          今天到了公司以后,跟組長(zhǎng)說了這件事情,組長(zhǎng)說讓我換用AXIS試試看,我到ws.apache.org/axis上面看了看文檔,在user guide里面給出的例子和我的代碼差別很大,我就只好按著它的例子重新改代碼

          寫完以后,配環(huán)境變量配的快要抓狂……部署的時(shí)候又是一頭霧水……最后始終沒有成功……最后回到宿舍才想到,AXIS和Apache SOAP Server不過都是服務(wù)器而已,不應(yīng)該存在規(guī)范上的區(qū)別,也就是不應(yīng)該會(huì)影響到客戶端的程序,于是我就按照最開始的代碼,把Service部署好,啟動(dòng) Tomcat,從WSDL中找到對(duì)應(yīng)的信息

          <wsdl:service name="ServiceService">
          ?<wsdl:port binding="impl:serviceSoapBinding" name="service">
          ? <wsdlsoap:address location="http://localhost:8080/axis/services/service" />
          ?</wsdl:port>
          </wsdl:service>

          在xml配置文件中,把location賦值給URL,把name賦值給TargetObjectURI,運(yùn)行Client,一切OK
          不知道是不是因?yàn)闄C(jī)器的問題,在公司的思路遠(yuǎn)遠(yuǎn)不如在宿舍啊

          不過今天至少讓我很熟練的掌握了如何手工部署AXIS服務(wù),創(chuàng)建一個(gè)wsdd文件,我把它命名為deploy.wsdd



          把這個(gè)文件放到Tomcat/webapps/axis/WEB-INF/目錄下,把service的類放到WEB-INF/classes/目錄下,把 axis.jar;jaxrpc.jar;commons-logging-1.0.4.jar;commons-discovery-0.2.jar;saaj.jar 放到classpath里面,啟動(dòng)Tomcat之后,到webapps/axis/WEB-INF目錄下運(yùn)行:
          java org.apache.axis.client.AdminClient deploy.wsdd
          之后可以訪問
          http://localhost:8080/axis/
          來查看剛才部署的service對(duì)應(yīng)的wsdl了

          posted @ 2006-09-18 15:05 小小涼粉 閱讀(455) | 評(píng)論 (0)編輯 收藏

          在web環(huán)境下,Quartz可以通過配置文件來完成后臺(tái)的作業(yè)調(diào)度,不必手工創(chuàng)建Trigger和Scheduler,其步驟如下:

          首先將quartz.jar,以及l(fā)ib目錄下面core和optional兩個(gè)目錄中的所有jar全都放入項(xiàng)目WEB-INF\lib目錄下

          job就是一個(gè)簡(jiǎn)單的java類,這里的功能就是輸出當(dāng)前的時(shí)間了。

          import java.util.Date;

          import org.apache.commons.logging.Log;
          import org.apache.commons.logging.LogFactory;
          import org.quartz.Job;
          import org.quartz.JobExecutionContext;
          import org.quartz.JobExecutionException;

          public class Helloworld implements Job{
          ?public Helloworld() {
          ?}

          ?private static Log _log = LogFactory
          ???.getLog(Helloworld.class);

          ?public void execute(JobExecutionContext context)
          ???throws JobExecutionException {
          ??_log.info("Hello World! - " + new Date());
          ?}
          }

          然后編寫quartz.properties文件,這個(gè)文件的默認(rèn)名稱就是quartz.properties,如果啟動(dòng)項(xiàng)目的時(shí)候,Quartz沒有在工程中找到該文件,就會(huì)從自己的jar包下面讀取其默認(rèn)的properties文件,其內(nèi)容如下:

          org.quartz.scheduler.instanceName = TestScheduler
          org.quartz.scheduler.instanceId = one

          org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
          org.quartz.threadPool.threadCount =? 2
          org.quartz.threadPool.threadPriority = 4

          org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin
          org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy}
          org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9}

          org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
          org.quartz.plugin.jobInitializer.fileName = quartz_job.xml
          org.quartz.plugin.jobInitializer.overWriteExistingJobs = false
          org.quartz.plugin.jobInitializer.failOnFileNotFound = true
          org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
          org.quartz.plugin.shutdownhook.cleanShutdown = true

          上面的

          org.quartz.plugin.jobInitializer.fileName = quartz_job.xml

          是用來配置定義job文件的名稱。

          然后編寫quartz_job.xml,

          <?xml version="1.0" encoding="UTF-8"?>
          <quartz>
          ? <job>
          ??? <job-detail>
          ????? <name>helloworld</name>
          ????? <group>group1</group>
          ????? <job-class>Helloworld</job-class>
          ??? </job-detail>
          ??? <trigger>
          ????? <cron>
          ??????? <name>test</name>
          ??????? <group>group1</group>
          ??????? <job-name>helloworld</job-name>
          ??????? <job-group>group1</job-group>
          ??????? <cron-expression>0 0/1 * * * ?</cron-expression>
          ???? </cron>
          ??? </trigger>
          ? </job>
          </quartz>

          可以看到,在配置文件中把jobdetail和trigger都作了完整的定義,并組合成一個(gè)job。下面,我們把上面兩個(gè)文件都放入/WEB-INF/classes目錄下,然后按照api中的說明修改一下web.xml。

          ???? <servlet>
          ???????? <servlet-name>
          ???????????? QuartzInitializer
          ???????? </servlet-name>
          ???????? <display-name>
          ???????????? Quartz Initializer Servlet
          ???????? </display-name>
          ???????? <servlet-class>
          ???????????? org.quartz.ee.servlet.QuartzInitializerServlet
          ???????? </servlet-class>
          ???????? <load-on-startup>1</load-on-startup>
          ???????? <init-param>
          ???????????? <param-name>config-file</param-name>
          ???????????? <param-value>/quartz.properties</param-value>
          ???????? </init-param>
          ???????? <init-param>
          ???????????? <param-name>shutdown-on-unload</param-name>
          ???????????? <param-value>true</param-value>
          ???????? </init-param>
          ???? </servlet>

          這樣,在啟動(dòng)Tomcat的時(shí)候,QuartzInitializerServlet這個(gè)Servlet就會(huì)自動(dòng)讀取quartz.properties這個(gè)配置文件,并初始化調(diào)度信息,啟動(dòng)Scheduler。
          我在這里用的是Quartz1.5.0,在1.5.1中新增加了QuartzInitializerListener,但是似乎有些問題,始終啟動(dòng)不起來,而且更過分的是,它的api居然寫錯(cuò)了,在<listener-class>這個(gè)標(biāo)記中,用了 QuartzInitializerServletListener,就算把機(jī)器砸了,它也找不到這個(gè)類啊!

          現(xiàn)在就大功告成了
          一個(gè)Job類,一個(gè)quartz.properties文件,一個(gè)quertz_job.xml文件,還有修改一下web.xml文件,很簡(jiǎn)單呀!

          不過看起來簡(jiǎn)單,解決的過程卻很郁悶,單單是考慮如何在后臺(tái)進(jìn)程中運(yùn)行Servlet就花了好長(zhǎng)時(shí)間,后來查資料以后才知道可以用Listener或者是啟動(dòng)時(shí)運(yùn)行的Servlet來完成,看來自己的底子還是不扎實(shí)的.

          另外就是在Tomcat出現(xiàn)問題的時(shí)候,居然忘了到logs下面去看日志,這個(gè)疏忽是不可原諒的!以后要牢牢記住!

          posted @ 2006-09-18 15:05 小小涼粉 閱讀(1143) | 評(píng)論 (0)編輯 收藏

          在驗(yàn)證用戶登錄的時(shí)候,各個(gè)類調(diào)用的順序如下所示:

          authenticationProcessionFilter(AuthenticationProcessingFilter)---->

          authenticationManager(ProviderManger)---->

          daoAuthenticationProvider(DaoAuthenticationProvider)---->

          userDetailsService(UserDetailsService)

          在最底層的UserDetailsService接口中,提供了loadUserByUsername這個(gè)方法,我們只需要實(shí)現(xiàn)這個(gè)接口,并實(shí)現(xiàn)接口中的方法,就可以使用自己的驗(yàn)證功能了。該方法傳入的參數(shù)是String username,返回類型是UserDetails,很顯然,我們需要通過自己的dao,根據(jù)username來得到自定義的user類型,然后把它封裝到UserDetails里面去,然后返回。

          另外,在UserDetail這個(gè)類里面,有一個(gè)GrantedAuthority[] 類型的屬性,用來存放該用戶所對(duì)應(yīng)的權(quán)限,我們?cè)趌oadUserByUsername這個(gè)方法里面,同樣也需要得到該用戶的權(quán)限,并把它賦給返回的UserDetails。

          假如用戶對(duì)應(yīng)的類名為UserInfo,權(quán)限對(duì)應(yīng)的類名為Roles,在UserInfo中有一個(gè)變量

          private Set roles;

          在得到權(quán)限信息的時(shí)候,因?yàn)樗羌希钥梢允褂醚舆t加載功能,讀取的時(shí)候先從緩存中取數(shù)據(jù),如果取不到的話,就調(diào)用UserInfo.getRoles()方法,這個(gè)時(shí)候就會(huì)到數(shù)據(jù)庫(kù)中取數(shù)據(jù)了,取到以后,再把數(shù)據(jù)放到緩存中。

          posted @ 2006-09-18 15:04 小小涼粉 閱讀(281) | 評(píng)論 (0)編輯 收藏

          1. SOAP--Simple Object Access Protocal

          SOAP is a lightweight protocol intented to exchanging structured information in a decentralized, distributed environment.The two major goals for SOAP is simplicity and extensibility.

          SOAP is widely used for XML messaging as it :

          ??? defines thin layer on top of widely understood HTTP?
          ??? is flexible and extensible?
          ??? enjoys broad industry and developer community support

          Main uses of SOAP are for

          ??? messaging: sending XML data orders, invoices, forms?
          ??? RPC: invoking services querying data sources, transacting

          2. WSDL--Web Service Definition Language

          As?the communication protocols and message formats are standardized?in the web community, it becomes increasingly possible and important to be able to?describe the communication s in some structured way.WSDL addresses this need by defining an XML grammar for describing network services as collections of communication endpoints capable of exchanging messages.

          3. ?UDDI--?Universal Description, Discovery, and Integration

          UDDI protocol is a central element of the group of related standards that comprise the Web services stack. The specification defines a standard method for publishing and discovering the network-based software components of a service-oriented architecture.

          4.? the relationship between SOAP,WSDL and UDDI

          web service client 需要定位另一個(gè)應(yīng)用程序或者是網(wǎng)絡(luò)上的某一段業(yè)務(wù)邏輯, client 通過 name catagory identifier 或者 specification 來從 UDDI registry 中查詢服務(wù),定位以后, client UDDI registry 中得到 WSDL 文檔的位置信息。在 WSDL 文檔的 XML schema 中包含了如何訪問 web service 和請(qǐng)求信息的格式, client 按照 xml schema 的格式來創(chuàng)建一個(gè) soap 消息,并向 host 發(fā)送請(qǐng)求。

          posted @ 2006-09-18 15:03 小小涼粉 閱讀(299) | 評(píng)論 (0)編輯 收藏

          用一個(gè)類來存放applicationContext:
          public class ContextHolder {
          ? private final static ContextHolder instance = new ContextHolder();
          ? private ApplicationContext ac;
          ? private ContextHolder() {
          ? }
          ? public static ContextHolder getInstance() {
          ??? return instance;
          ? }
          ? public synchronized void setApplicationContext(ApplicationContext ac) {
          ??? this.ac = ac;
          ? }
          ? public ApplicationContext getApplicationContext() {
          ??? return ac;
          ? } ?
          }

          然后寫一個(gè)servlet,繼承自org.springframework.web.context.ContextLoaderServlet,并配置web.xml,讓它在tomcat啟動(dòng)時(shí)自動(dòng)運(yùn)行。然后在它的init方法中,加入如下的代碼:
          WebApplicationContext context = WebApplicationContextUtils.
          ??? getWebApplicationContext(this.getServletContext());
          ContextHolder.getInstance().setApplicationContext(context);

          posted @ 2006-09-18 14:57 小小涼粉 閱讀(868) | 評(píng)論 (0)編輯 收藏

          Can you foresee everything? No. Are the decisions you make today final? No. It's practically impossible to think everything or know everything in the beginning of a project. You will learn more as a project goes on. However, you can use your experience or experiences of others to guide you in a certain direction. You can make decisions that might minimize changes tomorrow.

          posted @ 2006-09-18 14:54 小小涼粉 閱讀(184) | 評(píng)論 (0)編輯 收藏

          EventHandler要抽象出一個(gè)接口來,然后根據(jù)不同的需要實(shí)現(xiàn)不同的handler,不然就無法在服務(wù)器reply以后通知UI更新,但至于是否要在UI中再生成異步線程來做這件事情,還要通過編碼測(cè)試一下。

          不過目前我的感覺是不需要再生成異步線程了,因?yàn)榈讓覲eercore的操作本身就是異步的,不需要等待它的方法操作完畢以后再返回,應(yīng)該只需要把UI中要更新的控件作為參數(shù)傳到EventHandler里面去,這樣handler就可以通知UI更新了——打住!RCP非UI的線程是無法操作UI線程的!!只能通過UIJob或者是Display.asnyexec()方法來更新UI,所以....還是要定義很多的UIJob的子類的......

          posted @ 2006-09-18 14:54 小小涼粉 閱讀(318) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共3頁: 上一頁 1 2 3 
          主站蜘蛛池模板: 留坝县| 读书| 遂平县| 会理县| 宜兴市| 永城市| 五华县| 乐都县| 边坝县| 临颍县| 加查县| 龙岩市| 黄山市| 金秀| 灵山县| 金山区| 长子县| 中西区| 南昌县| 松原市| 吉隆县| 慈溪市| 汉中市| 高淳县| 建始县| 收藏| 上虞市| 万山特区| 大英县| 洛南县| 手机| 秀山| 涿州市| 清水河县| 宁化县| 平江县| 莱芜市| 灵宝市| 东乌珠穆沁旗| 阿拉善盟| 嘉定区|