none
webservice中的jndi问题 RRS feed

  • 问题

  • 项目需要通过jndi获得远程ejb对象,在把相应的操作发布成web service供.net调用

    直接通过JNDI访问没有问题,web service发布也没问题,可以查看wsdl,但是在web service服务端里使用JNDI获得远程EJB就报错了

    难道在web service中不能使用jndi???

    提供的service方法为:
    public FindCdmaResponse findCdma(FindCdmaRequest request) {

    FindCdmaResponse response = new FindCdmaResponse();

    try {
    OSSInterface oss = JNDIUtil.getOSSInterface();

    List list = oss.findCdmaAccNbrByWHRX(request.getDistNbr(), request.getNxxNbr(), request.getLineNbr(), request.getCount(), request.getLocalNetId());

    PhoneNumber[] numbers = new PhoneNumber[list.size()];
    for (int i = 0; i < list.size(); i++) {
    Map m = (Map) list.get(i);
    numbers[i] = new PhoneNumber();
    numbers[i].setAccNbr((String) m.get("AccNbr"));
    numbers[i].setAreaId((String) m.get("AreaId"));
    numbers[i].setAccNbrClassId((String) m.get("AccNbrClassId"));
    numbers[i].setAccNbrClassName((String) m.get("AccNbrClassName"));
    numbers[i].setAgentId((String) m.get("AgentId"));
    numbers[i].setWorkAreaId((String) m.get("WorkAreaId"));
    numbers[i].setWorkAreaName((String) m.get("WorkAreaName"));
    numbers[i].setIsAdvance((String) m.get("IsAdvance"));
    }

    response.set_return(numbers);
    } catch (RemoteException e) {
    e.printStackTrace();
    } catch (CreateException e) {
    e.printStackTrace();
    } catch (NoDataException e) {
    e.printStackTrace();
    } catch (InterfaceException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }

    return response;
    }

    public class JNDIUtil {

    private static final String JNDI_NAME = "OSSInterface";
    private static final String PROVIDER_URL = "t3://133.0.176.229:5001";
    private static final String SECURITY_PRINCIPAL = "weblogic";
    private static final String SECURITY_CREDENTIALS = "weblogic";

    public static Context getInitialContext() throws Exception {
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, PROVIDER_URL);
    p.put(Context.SECURITY_PRINCIPAL, SECURITY_PRINCIPAL);
    p.put(Context.SECURITY_CREDENTIALS, SECURITY_CREDENTIALS);

    return new InitialContext(p);
    }

    public static OSSInterface getOSSInterface() throws Exception {

    Context cxt = getInitialContext();
    Object objRef = cxt.lookup(JNDI_NAME);
    OSSInterfaceHome home = (OSSInterfaceHome) PortableRemoteObject.narrow(
    objRef, OSSInterfaceHome.class);

    return home.create();
    }

    }

    直接通过JNDI访问
    public class JNDITest {

    /**

    • @param args
    */
    public static void main(String[] args) {

    try {
    OSSInterface oss = JNDIUtil.getOSSInterface();

    List list = oss.findCdmaAccNbrByWHRX("027", "1330", "%29%",new Integer(10), new Integer(1001));

    for (int i = 0; i < list.size(); i++) {
    System.out.println(i + ":" + list.get(i));
    }
    } catch (RemoteException e) {
    e.printStackTrace();
    } catch (CreateException e) {
    e.printStackTrace();
    } catch (InterfaceException e) {
    e.printStackTrace();
    } catch (NoDataException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    }

    通过客户端调用
    public void testfindCdma() throws java.lang.Exception {

    String url = "http://localhost:8080/axis2/services/QiangHaoService";
    QiangHaoServiceStub stub = new QiangHaoServiceStub(url);
    FindCdmaRequest request = (FindCdmaRequest) getTestObject(FindCdmaRequest.class);

    request.setDistNbr("027");
    request.setNxxNbr("1330");
    request.setLineNbr("%29%");
    request.setCount(10);
    request.setLocalNetId(1001);
    PhoneNumber[] numbers = stub.findCdma(request).get_return();
    for (int i = 0; i < numbers.length; i++) {
    System.out.println(numbers[i].getAccNbr() + "," + numbers[i].getWorkAreaId() + ","
    + numbers[i].getAccNbrClassId() + "," + numbers[i].getAccNbrClassName() + ","
    + numbers[i].getAgentId() + "," + numbers[i].getWorkAreaId() + ","
    + numbers[i].getWorkAreaName() + "," + numbers[i].getIsAdvance());
    }
    assertNotNull(stub.findCdma(request));

    }

    错误日志
    org.apache.axis2.AxisFault: weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Failed to generate class for com.cattsoft.ibss.hub.intf.OSSInterface_trgpb2_HomeImpl_815_WLStub ] - with nested exception:
    [java.lang.reflect.InvocationTargetException - with target exception:
    [java.lang.IllegalAccessError: tried to access method weblogic.rmi.internal.StubInfo.getInterfaces(Ljava/lang/ClassLoader;)[Ljava/lang/Class; from class com.cattsoft.ibss.hub.intf.OSSInterface_trgpb2_HomeImpl_815_WLStub]]
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
    at com.ws.QiangHaoServiceStub.findCdma(QiangHaoServiceStub.java:186)
    at test.QiangHaoServiceTest.testfindCdma(QiangHaoServiceTest.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    2009年6月8日 8:48

答案

全部回复