调用OfBiz服务时出错

时间:2013-04-22 06:50:35

标签: ofbiz

我是OFBiz的新手,我正在创建简单的ofbiz服务并引用此链接http://www.packtpub.com/article/apache-ofbiz-service-engine-part1

我将练习项目创建为热部署。

我在servicedef / services.xml中创建了如下的learningFirstService.xml

服务
`<service name="learningFirstService" engine="java"
        location="org.ofbiz.practice.practice.PracticeServices" invoke="handleParameters">
        <description>Our First Service</description>
        <attribute name="firstName" type="String" mode="IN" optional="true" />
        <attribute name="lastName" type="String" mode="IN" optional="true" />
    </service>`

并在src.org.ofbiz.practice.practice pakcage中创建了PracticeServices.java类 并创建了方法

    public static Map learningFirstService(DispatchContext dctx, Map context){

        System.out.println("learning first service called");
        Map resultMap = ServiceUtil.returnSuccess("You have called on service 'learningFirstService' successfully!");
        return resultMap;
    }

和我的ofbiz-component.xml

    <?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="practice"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
      <resource-loader  name="main" type="component"/>

      <service-resource type="model" loader="main" location="servicedef/services.xml"/>

    <webapp name="practice"
       title="Practice"
       server="default-server"
       base-permission="OFBTOOLS"
       location="webapp/practice"
       mount-point="/practice"
       app-bar-display="true"/>
    <classpath type="dir" location="config"/>


</ofbiz-component>

learningforms.xml如下所示

    <?xml version="1.0" encoding="UTF-8"?>
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-form.xsd">

    <form name="TestingServices" type="single" target="${formTarget}">
        <field name="firstName"><text/></field>
        <field name="lastName"><text/></field>
        <field name="planetId"><text/></field>
        <field name="submit"><submit/></field>
    </form>
</forms>

并且在controller.xml中有用于显示学习表单的请求映射

     <request-map uri="TestFirstService">
            <event type="service" invoke="learningFirstService" />
            <response name="success" type="view" value="TestFirstService" />
        </request-map>
    <view-map name="TestFirstService" type="screen" page="component://practice/widget/PracticeScreens.xml#learningForm"/>

学习形式成功开放。但是当我点击提交按钮时。它在控制台中出错,

        Error in request handler: 
    Exception: org.ofbiz.webapp.event.EventHandlerException
    Message: Problems getting the service model (Cannot locate service by name (learningFirstService))
    ---- cause ---------------------------------------------------------------------
    Exception: org.ofbiz.service.GenericServiceException
    Message: Cannot locate service by name (learningFirstService)
    ---- stack trace ---------------------------------------------------------------
    org.ofbiz.service.GenericServiceException: Cannot locate service by name (learningFirstService)
    org.ofbiz.service.DispatchContext.getModelService(DispatchContext.java:191)
    org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:116)
    org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:648)
    org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:394)
    org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:224)
    org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:87)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:339)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:619)

该错误表明它无法找到我定义的服务。但无法理解它出错的地方。请帮帮我。

先谢谢。
ANKIT

1 个答案:

答案 0 :(得分:2)

        我们的第一服务                       `

Web服务.... invoke =“”的值必须与

相同

“org.ofbiz.practice.practice.PracticeServices”的方法,就像“learningFirstService”