爪哇哇

          一個軟件分析師的博客

          2007年4月10日 #

          XFIRE的一個例子,發現左web service真是簡單得要命!! 側面印證了寫代碼越來越沒前途了,哈

          接口 interface
          import J2EE技術的爬蟲.util.Collection;
          import J2EE技術的爬蟲.util.List;

          public interface IMathService {
           /**
            * 加
            * @param a
            * @param b
            * @return
            */
           public int add(int a,int b);
           /**
            * 減
            * @param a
            * @param b
            * @return
            */
           public int sub(int a,int b);
          /**
          上傳二進制文件
          */
            public String sendFile(String fileName,byte[] file );
           
          }

          實現 implements

          import J2EE技術的爬蟲.io.File;
          import J2EE技術的爬蟲.io.FileOutputStream;
          import J2EE技術的爬蟲.sql.Connection;
          import J2EE技術的爬蟲.sql.ResultSet;
          import J2EE技術的爬蟲.sql.Statement;
          import J2EE技術的爬蟲.util.ArrayList;
          import J2EE技術的爬蟲.util.Collection;
          import J2EE技術的爬蟲.util.List;

          import com.newsoft.oa.bean.User;
          import com.newsoft.oa.uitl.Connector;
          import com.thoughtworks.xstream.XStream;

          public class MathServiceImpl implements IMathService{
            public int add(int a,int b){
             return a+b;
            }
           
            public int sub(int a,int b){
             return a-b;
            }
            public String getWelComeStr(String name){
             return "hi "+name+"! 歡迎你";
            }
            public List getUsers(){
             List l=new ArrayList();
             l.add("name");
             l.add("password");
             l.add("sex");
             return l;
            }

          public String sendFile(String fileName, byte[] filebytes) {
           try{
            String path="";
             if(filebytes!=null&&filebytes.length>0){
              File file=new File("/"+fileName);
             
              file.createNewFile();
              FileOutputStream fos=new FileOutputStream(file);
              fos.write(filebytes);
              fos.close();
              path=file.getAbsolutePath();
              System.out.println(path);
             
              file=null;
             
             }
            
             return path;
           }catch(Exception ex){
            return "false";
           }
          }

          }

          配置文件

          放在 Classes/META-INF/xfire/service.xml;里面

          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://xfire.codehaus.org/config/1.0">
           <service>
            <name>MathService</name>
            <namespace>newsoft/oa/MathService</namespace>
            <serviceClass>
             com.newsoft.oa.services.IMathService
            </serviceClass>
            <implementationClass>
             com.newsoft.oa.services.MathServiceImpl
            </implementationClass>

           </service>
          </beans>

          其實是借鑒了Spring的寫法,用過Spring不會對著陌生,(Application-context.xml)

          WEB-XML加上

          <servlet>
            <servlet-name>XFireServlet</servlet-name>
            <servlet-class>
             org.codehaus.xfire.transport.http.XFireConfigurableServlet
            </servlet-class>
           </servlet>

           <servlet-mapping>
            <servlet-name>XFireServlet</servlet-name>
            <url-pattern>/servlet/XFireServlet/*</url-pattern>
           </servlet-mapping>

           <servlet-mapping>
            <servlet-name>XFireServlet</servlet-name>
            <url-pattern>/services/*</url-pattern>
           </servlet-mapping>


          最后就是客戶端了

          / /Create a metadata of the service             
           Service serviceModel = new ObjectServiceFactory().create(IMathService.class);
          // Create a proxy for the deployed service     
           
           XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());  
           String serviceUrl = "http://localhost:8080/ws/services/MathService";
            client = null;      
           try {         
             client = (IMathService) factory.create(serviceModel, serviceUrl); 
             File file=new File("c:\\SUPERMAP 白皮書.pdf");
             FileInputStream fis=new FileInputStream(file);
             byte[] b=new byte[fis.available()];
             fis.read(b);
            System.out.println(client.sendFile(file.getName(), b));
           } catch (Exception ex) {        
             ex.printStackTrace();
           }                           //Invoke the service   
           int serviceResponse = 0;
           int a=10,b=20;

          就是

          Service serviceModel = new ObjectServiceFactory().create(IMathService.class); 
           XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());  
           String serviceUrl = http://localhost:8080/ws/services/MathService;

          三行字建立連接請求,

          太輕松了

          傳輸文件速度也可以,二進制,2M多的文件,也能輕松傳遞

          用.net和delphi平臺測試,兼容性沒問題(按道理 soap,也不應該有問題)

          這是為客戶搭建的在 檔案系統和OA審批間作文件歸檔的嘗試項目

          哈,完整的項目代碼,就不方便講了。

          posted @ 2007-12-29 14:59 李立波 閱讀(2510) | 評論 (2)編輯 收藏

          關于 DOMINO LS里面 view的Ftsearch的 "entry is no longer in view"的研究

          1:
          原因主要是 數據的不唯一性

          domino文檔數據庫的弊病

          而且 FTSearch查詢起來也不很準確,三字符一下查詢,命中率不是十分高,大約 80%-95%

          2:
          entry is no longer in view錯誤的避免方法是

          用NotesViewEntry.IsValid方法先判斷那 Entry是否能調用

          如果不是調用里面很多方法 都會報  entry is no longer in view,就算 IsDocument也沒用處

          但這樣,如果是自己手動分頁,就會出現 GetNthEntry時候不太準確

          但沒辦法了,兩者弊,取其輕

          主要是客戶體驗受點影響了

          posted @ 2007-12-29 14:40 李立波 閱讀(1574) | 評論 (0)編輯 收藏

          近期負責公司的OA改造,接觸了ext-js框架,自己動手寫了些代碼,最有成就感的是 extnd里分頁的修改,一下是部分修改心得

          一:

          分頁要自己重寫:在 extnd-all-debug重寫拿取數據部分

          //自己重寫分頁拿數據的方法,這樣數據行數會正確現實
            var ds = new Ext.nd.data.DominoViewStore({
                    proxy: new Ext.data.HttpProxy({
                        url: Ext.nd.extndUrl+'GetView?OpenAgent',
                        method: "GET"
                    }),
                    baseParams: {db: "/"+Ext.nd.Session.CurrentDatabase.FilePath, vw: this.viewName },
                    reader: viewEntryReader,
                    remoteSort: true
                });

          。。。。。。。。。。。。。。。

          getView的ls代理如下

          'GetView:

          Option Public
          Option Explicit


          Sub Initialize
          %REM
          This agent can be called from the web to search any view and return results in the
          same format as the ?ReadViewEntries command. This was created for use with the
          NotesView2 class v1.3 and above.
          %END REM
           
           On Error Goto ErrorHandler
           
           Dim session As New NotesSession
           Dim dbSearch As NotesDatabase
           Dim colEntries As NotesViewEntryCollection
           Dim vwSearch As NotesView
           Dim entryResult As NotesViewEntry
           Dim docCurrent As NotesDocument
           Dim docResult As NotesDocument
           Dim col As NotesViewColumn
           Dim strQuery As String
           Dim strDb As String
           Dim strView As String
           Dim strCategory As String
           Dim intMax As Integer
           Dim lngCount As Long, i As Long
           Dim lngStart As Long, lngEnd As Long
           Dim strParameters As String
           Dim lngResults As Long
           Dim x,n As Integer
           Dim xmlStr,resortdescending ,resortascending As String
           Dim nav As NotesViewNavigator
           
           
           'start the xml document
           Print "Content-Type:text/xml;"
           Print "<?xml version=""1.0"" encoding=""gb2312""?>"
           
           'first we get the search parameters out of the querystring
           'db, vw, query, searchmax, count, and start
           Set docCurrent = session.DocumentContext
           
           strParameters = docCurrent.GetItemValue("Query_String")(0)
           'Msgbox strParameters
           strDb = GetParameter("db",strParameters)
           strDb = Replace(Strright(strDb,"/"),"/","\")
           strView = GetParameter("vw",strParameters)
           strQuery = GetParameter("query",strParameters)
           strCategory= GetParameter("RestrictToCategory",strParameters)
           resortdescending=GetParameter("resortdescending",strParameters)
           resortascending=GetParameter("resortascending",strParameters)
           
           intMax = 0
           If Isnumeric(GetParameter("searchmax",strParameters)) Then intMax = Cint(GetParameter("searchmax",strParameters))
           lngCount = 20
           If Isnumeric(GetParameter("count",strParameters)) Then lngCount = Clng(GetParameter("count",strParameters))
           lngStart = 1
           If Isnumeric(GetParameter("start",strParameters)) Then lngStart = Clng(GetParameter("start",strParameters))
           
           'now we get the view to search
           Set dbSearch = session.GetDatabase("",strDb,False)
           Set vwSearch = dbSearch.GetView(strView)
           
           'Msgbox resortdescending +" && "+resortascending
           
           'now we run the search
           If   strCategory="" Then
            
            Set colEntries = vwSearch.AllEntries 
           Else
            Set colEntries = vwSearch.GetAllEntriesByKey(strCategory)
           End If 
           
           lngResults=colEntries.Count
           
           
           'now we spit out the results
           Print "<viewentries toplevelentries=""" & Cstr(lngResults) & """>"
           
           
           'set the starting point for the loop
           If lngStart > lngResults Then lngStart = lngResults
           
           'set the ending point for the loop
           lngEnd = lngStart + lngCount - 1
           If lngEnd > lngResults Then lngEnd = lngResults
           'now loop through the appropriate subset of results and print out a viewentry tag for each one
           i = lngStart
           While i <= lngEnd
            
            If i = lngStart Then
             Set entryResult = colEntries.GetNthEntry(i) 
            Else
             Set entryResult = colEntries.GetNextEntry(entryResult)
            End If
            
            
            If Not entryResult Is Nothing   Then
            'If Not entryResult Is Nothing And entryResult.IsValid  Then
             'If entryResult.IsDocument Then
             Set docResult = entryResult.Document
             Print  "<viewentry position=""" & Cstr(i) & """ unid=""" & Cstr(docResult.universalID) & """ noteid=""" & Cstr(docResult.NoteID) & """ siblings=""" & Cstr(entryResult.SiblingCount) & """>"
             x = 0
             n=0
             Forall value In entryResult.ColumnValues
              Set col=vwSearch.Columns(x)
              
              If Not col.isCategory And  Not col.IsHidden  Then
               Print "<entrydata columnnumber=""" & Cstr(n) & """ name=""" & col.itemName & """>"
               Print  "<text>" & XMLEscape(GetValue(value,Cstr(docResult.universalID))) & "</text>"
               Print  "</entrydata>"
               n=n+1
              End If
              x = x + 1
             End Forall
             Print "</viewentry>"
             'End If
            End If
            i = i + 1
           Wend
          AtEnd:
           Print "</viewentries>"
           
           ''''Msgbox xmlStr
           Print xmlStr
           vwSearch.Clear
           Set dbSearch=Nothing
           Set vwSearch=Nothing
           Exit Sub
          ErrorHandler:
           Msgbox "<error>" & "Error in ($Ext.nd.SearchView): " & Error & "---at " & Erl & "</error>"
           Print "<error>" & "Error in ($Ext.nd.SearchView): " & Error & "---at " & Erl & "</error>"
           Resume AtEnd
          End Sub
          Function GetParameter(strParamName As String, strQuery As String) As String
           'this gets a parameter out of a querystring
           Dim i As Integer
           Dim s As String
           Dim v As Variant
           
           GetParameter = ""
           
           i = Instr(Ucase(strQuery),"&" & Ucase(strParamName) & "=")
           If i <> 0 Then
            s = Strright(Mid(strQuery, i),"=")
            If Instr(s, "&") Then
             s = Strleft(s, "&")
            End If
            v = Evaluate("@UrlDecode(""Domino""; """ & s & """)")
            GetParameter = Cstr(v(0))
           End If
          End Function
          Function XMLEscape(strValue As String) As String
           'this escapes a string so it can be printed out to xml safely
           strValue = Replace(strValue, "&" , "&amp;")
           strValue = Replace(strValue, "<" , "&lt;")
           strValue = Replace(strValue, ">" , "&gt;")
           XMLEscape = strValue
          End Function


          Function GetValue(strValue As Variant,id As String) As String
           On Error Goto sErr
           
           'Forall vs In strValue
           ' Msgbox "vs=" &  Cstr(vs)
           'End Forall
           GetValue=Cstr(strValue)
           Exit Function
          sErr:
           GetValue="文檔" & id
           Exit Function
          End Function

           

          有興趣可以研究下 ext-js的AJAX框架,確實很有趣

          posted @ 2007-12-29 14:32 李立波 閱讀(1933) | 評論 (1)編輯 收藏

          JAVA的對LDAP操作代碼(以DOMINO為例子)

          LdapConnector  連接類

          import J2EE技術的爬蟲.util.Hashtable;

          import javax.naming.Context;
          import javax.naming.directory.DirContext;
          import javax.naming.directory.InitialDirContext;
          import javax.naming.directory.SearchControls;

          public class LdapConnector {
           public final static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
           public final static String HOST_URL = "ldap://128.8.1.8:389";
              public static LdapConnector connector=null;
           
           private DirContext ctx;

           private Hashtable<String,String> env;
             
           public LdapConnector(String principal, String credentials) {
            env = new Hashtable();
            try {
             env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
             env.put(Context.PROVIDER_URL, HOST_URL);
             env.put(Context.SECURITY_AUTHENTICATION, "simple");
             env.put(Context.SECURITY_PRINCIPAL, principal);
             env.put(Context.SECURITY_CREDENTIALS, credentials);
             ctx = new InitialDirContext(env);
            } catch (Exception ex) {
             ex.printStackTrace();
            }
            
           }
           
           public  DirContext getDirContext(){
            return ctx;
           }
           
           public static SearchControls getSearchControls(){
            SearchControls constraints;
            constraints = new SearchControls();
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
            return constraints;
           }
           
           
           public static LdapConnector  init(){
               synchronized (LdapConnector.class) {
                if(connector==null)
              connector=new LdapConnector("lilb","1"); 
           }  
             return connector;
           }
          }

          測試類:

          import J2EE技術的爬蟲.util.ArrayList;

          import javax.naming.NamingEnumeration;
          import javax.naming.directory.Attribute;
          import javax.naming.directory.Attributes;
          import javax.naming.directory.DirContext;
          import javax.naming.directory.SearchResult;

          public class LdapText {

           /**
            * @param args
            */
           public static void main(String[] args) throws Exception{
            // TODO Auto-generated method stub
            String cn="";
            String dn="";
            
            String filter="";
            String searchBase="";
            NamingEnumeration<SearchResult> results;
            
            

          DirContext ctx =LdapConnector.init().getDirContext();
                  //先拿CN值 ================
                  searchBase="";
                  filter ="(uid=lilb)";
                  results =
             ctx.search(searchBase, filter, LdapConnector.getSearchControls());
            while (results != null && results.hasMore()) {
             SearchResult sr2 =  results.next();
             cn=(String)sr2.getAttributes().get("cn").get();
             dn=sr2.getName();
             System.out.println(dn);
            }
                  //=======================
                 
                  J2EE技術的爬蟲.util.List<String> uidList=new ArrayList<String>();
            
                  filter =
             "(&(objectClass=dominoGroup)(cn=IT事業部))";
                 
             results =
             ctx.search(searchBase, filter, LdapConnector.getSearchControls());
            
            while (results != null && results.hasMore()) {
             SearchResult sr =  results.next();
             System.out.println(sr.getName());
             
             Attributes attrs = sr.getAttributes();
             NamingEnumeration attrsEnum=attrs.get("member").getAll();
             System.out.println("組織里的人員有 :"+attrs.get("member"));
             while (attrsEnum != null && attrsEnum.hasMore()) {
              String str=(String)attrsEnum.next();
              System.out.println(str.equalsIgnoreCase(dn));
              NamingEnumeration<SearchResult> resultsPerson =
               ctx.search(str, "(objectClass=*)", LdapConnector.getSearchControls());//根據DN,再重新查找
              while (resultsPerson != null && resultsPerson.hasMore()) { 
               SearchResult srPerson =  resultsPerson.next();
               System.out.println(srPerson.getAttributes().get("cn").get());//里面人的CN
               System.out.println(srPerson.getAttributes().get("uid").get()+"@");//里面人的UID
               uidList.add(srPerson.getAttributes().get("uid").get().toString().toLowerCase());
              }
             }
             System.out.println("本組織是否存在這用戶 :"+uidList.contains("lilb"));
             
             
             
            }
           }

          }

          posted @ 2007-04-10 14:21 李立波 閱讀(1648) | 評論 (0)編輯 收藏

          我心目中中國隊的理想陣容

               我心目中的理想陣容 

               于大寶(韓鵬)

          于海   鄭智   董方卓
              邵佳一 
                   周海賓  
          孫詳 李偉峰 馮蕭庭 孫繼海



          前提試換了鬼老教練

          posted @ 2007-04-10 14:14 李立波 閱讀(197) | 評論 (0)編輯 收藏

          My Links

          Blog Stats

          News

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          文章檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宁陕县| 塔城市| 涞水县| 阜阳市| 中宁县| 会理县| 宁蒗| 长治县| 泰和县| 双柏县| 托里县| 漾濞| 高阳县| 维西| 洪雅县| 乡城县| 廉江市| 扎兰屯市| 武义县| 无锡市| 体育| 元江| 乐山市| 英山县| 河曲县| 陕西省| 长顺县| 余干县| 收藏| 龙海市| 阳高县| 宁乡县| 台北县| 栖霞市| 广南县| 喀什市| 乌鲁木齐县| 平武县| 赤水市| 榆林市| 隆子县|