restfull webservice没有连接sap

时间:2015-09-09 05:40:12

标签: java web-services rest sap

我正在创建一个用于连接SAP的restfull webservice.So,这里的web服务方法都正常工作但只有一个方法抛出错误,下面是该方法。

@Path("/Run")
public class RunBapi {

@GET
public Response runBapi() {

    return Response.status(200).entity("getUser is called").build();

}


@GET
@Path("/query")
public Response getUsers(
    @QueryParam("LIFNR") String accountNO,
    @QueryParam("BUKRS") String companyCode,
    @QueryParam("EKORG") String po,
    @QueryParam("CHAR1") String indicator) {



    ExecuteBapi bapi = new ExecuteBapi();
    bapi.bapi(accountNO,companyCode,po,indicator);
    return Response.status(200).entity("accountNO is: "+accountNO).build();

  }
} 

,我的ExecuteBapi类

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;

public class ExecuteBapi {


 public JCO.Client mConnection;
 public JCO.Repository mRepository;
 public JCO.Function function = null;

 public void connectDev() 
 {
     System.out.println("in");
     try
     {  

         mConnection = connectSAP();
         mConnection.connect();
         mRepository = new JCO.Repository("clss", mConnection);
         System.out.println("sapconnected");
     }
     catch(Exception e)
     {
         System.out.println("error=="+e);
     }
 }


  public JCO.Client connectSAP() {
      try {
        System.out.println("sap");
          setmConnection(JCO.createClient("sapclient",
                "userName",
                "password",
                "en",
                "hostname",
                   "00"));
          System.out.println("sap connected");
      } catch (Exception ex) {
        System.out.println("error in conneting=="+ex);
      }
  return getmConnection();
 }

 public JCO.Function createFunction(String name) throws Exception {
        try {
            IFunctionTemplate ft = mRepository.getFunctionTemplate(name.toUpperCase());
            if (ft == null) {
                return null;
            }
            return ft.getFunction();
        } catch (Exception ex) {
            throw new Exception("Problem retrieving JCO.Function object." + ex);
        }
    }


public void bapi(String accountNO, String companyCode, String po, String indicator){
    System.out.println("bapiex");
    connectDev();

}

public static void main(String args[]){
    ExecuteBapi bapi = new ExecuteBapi();
    connectDev();
}

/**
 * @return the mConnection
 */
public JCO.Client getmConnection() {
    return mConnection;
}

/**
 * @param mConnection the mConnection to set
 */
public void setmConnection(JCO.Client mConnection) {
    this.mConnection = mConnection;
}
}

所以这里我们运行ExcecuteBapi类manualy SAP会连接,但我们在webservice中运行这个方法它会抛出错误

org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError:com/sap/mw/jco/JCO

请帮帮我。

0 个答案:

没有答案