<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

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

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

    <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是提供的服務名,urn:service是URI。再寫一個腳本來調用配置文件部署服務

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

    啟動Tomcat之后,啟動腳本,然后執行Client代碼就可以了,Client的主體代碼很簡單,代碼里面就不加入注釋了。
    ??
    ??? 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 小小涼粉 閱讀(369) | 評論 (0)編輯 收藏

    昨天寫完程序并部署Service之后,一直都在拋出接口不匹配的異常,于是我就寫了個簡單的接口,只傳入一個String類型的參數,結果運行正常。然后我又寫了個只傳入Integer類型參數的接口,果不出所料,又發生了接口不匹配的異常。接下來我就開始改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));
    結果統統失敗,弄的我都要抓狂了。

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

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

    <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,運行Client,一切OK
    不知道是不是因為機器的問題,在公司的思路遠遠不如在宿舍啊

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



    把這個文件放到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里面,啟動Tomcat之后,到webapps/axis/WEB-INF目錄下運行:
    java org.apache.axis.client.AdminClient deploy.wsdd
    之后可以訪問
    http://localhost:8080/axis/
    來查看剛才部署的service對應的wsdl了

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

    在web環境下,Quartz可以通過配置文件來完成后臺的作業調度,不必手工創建Trigger和Scheduler,其步驟如下:

    首先將quartz.jar,以及lib目錄下面core和optional兩個目錄中的所有jar全都放入項目WEB-INF\lib目錄下

    job就是一個簡單的java類,這里的功能就是輸出當前的時間了。

    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文件,這個文件的默認名稱就是quartz.properties,如果啟動項目的時候,Quartz沒有在工程中找到該文件,就會從自己的jar包下面讀取其默認的properties文件,其內容如下:

    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都作了完整的定義,并組合成一個job。下面,我們把上面兩個文件都放入/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>

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

    現在就大功告成了
    一個Job類,一個quartz.properties文件,一個quertz_job.xml文件,還有修改一下web.xml文件,很簡單呀!

    不過看起來簡單,解決的過程卻很郁悶,單單是考慮如何在后臺進程中運行Servlet就花了好長時間,后來查資料以后才知道可以用Listener或者是啟動時運行的Servlet來完成,看來自己的底子還是不扎實的.

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

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

    在驗證用戶登錄的時候,各個類調用的順序如下所示:

    authenticationProcessionFilter(AuthenticationProcessingFilter)---->

    authenticationManager(ProviderManger)---->

    daoAuthenticationProvider(DaoAuthenticationProvider)---->

    userDetailsService(UserDetailsService)

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

    另外,在UserDetail這個類里面,有一個GrantedAuthority[] 類型的屬性,用來存放該用戶所對應的權限,我們在loadUserByUsername這個方法里面,同樣也需要得到該用戶的權限,并把它賦給返回的UserDetails。

    假如用戶對應的類名為UserInfo,權限對應的類名為Roles,在UserInfo中有一個變量

    private Set roles;

    在得到權限信息的時候,因為它是集合,所以可以使用延遲加載功能,讀取的時候先從緩存中取數據,如果取不到的話,就調用UserInfo.getRoles()方法,這個時候就會到數據庫中取數據了,取到以后,再把數據放到緩存中。

    posted @ 2006-09-18 15:04 小小涼粉 閱讀(280) | 評論 (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 需要定位另一個應用程序或者是網絡上的某一段業務邏輯, client 通過 name catagory identifier 或者 specification 來從 UDDI registry 中查詢服務,定位以后, client UDDI registry 中得到 WSDL 文檔的位置信息。在 WSDL 文檔的 XML schema 中包含了如何訪問 web service 和請求信息的格式, client 按照 xml schema 的格式來創建一個 soap 消息,并向 host 發送請求。

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

    用一個類來存放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;
    ? } ?
    }

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

    posted @ 2006-09-18 14:57 小小涼粉 閱讀(868) | 評論 (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 小小涼粉 閱讀(183) | 評論 (0)編輯 收藏

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

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

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

    僅列出標題
    共3頁: 上一頁 1 2 3 
    主站蜘蛛池模板: 亚洲日产2021三区| 亚洲精品成人区在线观看| 亚洲精品福利视频| 在线免费观看伊人三级电影| 亚洲成A人片77777国产| 国产一区二区三区亚洲综合| 国产一级理论免费版| 久久精品国产亚洲av瑜伽| 一区国严二区亚洲三区| 免费人成再在线观看网站| 亚洲午夜激情视频| 免费无码又爽又刺激一高潮| 亚洲AV无码国产精品色午友在线 | 国产1000部成人免费视频| 亚洲成人免费网站| 国产成人A在线观看视频免费| 亚洲AV无码片一区二区三区 | 亚洲视频免费在线看| 亚洲免费观看在线视频| 日韩免费高清视频| 免费国产污网站在线观看不要卡| 亚洲精品97久久中文字幕无码| 中文字幕不卡高清免费| 亚洲综合无码一区二区| 国产免费av片在线看| 羞羞视频网站免费入口| 亚洲AV无码一区二区三区系列| 7m凹凸精品分类大全免费| 亚洲精品无码久久久久秋霞| 亚洲欧洲精品成人久久奇米网| 久久免费观看国产精品| 亚洲午夜精品久久久久久app| 亚洲午夜精品第一区二区8050| 免费无码又爽又刺激高潮视频| 精品亚洲AV无码一区二区三区| 亚洲AⅤ优女AV综合久久久| 男女作爱在线播放免费网站| 亚洲天然素人无码专区| 亚洲永久精品ww47| 免费高清小黄站在线观看| 中文字幕免费观看全部电影|