Call WebService from Java (SSJS - XPages)


package com.domino.openntf;

import java.net.URL;
import java.util.HashMap;
import java.util.Vector;

import javax.faces.context.FacesContext;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceRef;

import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Session;

public class WSFake {
	
    @WebServiceRef(wsdlLocation="http://www.bestcoder.net:80/samples/FakeWS?wsdl")
	public static String Exec() {
		
		String designElementName = "com.domino.openntf.WSFake";
		String procedureName = "Exec";
		
		try
		{
			FacesContext context = FacesContext.getCurrentInstance();
			Session session = (Session) context.getApplication().getVariableResolver().resolveVariable(context, "session");
			HashMap viewScope = (HashMap) context.getApplication().getVariableResolver().resolveVariable(context, "viewScope");
			Database currentDatabase = com.ibm.xsp.model.domino.DominoUtils.getCurrentDatabase(context);
			
			// Enter WebService URL with ending "?WSDL"
			URL url = new URL("http://www.bestcoder.net:80/samples/FakeWS?wsdl");
			QName qName = new QName("urn:DefaultNamespace", "WSFakeDomino");
			
			InputVariables inp = new InputVariables();
			inp.setNo(12345);
			inp.setType("F");
			
			WSFakeDomino wsPort = new WSFakeDomino(url, qName);
			WSFake wsService = wsPort.getService();
			
			// Invoke Web Service
			OutputVariables out = wsService.getExec(inp)
			
			if (out.getReturnCode() == 0) {
				// No Error
				// Do Something ...
			} else {
				// Error
				// Do Something ...
			}
		} catch (Exception e) {
			// Exception - Hata :" + e.getClass().toString() + " - " + e.getMessage()
		}
		
		return "OK";
	}
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
1 comment(s)Login first to comment...
jeniffer homes
(at 02:04 on 22.07.2016)
Wonderful piece of code, works straight out of the box. Thanks!