Application Integration (On-Premises) : Incorporating web applications : Guidelines for Creating Web Applications : Invoking a Service from a Web Application : Invoking an Integration Server Service from a Servlet
Invoking an Integration Server Service from a Servlet
You can also invoke an Integration Server service from a servlet. The following shows a sample servlet that illustrates how to invoke an Integration Server service. It takes as input two strings (e.g., “hello” and “world”), invokes the pub.string:concat service to concatenate the two input strings, and returns as output the concatenated string (e.g., “hello world”).
Note:  
The com.wm.app.b2b.server.Service class which is imported in the following sample servlet is located in wm-isserver.jar.
import java.io.IOException;
import java.io.PrintWriter;
 
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import com.wm.data.*;
import com.wm.app.b2b.server.Service;
 
public class ServiceServlet extends HttpServlet {
 
// Allows you to have finer control over the logging levels
private static Log log = LogFactory.getLog( ServiceServlet.class );
 
public void doGet( HttpServletRequest request,
HttpServletResponse response)throws ServletException,
IOException {
 
PrintWriter out = response.getWriter();
 
ServletContext ctx = getServletContext();
// Will show on IS level 8
ctx.log("logging a string in the IS server log via the Servlet API");
log.info("Servlet logging at the IS level 4");
log.debug("Servlet logging at the IS level 8");
 
IDataCursor cursor = idata.getCursor();
String param1 = request.getParameter ("param1");
String param2 = request.getParameter ("param2");
 
// Pass the parameters to the pipeline
IDataUtil.put( cursor, "inString1", param1 );
IDataUtil.put( cursor, "inString2", param2 ); 
 
try{
 
idata = Service.doInvoke( "pub.string", "concat", idata );
 
}catch( Throwable t){
log.error("The service failed: " , t);
}
// Get the concatenated String returned by the Service
String value = (String)IDataUtil.get( cursor, "value" );
cursor.destroy();
out.println("<HTML>");
out.println("<P>Invoked the IS service <b>pub.string:concat</b> </P>");
out.println("<UL>");
out.println("<FONT COLOR=RED>");
out.println("<LI>param1 = " + param1 + "</LI>");
out.println("<FONT COLOR=BLUE>");
out.println("<LI>param2 = " + param2 + "</LI>");
out.println("<FONT COLOR=RED>");
out.println("<LI>Service returned = " + value + "</LI>");
out.println("</UL>");
out.println("</html>");
 
}
}
Copyright © 2015- 2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback