Hello,

I am attempting to call my own Java class between forms, meaning in a
mapping activity.

My Java code looks like this:


Code:
--------------------

package fk.pob;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.w3c.dom.Document;
import org.w3c.dom.*;
import org.apache.xml.serialize.XMLSerializer;
import org.apache.xml.serialize.OutputFormat;

public class CallWebservice {

public void createCase() throws MalformedURLException,
IOException {

//Code to make a webservice HTTP request
String responseString = "";
String outputString = "";
String wsURL = "https://url/webservice.svc";
URL url = new URL(wsURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
String xmlInput
= "my soap envelope here";


byte[] buffer = new byte[xmlInput.length()];
buffer = xmlInput.getBytes();
bout.write(buffer);
byte[] b = bout.toByteArray();
String SOAPAction
= "http://soapactionurl";
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty("Content-Length",
String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", SOAPAction);
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
//Write the content of the request to the outputstream of the HTTP Connection.
out.write(b);
out.close();
//Ready with sending the request.

//Read the response.
InputStreamReader isr
= new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);

//Write the SOAP message response to a String.
while ((responseString = in.readLine()) != null) {
outputString = outputString + responseString;
}
System.out.println("Response string: " + outputString);
//Parse the String output to a org.w3c.dom.Document and be able to reach every node with the org.w3c.dom API.
//Document document = parseXmlFile(outputString);

//NodeList nodeLst = document.getElementsByTagName("GetWeatherResult");
//String weatherResult = nodeLst.item(0).getTextContent();
//System.out.println("Weather: " + weatherResult);

//Write the SOAP message formatted to the console.
//String formattedSOAPResponse = formatXML(outputString);
//System.out.println(formattedSOAPResponse);

}

//format the XML in your String
public String formatXML(String unformattedXml) {
try {
Document document = parseXmlFile(unformattedXml);
OutputFormat format = new OutputFormat(document);
format.setIndenting(true);
format.setIndent(3);
format.setOmitXMLDeclaration(true);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private Document parseXmlFile(String in) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(in));
return db.parse(is);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

--------------------


I have then edited the IDMProv.war - under WEB-INF/classes i have added
a folder named fk, and a subfolder named pob and under pob placed the
..class file, CallWebservice.class

I have edited the UIControlRegistry.xml under <services> I have added:


Code:
--------------------

<service resultType="json" authenticated="true" config="false">
<key>createCase</key>
<classname>fk.pob.CallWebservice.createCase</classname>
</service>

--------------------


In my workflow mapping activity I have tried two options:


Code:
--------------------

Packages.fk.pob.CallWebservice.createCase();

--------------------


and


Code:
--------------------

var result=IDVault.execService("createCase");

--------------------


Then restarted Tomcat server.

In both cases I get this in the catalina.out:


Code:
--------------------

2016-01-18 15:59:55,087 [pool-3-thread-8] ERROR com.novell.soa.af.impl.activity.ActivityNode- [RBPM] Error Evaluating Script Error Evaluating Script com.novell.soa.script.mozilla.javascript.Evaluator Exception: Java class "fk.pob.CallWebservice" has no public instance field or method named "createCase". 1 0
2016-01-18 15:59:55,087 [pool-3-thread-8] ERROR com.novell.soa.af.impl.LogEvent- [RBPM] [Workflow_Error] Initiated by cn=uaadmin,o=xxx, Error Message: Dataitem [MAP0] with expression [Packages.fk.pob.CallWebservice.createCase();] failed to evaluate., Process ID: 4726fb365abc41388bfe723879b15b8d, Process Name: cn=workflowname,cn=requestdefs,cn=appconfig,cn=xxx ,cn=xxx,ou=xxx,o=xxx:57, Activity: Activity, Recipient: cn=uaadmin,o=xxx

--------------------


Any ideas what I might be doing wrong?

Thanks in advance,

Jacob.


--
jacmarpet
------------------------------------------------------------------------
jacmarpet's Profile: https://forums.netiq.com/member.php?userid=415
View this thread: https://forums.netiq.com/showthread.php?t=55149