Lotus Notes thrwoing中的Java代理;java.security.AccessControlException“;例外情况

Lotus Notes thrwoing中的Java代理;java.security.AccessControlException“;例外情况,java,lotus-notes,javaagents,Java,Lotus Notes,Javaagents,很明显,我正在尝试使用Google自定义搜索API在Google中搜索。我用LotusNotes制作了这个Java代理 主要类别: import java.util.List; import lotus.domino.AgentBase; import com.google.api.services.customsearch.model.Result; public class JavaAgent extends AgentBase { public void NotesMain() {

很明显,我正在尝试使用Google自定义搜索API在Google中搜索。我用LotusNotes制作了这个Java代理

主要类别:

import java.util.List;
import lotus.domino.AgentBase;
import com.google.api.services.customsearch.model.Result;
public class JavaAgent extends AgentBase {
    public void NotesMain() {
        GoogleSearchClient gsc = new GoogleSearchClient();
        String searchKeyWord = "test";
        List<Result> resultList =    gsc.getSearchResult(searchKeyWord);
        if(resultList != null && resultList.size() > 0){
            for(Result result: resultList){
                System.out.println(result.getHtmlTitle());
                System.out.println(result.getFormattedUrl());
                System.out.println("----------------------------------------");
            }
        }
    }
}
  • 我想试试,但我的软件版本是9

  • 我在Eclipse中尝试了相同的代码,它工作得很好,所以我认为Notes安全配置是错误的。我必须使用LotusNotes,因为我必须将信息保存在表单等中

  • 我将运行时安全级别更改为3(允许具有完全管理权限的受限操作)


  • 你知道我该怎么做吗?

    当我在Lotus中为我的Web服务消费者开发WS-Security时,我遇到了同样的错误。我发现通过使用
    .jar
    文件中的方法可以避免这种情况。因此,您需要在IDE中创建单独的
    .jar
    ,并在Lotus代理中使用它。
    下面是在代码中使用
    AccessController.doPrivileged
    的示例:

    import java.util.Collections;
    import java.util.List;
    import com.google.api.client.http.HttpTransport;
    import com.google.api.client.http.javanet.NetHttpTransport;
    import com.google.api.client.json.JsonFactory;
    import com.google.api.services.customsearch.Customsearch;
    import com.google.api.services.customsearch.model.Result;
    import com.google.api.services.customsearch.model.Search;
    public class GoogleSearchClient {
        public List<Result> getSearchResult(final String keyword){
            String GOOGLE_SEARCH_URL = https://www.googleapis.com/customsearch/v1?";
            //api key
            final String API_KEY = "xxxxxxxxxxxxxxxxxxxxx";
            //custom search engine ID
            final String SEARCH_ENGINE_ID = "xxxxxxxxxx:xxxxxxxxxxxx";
            String FINAL_URL= GOOGLE_SEARCH_URL + "key=" + API_KEY + "&cx=" + SEARCH_ENGINE_ID;
            // Set up the HTTP transport and JSON factory
            HttpTransport httpTransport = new NetHttpTransport();
            JsonFactory jsonFactory = new com.google.api.client.json.jackson2.JacksonFactory();
            //HttpRequestInitializer initializer = (HttpRequestInitializer)new CommonGoogleClientRequestInitializer(API_KEY);
            final Customsearch customsearch = new Customsearch(httpTransport, jsonFactory,null);
    
            return AccessController.doPrivileged(
                    new PrivilegedAction<List<Result>>() {
                @Override
                public List<Result> run() {
                    List<Result> resultList = Collections.emptyList();
                    try {
                        Customsearch.Cse.List list = customsearch.cse().list(keyword);
                        list.setKey(API_KEY);
                        list.setCx(SEARCH_ENGINE_ID);
                        //num results per page
                        //list.setNum(2L);
    
                        //for pagination
                        list.setStart(10L);
                        Search results = list.execute();
                        resultList = results.getItems();
    
                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    return resultList;
                }
            });
        }
    }
    
    import java.util.Collections;
    导入java.util.List;
    导入com.google.api.client.http.HttpTransport;
    导入com.google.api.client.http.javanet.NetHttpTransport;
    导入com.google.api.client.json.JsonFactory;
    导入com.google.api.services.customsearch.customsearch;
    导入com.google.api.services.customsearch.model.Result;
    导入com.google.api.services.customsearch.model.Search;
    公共类GoogleSearchClient{
    公共列表getSearchResult(最终字符串关键字){
    字符串GOOGLE\u SEARCH\u URL=https://www.googleapis.com/customsearch/v1?";
    //api密钥
    最终字符串API_KEY=“XXXXXXXXXXXXXXXXXX”;
    //自定义搜索引擎ID
    最终字符串搜索引擎\u ID=“XXXXXXXXX:xxxxxxxxxx”;
    字符串FINAL\u URL=GOOGLE\u SEARCH\u URL+“key=“+API\u key+”&cx=“+SEARCH\u ENGINE\u ID;
    //设置HTTP传输和JSON工厂
    HttpTransport HttpTransport=新的NetHttpTransport();
    JsonFactory=new com.google.api.client.json.jackson2.JacksonFactory();
    //HttpRequestInitializer初始值设定项=(HttpRequestInitializer)新的通用GoogleClientRequestInitializer(API_键);
    最终Customsearch Customsearch=新Customsearch(httpTransport,jsonFactory,null);
    返回AccessController.doPrivileged(
    新特权(){
    @凌驾
    公共列表运行(){
    List resultList=Collections.emptyList();
    试一试{
    Customsearch.Cse.List List=Customsearch.Cse().List(关键字);
    列表。设置键(API_键);
    list.setCx(搜索引擎ID);
    //每页的结果数
    //list.setNum(2L);
    //分页
    列表。设置启动(10L);
    搜索结果=list.execute();
    resultList=results.getItems();
    }捕获(例外e){
    e、 printStackTrace();
    }
    返回结果列表;
    }
    });
    }
    }
    
    java.security.AccessControlException: Access denied (java.lang.reflect.ReflectPermission suppressAccessChecks)
        at java.security.AccessController.throwACE(AccessController.java:100)
        at java.security.AccessController.checkPermission(AccessController.java:174)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:544)
        at COM.ibm.JEmpower.applet.AppletSecurity.superDotCheckPermission(AppletSecurity.java:1449)
        at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1617)
        at COM.ibm.JEmpower.applet.AppletSecurity.checkPermission(AppletSecurity.java:1464)
        at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:118)
        at com.google.api.client.util.FieldInfo.of(FieldInfo.java:97)
        at com.google.api.client.util.ClassInfo.<init>(ClassInfo.java:172)
        at com.google.api.client.util.ClassInfo.of(ClassInfo.java:90)
        at com.google.api.client.util.GenericData.<init>(GenericData.java:79)
        at com.google.api.client.util.GenericData.<init>(GenericData.java:61)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.<init>(AbstractGoogleClientRequest.java:109)
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.<init>(AbstractGoogleJsonClientRequest.java:57)
        at com.google.api.services.customsearch.CustomsearchRequest.<init>(CustomsearchRequest.java:43)
        at com.google.api.services.customsearch.Customsearch$Cse$List.<init>(Customsearch.java:178)
        at com.google.api.services.customsearch.Customsearch$Cse.list(Customsearch.java:154)
        at GoogleSearchClient.getSearchResult(Unknown Source)
        at JavaAgent.NotesMain(Unknown Source)
        at lotus.domino.AgentBase.runNotes(Unknown Source)
        at lotus.domino.NotesThread.run(Unknown Source)
    
    grant { permission java.util.PropertyPermission "http.keepAlive", "read, write"; };
    grant { permission java.security.AllPermission; } 
    
    import java.util.Collections;
    import java.util.List;
    import com.google.api.client.http.HttpTransport;
    import com.google.api.client.http.javanet.NetHttpTransport;
    import com.google.api.client.json.JsonFactory;
    import com.google.api.services.customsearch.Customsearch;
    import com.google.api.services.customsearch.model.Result;
    import com.google.api.services.customsearch.model.Search;
    public class GoogleSearchClient {
        public List<Result> getSearchResult(final String keyword){
            String GOOGLE_SEARCH_URL = https://www.googleapis.com/customsearch/v1?";
            //api key
            final String API_KEY = "xxxxxxxxxxxxxxxxxxxxx";
            //custom search engine ID
            final String SEARCH_ENGINE_ID = "xxxxxxxxxx:xxxxxxxxxxxx";
            String FINAL_URL= GOOGLE_SEARCH_URL + "key=" + API_KEY + "&cx=" + SEARCH_ENGINE_ID;
            // Set up the HTTP transport and JSON factory
            HttpTransport httpTransport = new NetHttpTransport();
            JsonFactory jsonFactory = new com.google.api.client.json.jackson2.JacksonFactory();
            //HttpRequestInitializer initializer = (HttpRequestInitializer)new CommonGoogleClientRequestInitializer(API_KEY);
            final Customsearch customsearch = new Customsearch(httpTransport, jsonFactory,null);
    
            return AccessController.doPrivileged(
                    new PrivilegedAction<List<Result>>() {
                @Override
                public List<Result> run() {
                    List<Result> resultList = Collections.emptyList();
                    try {
                        Customsearch.Cse.List list = customsearch.cse().list(keyword);
                        list.setKey(API_KEY);
                        list.setCx(SEARCH_ENGINE_ID);
                        //num results per page
                        //list.setNum(2L);
    
                        //for pagination
                        list.setStart(10L);
                        Search results = list.execute();
                        resultList = results.getItems();
    
                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    return resultList;
                }
            });
        }
    }