简体   繁体   English

在Java WebService中创建MarkLogic客户端时发生ClassNotFount异常

[英]ClassNotFount exception while creating MarkLogic client in Java WebService

I've used wsdl file to generate Java classes, but I can't create MarkLogic client in endpoint (it throws NoClassFound exception). 我已使用wsdl文件生成Java类,但是无法在端点中创建MarkLogic客户端(它会引发NoClassFound异常)。

Endpoint code: 端点代码:

/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package yu.ac.ns.ftn.informatika.ws.hello;

import java.util.logging.Logger;

import yu.ac.ns.ftn.informatika.ws.hello.types.RequestMissType;

import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.Authentication;

/**
 * This class was generated by Apache CXF 2.1.3
 * Fri Jan 23 09:13:16 CET 2009
 * Generated source version: 2.1.3
 * 
 */
@javax.ejb.Stateless
@javax.jws.WebService(
     serviceName = "HelloDocumentService",
     portName = "HelloDocumentPort",
     targetNamespace =   "http://informatika.ftn.ns.ac.yu/ws/hello",
     endpointInterface = "yu.ac.ns.ftn.informatika.ws.hello.HelloDocument")

public class HelloDocumentImpl implements HelloDocument {

private static final Logger LOG = 
Logger.getLogger(HelloDocumentImpl.class.getName());

/* (non-Javadoc)
 * @see 
yu.ac.ns.ftn.informatika.ws.hello.HelloDocument#sayHelloMiss
(yu.ac.ns.ftn.informatika.ws.hello.types.RequestMissType  requestMiss )*
 */


public java.lang.String sayHelloMiss(RequestMissType requestMiss) { 
    LOG.info("Executing operation sayHelloMiss");
    System.out.println(requestMiss);

    DatabaseClient client = 
      DatabaseClientFactory.newClient(
          "localhost", 8000,
          new DatabaseClientFactory.DigestAuthContext("user1", "user1"));
    System.out.println(client);



    return "Hello miss " + requestMiss.getFirstName() + " " + requestMiss.getLastName();
}

}

Client code: 客户代码:

package yu.ac.ns.ftn.informatika.ws.client;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import yu.ac.ns.ftn.informatika.ws.hello.HelloDocument;
import yu.ac.ns.ftn.informatika.ws.hello.HelloDocumentService;
import yu.ac.ns.ftn.informatika.ws.hello.types.RequestMissType;

public class HelloClient {

    public void testIt1() {

        try {
            URL wsdlLocation = new URL("http://localhost:8080/vezbe-wsdl-ws/services/HelloDocument?wsdl");
            QName serviceName = new QName("http://informatika.ftn.ns.ac.yu/ws/hello", "HelloDocumentService");
            QName portName = new QName("http://informatika.ftn.ns.ac.yu/ws/hello", "HelloDocumentPort");

            Service service = Service.create(wsdlLocation, serviceName);

            HelloDocument hello = service.getPort(portName, HelloDocument.class); 

            RequestMissType request = new RequestMissType();
            request.setFirstName("Dijana");
            request.setLastName("Ninkovic");

            String response = hello.sayHelloMiss(request);
            System.out.println("Response from WS: " + response);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        HelloClient client = new HelloClient();
        client.testIt1();
    }

}

If I delete code for creating MarkLogic client everything works fine. 如果删除用于创建MarkLogic客户端的代码,则一切正常。

Apache tomee exception: Apache tomee异常:

org.apache.catalina.LifecycleException: Failed to start component 
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/vezbe-wsdl-ws]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
 Caused by: java.lang.NoClassDefFoundError: com/marklogic/client/DatabaseClientFactory$SecurityContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetPublicMethods(Unknown Source)
    at java.lang.Class.getMethods(Unknown Source)
    at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.processApplicationExceptions(AnnotationDeployer.java:2657)
    at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2176)
    at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1662)
    at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:335)
    at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:363)
    at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:850)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:791)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:746)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:118)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: com.marklogic.client.DatabaseClientFactory$SecurityContext
    at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:114)
    at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:66)
    ... 27 more
Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read1(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at java.io.FilterInputStream.read(Unknown Source)
    at org.apache.openejb.loader.IO.copy(IO.java:279)
    at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:111)
    ... 28 more

It looks like you are missing some jars while deploying your application. 似乎在部署应用程序时缺少一些jar。 Please make sure you have your build.xml configuration set so it deploys all of marklogic jars you need. 请确保已设置build.xml配置,以便它部署所需的所有marklogic jar。

<target name="war" depends="compile">
    <delete file="${war.name}"/>
    <war warfile="${dist.dir}/${war.name}" webxml="${webinf.dir}/web.xml">
        <classes dir="${bin.dir}">
            <exclude name="**/client/*.class"/>
            <include name="**/*.class"/>
        </classes>
        <lib dir="${lib.dir}">
            <include name="*.jar"/>
        </lib>
        <webinf dir="${webinf.dir}">
            <include name="wsdl/**"/>
            <include name="cxf-servlet.xml"/>
        </webinf>
    </war>
</target>

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM