You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Lanzjess <al...@gmail.com> on 2017/08/10 08:24:20 UTC

REST Tutorial Not Working on Latest Version 16.11 Released

I am following the REST tutorial
https://cwiki.apache.org/confluence/display/OFBIZ/Export+service+using+REST
but still fails for Latest Version 16.11 Released.          

LocalDispatcher dispatcher =
*GenericDispatcher*.getLocalDispatcher("default",delegator);

The above code in class PingResource  is not working. Currently, the class
GenericDispatcher is private as well as its constructor. 
//=========================================================================
package restcomponent;
 
 
import java.util.Map;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
 
import javolution.util.FastMap;
 
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.entity.DelegatorFactory;
import org.apache.ofbiz.entity.GenericDelegator;
import org.apache.ofbiz.service.GenericDispatcher;
import org.apache.ofbiz.service.GenericServiceException;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.service.ServiceUtil;
 
@Path("/ping")
public class PingResource {
 
    @GET
    @Produces("text/plain")
    @Path("{message}")
    public Response sayHello(@PathParam("message") String message) {
 
        GenericDelegator delegator = (GenericDelegator)
DelegatorFactory.getDelegator("default");
        LocalDispatcher dispatcher =
GenericDispatcher.getLocalDispatcher("default",delegator);
 
        Map<String, String> paramMap = UtilMisc.toMap( "message", message );
 
        Map<String, Object> result = FastMap.newInstance();
        try {
            result = dispatcher.runSync("ping", paramMap);
        } catch (GenericServiceException e1) {
            Debug.logError(e1, PingResource.class.getName());
            return Response.serverError().entity(e1.toString()).build();
        }
 
        if (org.apache.ofbiz.service.ServiceUtil.isSuccess(result)) {
            return Response.ok("RESPONSE: *** " + result.get("message") + "
***").type("text/plain").build();
        }
 
        if (org.apache.ofbiz.service.ServiceUtil.isError(result) ||
ServiceUtil.isFailure(result)) {
            return
Response.serverError().entity(ServiceUtil.getErrorMessage(result)).build();
        }
 
        // shouldn't ever get here ... should we?
        throw new RuntimeException("Invalid ");
    }
}



--
View this message in context: http://ofbiz.135035.n4.nabble.com/REST-Tutorial-Not-Working-on-Latest-Version-16-11-Released-tp4709425.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: REST Tutorial Not Working on Latest Version 16.11 Released

Posted by Lanzjess <al...@gmail.com>.
Hi Michael,

Yes I agree on that. That's why I am searching for the updated tutorial
about web service. Perhaps you could provide a REST implementation for
resource and client program.
I was able to use Axis2 Web Service Framework for a client program.

Regards,

On Sat, Aug 12, 2017 at 4:40 AM, Michael Brohl-3 [via OFBiz] <
ml+s135035n4709520h21@n4.nabble.com> wrote:

> Hi Allan,
>
> the mentioned tutorial is deprecated as stated in the information box on
> top of the article.
>
> Apache Wink is retired and there were several API changes recently. It
> is not recommended to follow this tuturial.
>
> Best regards,
>
> Michael Brohl
> ecomify GmbH
> www.ecomify.de
>
>
> Am 10.08.17 um 10:24 schrieb Lanzjess:
>
> > I am following the REST tutorial
> > https://cwiki.apache.org/confluence/display/OFBIZ/
> Export+service+using+REST
> > but still fails for Latest Version 16.11 Released.
> >
> > LocalDispatcher dispatcher =
> > *GenericDispatcher*.getLocalDispatcher("default",delegator);
> >
> > The above code in class PingResource  is not working. Currently, the
> class
> > GenericDispatcher is private as well as its constructor.
> > //=========================================================================
>
> > package restcomponent;
> >
> >
> > import java.util.Map;
> >
> > import javax.ws.rs.GET;
> > import javax.ws.rs.Path;
> > import javax.ws.rs.PathParam;
> > import javax.ws.rs.Produces;
> > import javax.ws.rs.core.Context;
> > import javax.ws.rs.core.HttpHeaders;
> > import javax.ws.rs.core.Response;
> >
> > import javolution.util.FastMap;
> >
> > import org.apache.ofbiz.base.util.Debug;
> > import org.apache.ofbiz.base.util.UtilMisc;
> > import org.apache.ofbiz.entity.DelegatorFactory;
> > import org.apache.ofbiz.entity.GenericDelegator;
> > import org.apache.ofbiz.service.GenericDispatcher;
> > import org.apache.ofbiz.service.GenericServiceException;
> > import org.apache.ofbiz.service.LocalDispatcher;
> > import org.apache.ofbiz.service.ServiceUtil;
> >
> > @Path("/ping")
> > public class PingResource {
> >
> >      @GET
> >      @Produces("text/plain")
> >      @Path("{message}")
> >      public Response sayHello(@PathParam("message") String message) {
> >
> >          GenericDelegator delegator = (GenericDelegator)
> > DelegatorFactory.getDelegator("default");
> >          LocalDispatcher dispatcher =
> > GenericDispatcher.getLocalDispatcher("default",delegator);
> >
> >          Map<String, String> paramMap = UtilMisc.toMap( "message",
> message );
> >
> >          Map<String, Object> result = FastMap.newInstance();
> >          try {
> >              result = dispatcher.runSync("ping", paramMap);
> >          } catch (GenericServiceException e1) {
> >              Debug.logError(e1, PingResource.class.getName());
> >              return Response.serverError().entity(e1.toString()).build();
>
> >          }
> >
> >          if (org.apache.ofbiz.service.ServiceUtil.isSuccess(result)) {
> >              return Response.ok("RESPONSE: *** " + result.get("message")
> + "
> > ***").type("text/plain").build();
> >          }
> >
> >          if (org.apache.ofbiz.service.ServiceUtil.isError(result) ||
> > ServiceUtil.isFailure(result)) {
> >              return
> > Response.serverError().entity(ServiceUtil.getErrorMessage(result)).build();
>
> >          }
> >
> >          // shouldn't ever get here ... should we?
> >          throw new RuntimeException("Invalid ");
> >      }
> > }
> >
> >
> >
> > --
> > View this message in context: http://ofbiz.135035.n4.nabble.
> com/REST-Tutorial-Not-Working-on-Latest-Version-16-11-
> Released-tp4709425.html
> > Sent from the OFBiz - User mailing list archive at Nabble.com.
>
>
> *smime.p7s* (5K) Download Attachment
> <http://ofbiz.135035.n4.nabble.com/attachment/4709520/0/smime.p7s>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://ofbiz.135035.n4.nabble.com/REST-Tutorial-Not-Working-
> on-Latest-Version-16-11-Released-tp4709425p4709520.html
> To unsubscribe from REST Tutorial Not Working on Latest Version 16.11
> Released, click here
> <http://ofbiz.135035.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4709425&code=YWxsYW4uemFyc3VlbGFAZ21haWwuY29tfDQ3MDk0MjV8LTEzMTY0MjA4MDI=>
> .
> NAML
> <http://ofbiz.135035.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



-- 
*Allan L. Zarsuela*
*Systems Analyst/Programmer*
Cellphone number: +971-5221-40525




--
View this message in context: http://ofbiz.135035.n4.nabble.com/REST-Tutorial-Not-Working-on-Latest-Version-16-11-Released-tp4709425p4709706.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: REST Tutorial Not Working on Latest Version 16.11 Released

Posted by Michael Brohl <mi...@ecomify.de>.
Hi Allan,

the mentioned tutorial is deprecated as stated in the information box on 
top of the article.

Apache Wink is retired and there were several API changes recently. It 
is not recommended to follow this tuturial.

Best regards,

Michael Brohl
ecomify GmbH
www.ecomify.de


Am 10.08.17 um 10:24 schrieb Lanzjess:
> I am following the REST tutorial
> https://cwiki.apache.org/confluence/display/OFBIZ/Export+service+using+REST
> but still fails for Latest Version 16.11 Released.
>
> LocalDispatcher dispatcher =
> *GenericDispatcher*.getLocalDispatcher("default",delegator);
>
> The above code in class PingResource  is not working. Currently, the class
> GenericDispatcher is private as well as its constructor.
> //=========================================================================
> package restcomponent;
>   
>   
> import java.util.Map;
>   
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.HttpHeaders;
> import javax.ws.rs.core.Response;
>   
> import javolution.util.FastMap;
>   
> import org.apache.ofbiz.base.util.Debug;
> import org.apache.ofbiz.base.util.UtilMisc;
> import org.apache.ofbiz.entity.DelegatorFactory;
> import org.apache.ofbiz.entity.GenericDelegator;
> import org.apache.ofbiz.service.GenericDispatcher;
> import org.apache.ofbiz.service.GenericServiceException;
> import org.apache.ofbiz.service.LocalDispatcher;
> import org.apache.ofbiz.service.ServiceUtil;
>   
> @Path("/ping")
> public class PingResource {
>   
>      @GET
>      @Produces("text/plain")
>      @Path("{message}")
>      public Response sayHello(@PathParam("message") String message) {
>   
>          GenericDelegator delegator = (GenericDelegator)
> DelegatorFactory.getDelegator("default");
>          LocalDispatcher dispatcher =
> GenericDispatcher.getLocalDispatcher("default",delegator);
>   
>          Map<String, String> paramMap = UtilMisc.toMap( "message", message );
>   
>          Map<String, Object> result = FastMap.newInstance();
>          try {
>              result = dispatcher.runSync("ping", paramMap);
>          } catch (GenericServiceException e1) {
>              Debug.logError(e1, PingResource.class.getName());
>              return Response.serverError().entity(e1.toString()).build();
>          }
>   
>          if (org.apache.ofbiz.service.ServiceUtil.isSuccess(result)) {
>              return Response.ok("RESPONSE: *** " + result.get("message") + "
> ***").type("text/plain").build();
>          }
>   
>          if (org.apache.ofbiz.service.ServiceUtil.isError(result) ||
> ServiceUtil.isFailure(result)) {
>              return
> Response.serverError().entity(ServiceUtil.getErrorMessage(result)).build();
>          }
>   
>          // shouldn't ever get here ... should we?
>          throw new RuntimeException("Invalid ");
>      }
> }
>
>
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/REST-Tutorial-Not-Working-on-Latest-Version-16-11-Released-tp4709425.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.