REST Tutorial Not Working on Latest Version 16.11 Released

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

REST Tutorial Not Working on Latest Version 16.11 Released

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 ");
    }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: REST Tutorial Not Working on Latest Version 16.11 Released

Michael Brohl-3
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: REST Tutorial Not Working on Latest Version 16.11 Released

Lanzjess
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] <[hidden email]> 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



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.
NAML



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

Loading...