Domino 9 und frühere Versionen > ND8: Entwicklung - XPages

WebService mit XPage konsumieren

<< < (2/3) > >>

atbits:
Ich denke das hier ist so ziemlich das was Du suchst:

http://www-10.lotus.com/ldd/ddwiki.nsf/dx/reuse_web_services_xpage.htm

Using existing Web Services in an Xpage
Web Service
So far, we have discussed two methods to reference existing business logic in XPages. Web services is a third option and it will leverage the same technique described in the Java section: the ability of Server Side JavaScript to call Java. Instead of calling your business logic, we will use JavaScript to access JAR files distributed with the IBM Lotus Domino 8.5 server. These JAR files provide the Web Services client framework providing access to web services. In this article we will use Apache Axis and the extensible type mapping framework (javax.xml.rpc.encoding). Web services can not be used by XPages to access business logic running on the same Lotus Domino server because a deadlock condition might occur in the HTTP server. This restriction prevents XPages from using Web services to call an applications business logic, but we include this technique here because Web services can be used to access business logic running in another application on a different server.

In the LotusScript section a "Credit Rating" scenario is discussed. A new label was added, with a computed value using Server Side JavaScript to call an agent. The return value from this formula is displayed as the label contents. Web services would be a viable alternative, if the "Credit Rating" business logic was in another application on another server. A new label would be added, with a computed value using Server Side JavaScript to call the Web service. Lets walk through that code

JavaScript code to call a Web service to operate on parameters, and return a value.


--- Code: ---

      var service = new org.apache.axis.client.Service;

      var call = service.createCall();

      call.setTargetEndpointAddress("http://myServer.myCompany.com/WebServicesDemo.nsf/DemoWebService?WSDL");

      call.setOperationName( "CalcCreditRating" );

      var xmlType = new javax.xml.rpc.encoding.XMLType();

 
      call.addParameter("INPUT1", xmlType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);


      call.addParameter("INPUT2", xmlType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

      call.setReturnType(xmlType.XSD_STRING);

      var a = new java.lang.Object[2];

      a[0] = "CompanyA";

      a[1] = "2008";

      var rating = call.invoke(a);

      print ("return value from web service = "+rating);

      return rating;

--- Ende Code ---

We will only describe the Web service client code. A Web service provider must also be implemented for the sample above to access. In this case, the author used another Lotus Domino 8.5 server as the Web Service provider. This Web service accepted two strings as input arguments and returned a string for the credit rating. Any Web Services provider is acceptable, but some of the sample code might require minor modifications.

On line (1) and (2) we create the Service and Call object to access the Web service. We then associate the Call object to the WSDL (3) which defines the available operations. We must specify the operation we plan to call (4) because a Web Service can contain multiple operations. The next lines (5 - 8) define the arguments, the input argument (6) and (7), and the return (8). The string arguments are passed as an array (9 -11), and then the call is invoked (12). The "Credit Rating" is returned (14) to the computed value and displayed as the label.

The example above was written in JavaScript and calls the Apache Axis and the extensible type mapping framework (javax.xml.rpc.encoding) JAR files. Any Web Services client framework can be used. Apache Axis was selected because it is distributed with the Lotus Domino 8.5 server. If you prefer to develop your solutions in Java instead of JavaScript then develop your code in Java, package the JAR file as described above in the Java section and call your routines from JavaScript. With Java, you can test your logic using JUnit and debug any problems before calling it from XPages.

For other techniques for reusing business logic from XPages please see this article here.

atbits:
Schau mal hier http://www.openntf.org/blogs/openntf.nsf/d6plinks/NHEF-8CBF9R
Ein Beispiel wie es geht

Markus_8891:
Hi,

ich hab mal die JavaScript Variante aus dem angegeben Artikel ausprobiert.
"Using existing Web Services in an Xpage".

Ich arbeite mit einem Domino 8.5.2.


Das war die erste Fehlermeldung die ich bekommen habe.


--- Code: ---Exception
Error while executing JavaScript computed expression
Script interpreter error, line=3, col=48: [ReferenceError] 'org' not found

JavaScript code

   1: var service = new org.apache.axis.client.Service;
   2:
   3:       var call = service.createCall();
   4:

--- Ende Code ---

Dann hab ich mir mal den neuen package name gesucht.

Habe dann diesen  "lotus.domino.axis.client.Service" package Name gefunden.

Nur leider kommt jetzt der Fehler der unten steht.

Wie kann ich denn dann ein Service Object erzeugen. Wenn es keinen öffentlichen
Kontruktor gibt ? 



--- Code: ---Error while executing JavaScript computed expression
Script interpreter error, line=3, col=50: Cannot find java public constructor 'lotus.domino.axis.client.Service()'

JavaScript code

   1: var service = new lotus.domino.axis.client.Service;
   2:       //var service = new org.apache.axis.client.Service;
   3:
   4:       var call = service.createCall();
   5:

--- Ende Code ---

Vielen Danke für Hilfe eure Hilfe im vorraus. 

m3:
Hallo Markus!

Du hast gar nichts falsch gemacht,

--- Code: ---var service = new org.apache.axis.client.Service;
--- Ende Code ---
wäre schon richtig gewesen.

Leider wurde in Domino 8.5.2 die Art und Weise geändert, wie org.apache.axis.client.Service in Domino eingebunden wurde. Stand es früher über den Classpath zur Verfügung, wurde es ab 8.5.2. als OSGI Plugin eingebunden und steht daher nicht mehr für eine wie oben beschriebene Einbindung zur Verfügung.

Du musst Dir also die Axis libraries von der Axis Homepage herunterladen und wie in Using existing Java in an Xpage beschrieben einbinden.
Anschließend noch die Security gemäß Xpages Jar file Access Denied im java.policy File umsetzten:

--- Zitat ---Support suggested adding to the java.policy file (in ..\Lotus\Domino\jvm\lib\security folder).
Add this to the grant section:
permission java.lang.RuntimePermission "getClassLoader";
--- Ende Zitat ---

Dann sollte es funktionieren.

P.S.: Wenn das wer "gefixed" haben will, sodass es wieder so wie früher funktioniert, möge einen enstprechenden PMR aufmachen.

Markus_8891:
Okay danke das hat wunderbar geklappt.

Dies Axis jars hatte ich aus den Versuchen vorher auch schon :P ... dann ging das schnell.

Manchmal versteh ich die IBM nicht, das sie diesen policy Eintrag raus nehmen.
Mit den eingebundenen jars arbeiten doch meines Wissens nach relativ viele Entwickler.

Vielen Dank

Navigation

[0] Themen-Index

[#] Nächste Seite

[*] Vorherige Sete

Zur normalen Ansicht wechseln