Servis-Rhino 4211B Guia do Utilizador Página 83

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 298
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 82
Error Handling for Adapters
See also:
developerWorks – Error handling in IBM Worklight adapters - 2012-12-05
Invoking Java code from an Adapter
When an adapter is invoked by the client a JavaScript routine is executed. IBM's Worklight server
runs JavaScript on the Mozilla Rhino engine. Rhino has the ability to execute arbitrary Java code.
The implication of this is that an Adapter can also invoke Java code.
Java code that is compiled and placed in a JAR file is added to the class-path of the JavaScript
environment if that JAR is added into the project's server/lib folder.
Here is an example of calling Java through an adapter.
1. Create a Java project called Adapter2Java
2. Create a package called "com.kolban"
3. Create a Java class called "Adapter2Java"
4. Implement the Java class as follows:
package com.kolban;
public class Adapter2Java {
public String getGreeting(String name) {
return "Hello, " + name;
}
}
What this class does is expose a function called "getGreeting" that, when called, will return a
greeting.
5. Export the Java project as a JAR file called "Adapter2Java.jar".
6. Create a Worklight project called WL_Adapter2Java
7. Copy the JAR file into the projects server/lib folder
8. Create a new adapter called Adapter2Java
Page 83
Vista de página 82
1 2 ... 78 79 80 81 82 83 84 85 86 87 88 ... 297 298

Comentários a estes Manuais

Sem comentários