Ankit
Ankit

Reputation: 157

Error while calling OfBiz service

I am new to OFBiz and I am creating the simple ofbiz service and referring this link http://www.packtpub.com/article/apache-ofbiz-service-engine-part1

I created practice project into hot-deployment.

I created services in servicedef/services.xml as below for 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>`

and created PracticeServices.java class into src.org.ofbiz.practice.practice pakcage and created method

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

and in my 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 is like below

    <?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>

and in controller.xml there is request mapping for showing learning form

     <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"/>

The learningForm in successfully opening. but when i click on submit button. it gives error in console like,

        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)

That error shows it can't locate the service that i defined. But can't understand where its going wrong. Please help me.

Thanks in advanced.
Ankit

Upvotes: 1

Views: 4594

Answers (1)

zgzlwm
zgzlwm

Reputation: 21

Our First Service `

the web service ....tht value of invoke=" " must be the same with

"org.ofbiz.practice.practice.PracticeServices" 's method , just like "learningFirstService"

Upvotes: 2

Related Questions