Note that there are some explanatory texts on larger screens.

plurals
  1. POi want to call a java class from the worklight adapter
    primarykey
    data
    text
    <p>i have followed this document module 5.5 in this url "<a href="http://www.ibm.com/developerworks/mobile/worklight/getting-started.html#authentication" rel="nofollow">http://www.ibm.com/developerworks/mobile/worklight/getting-started.html#authentication</a>" or <a href="ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/Module_05_5_-_Using_Java_in_Adapters.pdf" rel="nofollow">ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/Module_05_5_-_Using_Java_in_Adapters.pdf</a></p> <p>and did the same my code structure is </p> <pre><code>server/java folder name com.worklight.custonmode package name loginfunction.java java file inside com.worklight.custonmode package login java method in class loginfunction </code></pre> <p>and i have called from the worklight adapter as </p> <pre><code>function loginmodules(username, passwd) { return { result : com.worklight.custonmode.loginfunction.login() }; } </code></pre> <p>when i am calling am getting the error like this as</p> <pre><code> 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\". </code></pre> <p>(C%3A%5CUsers%5CADMIN%5CworkspaceM11%5CMobileClient%5Cadapters%5CAdapter/Adapter-impl.js#103)"],"isSuccessful":false,"warnings":[],"info":[]}*/</p> <pre><code> 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) </code></pre> <p>my login function in loginfunction.java</p> <pre><code> 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("&gt;&gt; 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("&gt;&gt; Project Areas:"); for (int i = 0; i &lt; length; i++) { System.out.println("&gt;&gt; \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(); } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload