在Java WebService中创建MarkLogic客户端时出现ClassNotFount异常

时间:2017-06-29 17:19:46

标签: java web-services soap marklogic

我使用wsdl文件生成Java类,但我无法在端点创建MarkLogic客户端(它会抛出NoClassFound异常)。

端点代码:

/**
 * 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();
}

}

客户代码:

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();
    }

}

如果删除用于创建MarkLogic客户端的代码,一切正常。

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

1 个答案:

答案 0 :(得分:0)

在部署应用程序时,您似乎缺少一些罐子。 请确保您拥有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>
祝你好运!