Hi all,
I'm working in JCO, and i like have a connection with a system SAP, but i can't to connect with this system.
I have a web page where i take date for to connect with system SAP(example: user, password,...etc).
I have a class in Java, with the method:
public String Conectar_Sap(
String mandante,
String usuario,
String psw,
String idioma){
String resultado;
JCO.Client mConnection;
//PROBLEM----
>mConnection = JCO.createClient("mandante","usuario","psw","hostname","00");
mConnection.connect();
mConnection.disconnect();
return resultado="ok";
}
The problem is in: mConnection = JCO.createClient("mandante","usuario","psw","hostname","00");
I don't know why no work.
Please, help me.
Thank's in advanced.
Hi Vicente,
please remove the '"'s from the String parameters in the method call which creates the client. Instead of:
mConnection = JCO.createClient("mandante","usuario","psw","hostname","00");
use
mConnection = JCO.createClient(mandante, usuario, psw, hostname, "00");
If the corresponding parameter contents are correct, you should be able to open the connection.
Hope that helps.
Regards
Stefan
Hi Stefan,
Thank's for your help.
I have resolve this problem, but i don't know why it haven't connect with the system SAP.
This is the code of method where i take data of the web page:
**********************************************************
public String getConexion(
String mandante,
String usuario,
String psw,
String idioma)
throws Exception {
try {
if (mandante != null && usuario != null && psw != null && idioma != null) {
Resultado = conbean.Conectar_Sap(mandante,usuario,psw,idioma);
}
} catch (Exception ex) {
throw new Exception("Error al intentar conectar con SAP a traves de JCO");
}
return Resultado;
}
**********************************************************
I think that the problem is when i call the method "conbean.Conectar_Sap",(that it is the method that i have write before), why the value of the web page are corrects and always exit the exception : "Error al intentar conectar con SAP a traves de JCO".
What I can have?,
Any idea?
Thank's in advanced.
Vicente
Hi Stefan,
Thank's for you help.
I write you the code of my application. My application to consist of 3 file, (.jar, .was, .ear).
1.-In the .war i have code of the web page and java class where i take the value of the conexion.
1a.- Code of web page:
*********************************************************
<%@ page language="java" %>
<html>
<jsp:useBean id="con" scope="session"
class="com.sap.conectar.beans.ConProxy"/>
<body>
<FORM METHOD="post" ACTION="Conectar.jsp">
<P>Mandante:</P>
<P><INPUT NAME="Mandante" size=10></P>
<P>Usuario:</P>
<P><INPUT name="Usuario" size=10></P>
<P>Clave de Acceso:</P>
<P><INPUT NAME="Psw" size=10></P>
<P>Idioma:</P>
<P><INPUT NAME="Idioma" size=10></P>
<P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Entrar"></P>
</FORM>
<P><HR HEIGHT="1px" WIDTH="80%" COLOR="#000000"></P>
<% try { %>
<B> <%="Datos de la conexion son: " +
con.getConexion(request.getParameter("Mandante"),request.getParameter("Usuario"),
request.getParameter("Psw"), request.getParameter("Idioma"))%></B>
</P>
<% } catch (Exception ex) { %>
<%=ex.getMessage()%>
<% } %>
</body>
</html>
**********************************************************
1b.- Code of the java class of the file .war
*********************************************************
package com.sap.conectar.beans;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.sap.conectar.*;
import com.sap.conectar.ConectarHome;
public class ConProxy {
public Conectar con;
public String Resultado;
public void init() throws Exception {
//Lookup the enterprise bean
try {
InitialContext ctx = new InitialContext();
Object ob = ctx.lookup("java:comp/env/ejb/ConectarBean");
ConectarHome home =
(ConectarHome) PortableRemoteObject.narrow(
ob,
ConectarHome.class);
//Initialize the enterprise bean
con = home.create();
} catch (Exception e) {
throw new Exception(
"Error instantiating Conexion EJB" + e.toString());
}
}
public ConProxy() throws Exception {
init();
}
public String getConexion(
String mandante,
String usuario,
String psw,
String idioma)
throws Exception {
try {
if (mandante != null && usuario != null && psw != null && idioma != null) {
Resultado = con.Conectar_Sap(mandante,usuario,psw,idioma);
}
}
catch (Exception ex) {
throw new Exception("Error al intentar conectar con SAP a traves de JCO");
}
return Resultado;
}
}
this is of exception that always show in the web page----
> "throw new Exception("Error al intentar conectar con SAP a traves de JCO")"
**********************************************************
2.- In the .jar i have a ejb, with interface.
This java class is where i have the conexion SAP.
The code is:
**********************************************************
package com.sap.conectar;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.sap.mw.jco.*;
public class ConectarBean implements SessionBean {
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
myContext = context;
}
private SessionContext myContext;
/**
Business Method.
*/
public String Conectar_Sap(
String mandante,
String usuario,
String psw,
String idioma){
String Resultado;
try{
JCO.Client mConnection;
mConnection = JCO.createClient(mandante,usuario,psw,idioma,"Sap46b02","00");
mConnection.connect();
System.out.println(mConnection.getAttributes());
mConnection.disconnect();
}
catch(Exception ex){
return Resultado = "no hace la conexion";
}
return Resultado="conexion conexion";
}
public void ejbCreate() throws CreateException {
// TODO : Implement
}
}
**********************************************************
3.- The file .ear is the union of .jar and .war and it is that i have deploy.
I have imported the JCO class the proyect. I tink that the problem perhaps is in the class JCO.
Thank's for all.
Excuse me for my english.
Vicente
Hi Stefan,
Very Thank's for your help.
I have proved your solution and the exception is:
**********************************************************
Datos de la conexion son: com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception thrown by the com.sap.conectar.ConectarObjectImpl0.Conectar_Sap(java.lang.String,java.lang.String,java.lang.String,java.lang.String) method. at com.sap.conectar.ConectarObjectImpl0.Conectar_Sap(ConectarObjectImpl0.java:156) at com.sap.conectar.Conectar_Stub.Conectar_Sap(Conectar_Stub.java:55) at com.sap.conectar.beans.ConProxy.getConexion(ConProxy.java:44) at jsp_Conectar1103626769347._jspService(jsp_Conectar1103626769347.java:19) at com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.service(JSPServlet.java:469) at com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.service(JSPServlet.java:181) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:373) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:250) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:319) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:297) at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:696) at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:221) at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92) at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:146) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37) at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:140) Caused by: java.lang.NoClassDefFoundError: com/sap/mw/jco/JCO at com.sap.conectar.ConectarBean.Conectar_Sap(ConectarBean.java:37) at com.sap.conectar.ConectarObjectImpl0.Conectar_Sap(ConectarObjectImpl0.java:139) ... 20 more ; nested exception is: java.lang.NoClassDefFoundError: com/sap/mw/jco/JCO **********************************************************
I have the JCO class in the proyect and i don't know why the error.
Perhaps I need insert the JCO class in specify folder.
Any idea?
PD: I think that never will finish this proyect, jejeje.
Add a comment