尝试创建Web服务

时间:2018-02-21 22:10:16

标签: java

我已经创建了一个转换为Web服务的方法,如下所示:

@WebMethod(operationName = "doCanny")
public void doCanny()
{
    try 
    {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat color = Imgcodecs.imread("C:\\Users\\bheda\\Desktop\\Cat03.jpg");


    Mat gray = new Mat();
    Mat draw = new Mat();
    Mat wide = new Mat();

    Imgproc.cvtColor(color, gray, Imgproc.COLOR_BGR2GRAY);
    Imgproc.Canny(gray, wide, 50, 150, 3, false);
    wide.convertTo(draw, CvType.CV_8U);

    if(Imgcodecs.imwrite("C:\\Users\\bheda\\Desktop\\Cat03.jpg", draw))
    {
        System.out.println("edge is detected .......");
    }
    }
    catch(Exception e)
    {

    }
}

当我部署并测试此Web服务时,我收到以下错误:

  

WS00041:服务调用引发了一个异常,消息为:null;   有关更多详细信息,请参阅服务器日志。例外详细信息:   java.lang.reflect.InvocationTargetException   javax.servlet.ServletException:   java.lang.reflect.InvocationTargetException at   org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:342)   在   org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:106)   在   org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:157)   在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at at   org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)   在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)   在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)   在   org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)   在   org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)   在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)at   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)   在   org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)   在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)   在   com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459)   在   com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)   在   org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)   在   org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)   在   org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)   在   org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)   在   org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)   在   org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)   在   org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)   在   org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)   在   org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)   在   org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)   在   org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)   在   org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)   在   org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56)   在   org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)   在   org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565)   在   org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545)   在java.lang.Thread.run(Thread.java:748)引起:   java.lang.reflect.InvocationTargetException at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:498)at   org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:313)   ... 32更多引起:com.sun.xml.ws.fault.ServerSOAPFaultException:   客户端从服务器收到SOAP Fault:没有opencv_java340 in   java.library.path请参阅服务器日志以查找更多详细信息   关于失败的确切原因。在   com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)   在   com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:131)   在   com.sun.xml.ws.client.sei.StubHandler.readResponse(StubHandler.java:253)   在   com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:203)   在   com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:290)   在   com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)   在   com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:92)   在com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:161)at   com.sun.proxy。$ Proxy313.doCanny(未知来源)... 37更多

我不确定我做错了什么。我认为这可能是我的文件路径,但我不确定。

1 个答案:

答案 0 :(得分:0)

no opencv_java340 in java.library.path 

是什么引起了错误。 Core.NATIVE_LIBRARY_NAME指向OpenCV本机库(Windows上的DLL文件,Linux上的文件)。启动Glassfish时,必须添加环境变量LD_LIBRARY_PATH并将其设置为OpenCV安装的路径。