Skip to Content
0
Mar 10, 2020 at 12:59 AM

how to create a JSP connection to SAP through Jco?

97 Views Last edit Mar 10, 2020 at 01:00 AM 2 rev

I want to create a JSP and fetch data from SAP. I followed the official tutorial of sJco 3.0 and stuck in the first step. I'm really confused. Can some give a hint ? below is the offical sample code.

public class StepByStepClient
{
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST,
"ls4065");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,
"85");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT,
"800");
connectProperties.setProperty(DestinationDataProvider.JCO_USER,
"homo faber");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,
"alaska");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG,
"en");
createDestinationDataFile(DESTINATION_NAME1,
connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPA
CITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMI
T, "10");
createDestinationDataFile(DESTINATION_NAME2,
connectProperties);
}
static void createDestinationDataFile(String destinationName,
Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg,
false);
connectProperties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the
destination files", e);
}
}
public static void step1Connect() throws JCoException
  {
	  JCoDestination destination=JCoDestinationManager.getDestination(DESTINATION_NAME1);
	  System.out.print(destination.getAttributes());
  }

1.I don't understand what's the use of createDestinationDataFile method? It just create a file isn't it? all the property already set up in DestinationProvider, then why need a file?

2.I copy the sample code to a project and it worked. But when I triy to create a JSP and call it error happened. I doubt maybe the configuration file ABAP_AS_WITHOUT_POOL.property is the reason. Anyone has same error before? The error is below.

08:49:20,035 ERROR [stderr] (default task-2) java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
08:49:20,036 ERROR [stderr] (default task-2) 	at java.lang.ClassLoader.loadLibrary(Unknown Source)
08:49:20,049 ERROR [stderr] (default task-2) 	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
08:49:20,049 ERROR [stderr] (default task-2) 	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
08:49:20,186 ERROR [stderr] (default task-2) 	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
08:49:20,187 ERROR [stderr] (default task-2) 	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
...
08:49:20,229 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /TestWebsite/1.jsp: javax.servlet.ServletException: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
	at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:889)
	at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:818)
	at org.apache.jsp._1_jsp._jspService(_1_jsp.java:165)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	...
Caused by: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
	at com.sap.conn.jco.rt.MiddlewareJavaRfc.<clinit>(MiddlewareJavaRfc.java:226)
	at com.sap.conn.jco.rt.DefaultJCoRuntime.initialize(DefaultJCoRuntime.java:98)
	at com.sap.conn.jco.rt.JCoRuntimeFactory.<clinit>(JCoRuntimeFactory.java:23)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at com.sap.conn.jco.JCo.createJCo(JCo.java:52)
	at com.sap.conn.jco.JCo.<clinit>(JCo.java:26)
	at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:104)
	at SCOfetch.JCOtest.step4QueryTable(JCOtest.java:217)
	at org.apache.jsp._1_jsp._jspService(_1_jsp.java:149)
	... 45 more