Exceptions details : java.lang.reflect.InvocationTargetException

I want to insert Data into cassandra database using a Web Service with java so I started with a class DBCOnnector to connect with database and a method InsertData to insert data this is the file DBConnector.java

 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package WS_cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.Metadata;
import com.datastax.driver.core.Session;

/**
 *
 * @author mon pc
 */
public class DBConnector {
    private Cluster cluster;
    private Session session;

    public  DBConnector() {
        this.cluster = Cluster.builder().addContactPoint("localhost").withPort(9042).build();
        final Metadata metadata = cluster.getMetadata();

        for (final Host host : metadata.getAllHosts()) {
            System.out.println("driver version " + host.getCassandraVersion());
        }

        this.session = cluster.connect();
    }

    public Session getSession() {
        return this.session;
    }
    public void setSession(Session session) {
        this.session = session;
    }

    public Cluster getCluster() {
        return cluster;
    }

    public void setCluster(Cluster cluster) {
        this.cluster = cluster;
    }
    public void close() {
        cluster.close();
    }
    
    public void insertData() {
    StringBuilder sb = new StringBuilder("INSERT INTO movies_keyspace.movies (title,year,descreiption) "
                    + "VALUES ('sara',10,'hhhh') ");

    String query = sb.toString();
    session.execute(query);
}
}

and this is the web service WS_Cassandra.java where I called the method InsertData :

package WS_cassandra;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

/**
 *
 * @author mon pc
 */
@WebService(serviceName = "WS_Cassandra")
public class WS_Cassandra {
    DBConnector d;

    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "insert")
    public String insert() {
        d=new DBConnector();
        d.insertData();
        return "yes";

    }
}

When I run the program I got this error :

WS00041: Service invocation threw an exception with message : null; Refer to the server log for more details
Exceptions details : java.lang.reflect.InvocationTargetException

javax.servlet.ServletException: java.lang.reflect.InvocationTargetExceptionat org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:342)at org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:106)at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:157)at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:313)... 32 more Caused by: com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: java.lang.ExceptionInInitializerError Please see the server log to find more detail regarding exact cause of the failure.at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:128)at com.sun.xml.ws.client.sei.StubHandler.readResponse(StubHandler.java:253)at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:203)at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:290)at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:92)at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:161)at com.sun.proxy.$Proxy278.insert(Unknown Source)... 37 more ```
any solution ? 


Read more here: https://stackoverflow.com/questions/65708635/exceptions-details-java-lang-reflect-invocationtargetexception

Content Attribution

This content was originally published by Han Ane at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: