gpt4 book ai didi

java - 我想从工作灯适配器调用 java 类

转载 作者:行者123 更新时间:2023-11-28 20:35:43 24 4
gpt4 key购买 nike

我已在该 url“http://www.ibm.com/developerworks/mobile/worklight/getting-started.html#authentication ”或 ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/Module_05_5_-_Using_Java_in_Adapters.pdf 中关注此文档模块 5.5

并做了同样的事情,我的代码结构是

server/java                        folder name
com.worklight.custonmode package name
loginfunction.java java file inside com.worklight.custonmode package
login java method in class loginfunction

我已经从工作灯适配器调用了

function loginmodules(username, passwd) {   
return {
result : com.worklight.custonmode.loginfunction.login()
};
}

当我打电话时收到这样的错误

 response [/apps/services/api/Light/common/query] success: /*-secure- {"responseID":"2","errors":["Ecma Error: TypeError: Cannot call property login in object [JavaPackage com.worklight.custonmode.loginfunction]. It is not a function, it is \"object\". 

(C%3A%5CUsers%5CADMIN%5CworkspaceM11%5CMobileClient%5Cadapters%5CAdapter/Adapter-impl.js#103)"],"isSuccessful":false,"警告":[],"信息":[] }*/

    worklight.js (line 1112)

Procedure invocation error. Ecma Error: TypeError: Cannot call property login in object [JavaPackage com.worklight.custonmode.loginfunction]. It is not a function, it is "object". (C%3A%5CUsers%5CADMIN%5CworkspaceM11%5CMobileClient%5Cadapters%5CAdapter/Adapter-impl.js#103)

loginfunction.java 中的我的登录函数

  public class loginfunction {

public static void login() {
//============== Code to adapt to your own configuration =============//
String server = "https://ibm-f4acjqe8c6p:9443/dfd"; // Set the Public URI of your RRC server
String JTS_Server = "https://ibm-f4acjqe8c6p:9443/jts"; //Set the public URI of your JTS server
String login = "Admin"; // Set the user login
String password = "Admin"; // Set the associated password
//============== -------------------------------------- =============//

String rootServices = server + "/rootservices";
String catalogXPath = "/rdf:Description/oslc_we:rweServiceProviders/@rdf:resource";
String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title";

System.out.println(">> Example03: Print out the content of the Service Providers catalog");
System.out.println(" - Root Services URI: "+rootServices);
System.out.println(" - Service Providers catalog XPath expression: "+catalogXPath);
System.out.println(" - Service Provider title XPath expression: "+serviceProviderTitleXPath);
System.out.println(" - Login: "+login);
System.out.println(" - Password: "+password);

// Setup the HttClient
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpUtils.setupLazySSLSupport(httpclient);

// Setup the rootServices request
HttpGet rootServiceDoc = new HttpGet(rootServices);
rootServiceDoc.addHeader("Accept", "application/rdf+xml");
rootServiceDoc.addHeader("OSLC-Core-Version", "2.0");

try {
// Request the Root Services document
HttpResponse rootServicesResponse = HttpUtils.sendGetForSecureDocument(
server, rootServiceDoc, login, password, httpclient,JTS_Server);

if (rootServicesResponse.getStatusLine().getStatusCode() == 200) {
// Define the XPath evaluation environment
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(
new NamespaceContextMap(new String[]
{ "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"oslc_we","http://open-services.net/xmlns/we/1.0/"}));

// Parse the response body to retrieve the catalog URI
InputSource source = new InputSource(rootServicesResponse.getEntity().getContent());
Node attribute = (Node) (xpath.evaluate(catalogXPath, source, XPathConstants.NODE));
String serviceProvidersCatalog = attribute.getTextContent();
rootServicesResponse.getEntity().consumeContent();

// Setup the catalog request
HttpGet catalogDoc = new HttpGet(serviceProvidersCatalog);
catalogDoc.addHeader("Accept", "application/xml");
catalogDoc.addHeader("OSLC-Core-Version", "2.0");

// Access to the Service Providers catalog
HttpResponse catalogResponse = HttpUtils.sendGetForSecureDocument(
server, catalogDoc, login, password, httpclient,JTS_Server);
if (catalogResponse.getStatusLine().getStatusCode() == 200) {
// Define the XPath evaluation environment
XPath xpath2 = factory.newXPath();
xpath2.setNamespaceContext(
new NamespaceContextMap(new String[]
{ "oslc", "http://open-services.net/ns/core#",
"dcterms","http://purl.org/dc/terms/"}));

// Parse the response body to retrieve the Service Provider
source = new InputSource(catalogResponse.getEntity().getContent());
NodeList titleNodes = (NodeList) (xpath2.evaluate(serviceProviderTitleXPath, source, XPathConstants.NODESET));

// Print out the title of each Service Provider
int length = titleNodes.getLength();
System.out.println(">> Project Areas:");
for (int i = 0; i < length; i++) {
System.out.println(">> \t - "+ titleNodes.item(i).getTextContent());
}
}
}
rootServicesResponse.getEntity().consumeContent();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XPathExpressionException e) {
e.printStackTrace();
} catch (InvalidCredentialsException e) {
e.printStackTrace();
} finally {
// Shutdown the HTTP connection
httpclient.getConnectionManager().shutdown();
}
}

}

最佳答案

我刚刚想通了这一点。有趣的是,两个月来每个人都在这个问题上保持沉默。对我来说,这根本不明显,因为它在某些项目中有效,而在其他项目中则不起作用。对于机器来说也是如此。它会在一个地方起作用,但在另一个地方不起作用(如果您不知道发生了什么)。

检查您的 .project 文件并确保其中包含正确的 buildCommand 标记。

<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.worklight.studio.plugin.WorklightProjectBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>

了解更多信息:ECMA TypeError calling Java class from Worklight adapter

关于java - 我想从工作灯适配器调用 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15428243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com