You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by David Shere <ds...@steelerubber.com> on 2007/03/19 21:16:45 UTC

Service calling a service

I'm trying to write a java service that will call another service.  The 
other service takes three strings and a map as input.  This is what I 
have so far.

public static Map printLabel(DispatchContext dctx, Map context) {
     GenericDelegator delegator = dctx.getDelegator();

     String productId  = (String) context.get("productId");
     String producName = (String) context.get("productName");
     String printer    = (String) context.get("printer");

     // call service here with above parameters
     //
     //

     Map results = ServiceUtil.returnSuccess();
     return results;
}

Am on the right track?

-- 
David Shere
Information Technology Services
Steele Rubber Products
www.SteeleRubber.com


Re: Service calling a service

Posted by Rishi Solanki <ri...@gmail.com>.
You can use it in different way:
At the service level use default-entity-name="TicketBookingDetails" if you
want to use other entity then use <auto-attributes mode="IN" include="pk"
optional="true" entity-name="PaymentDetails"/>

The auto-attributes override the default-entity-name setting otherwise it
takes the default-entity. Another way to do this, just include the
additional parameters as in and add their implementation - <attribute
name="expYear" type="String" mode="IN" optional="true"/>

There is no other-entity-name attribute available at service definition
level tags.

HTH!

--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com


On Fri, Jun 29, 2012 at 11:42 AM, madhu <ma...@lntinfotech.com>wrote:

> hi,
> i want to insert data in 2 entities in one service call.for that i wrote
> the
> following service
>
> <service name="updateStatus" engine="java"
> default-entity-name="TicketBookingDetails"
> other-entity-name="PaymentDetails"
>                                location="org.ofbiz.eticket.ETicket_booking"
> invoke="updateStatus_TicketBooking" auth="false">
>                <description>Update TicketBookingDetails</description>
>                <auto-attributes mode="IN" include="pk" optional="true"/>
>                <auto-attributes mode="IN" include="nonpk" optional="true"/>
>                                <attribute name="expMonth" type="String"
> mode="IN"  optional="true"/>
>                <attribute name="expYear" type="String" mode="IN"
> optional="true"/>
>        </service>
>
> can i give like this
> default-entity-name="TicketBookingDetails"
> other-entity-name="PaymentDetails"
> and
>
> in updateStatus_TicketBooking method i am calling another method.
>
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Service-calling-a-service-tp145137p4634193.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>

Re: Service calling a service

Posted by madhu <ma...@lntinfotech.com>.
hi,
i want to insert data in 2 entities in one service call.for that i wrote the
following service

<service name="updateStatus" engine="java"
default-entity-name="TicketBookingDetails"
other-entity-name="PaymentDetails"
				location="org.ofbiz.eticket.ETicket_booking"
invoke="updateStatus_TicketBooking" auth="false">
		<description>Update TicketBookingDetails</description>		
		<auto-attributes mode="IN" include="pk" optional="true"/>
		<auto-attributes mode="IN" include="nonpk" optional="true"/>
				<attribute name="expMonth" type="String" mode="IN"  optional="true"/>
		<attribute name="expYear" type="String" mode="IN" optional="true"/>				
	</service>

can i give like this
default-entity-name="TicketBookingDetails"
other-entity-name="PaymentDetails"
and 

in updateStatus_TicketBooking method i am calling another method.


--
View this message in context: http://ofbiz.135035.n4.nabble.com/Service-calling-a-service-tp145137p4634193.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Service calling a service

Posted by David Shere <ds...@steelerubber.com>.
Come to North Carolina.  We have sea and mountains!

Jacopo Cappellato wrote:
> really? And where I'm supposed to have my vacation? Sea or mountains? :-)

-- 
David Shere
Information Technology Services
Steele Rubber Products
www.SteeleRubber.com


Re: Service calling a service

Posted by Jacopo Cappellato <ti...@sastau.it>.
David,

David Shere wrote:
> ...
> Jacopo has been very helpful to (and patient with) me on this issue, but 
> he's on vacation for the next few days.
> 

really? And where I'm supposed to have my vacation? Sea or mountains? :-)

Unfortunately this is not really true, and I don't know what I wrote you 
that could have made you believe that I was going to be on vacation.

 From office,

Jacopo



Re: Service calling a service

Posted by Walter Vaughan <wv...@steelerubber.com>.
Jacopo Cappellato wrote:
> David, all,
> 
> I'd like to clarify that this issue is not strictly related to OFBiz and 
> service calls.
> It is an issue probably caused by my ignorance on the usage of the 
> javax.print API:
> 
> http://java.sun.com/j2se/1.4.2/docs/api/javax/print/package-summary.html

DavidS said you were looking for code to discover lan printers. I definately 
don't understand the one-dimension java printing tools, but I posted two 
snippets of code at
http://forum.java.sun.com/thread.jspa?threadID=216673&start=17&tstart=0

Here's code to find printers that the machine the javaVM is running in knows 
about. This code works, but needs cleanups since I think it imports too much 
stuff. And I am NOT a java coder. This is only Proof of Concept.

<code>

import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.attribute.AttributeSetUtilities.*;

public class Eltron3 {

         public static void main(String[] args) {
                 PrintService psZebra = null;
                 String sPrinterName = null;
                 PrintService[] services = 
PrintServiceLookup.lookupPrintServices(null, null);
                 for (int i = 0; i < services.length; i++) {
                         PrintServiceAttribute attr = 
services[i].getAttribute(PrinterName.class);
                         sPrinterName = ((PrinterName)attr).getValue();
                         System.out.println("Found printer: " + sPrinterName + 
"\n");
                 }
                 System.out.println("Finshed\n");
         }
}


</code>

See the link for the code to print to a named printer with a byte stream.
--
Walter

Re: Service calling a service

Posted by Jacopo Cappellato <ti...@sastau.it>.
David, all,

I'd like to clarify that this issue is not strictly related to OFBiz and 
service calls.
It is an issue probably caused by my ignorance on the usage of the 
javax.print API:

http://java.sun.com/j2se/1.4.2/docs/api/javax/print/package-summary.html

In that service I've just tried to implement what is described at the 
bottom of that page; to that, I've added the code to search for a 
printer by its URI.
Unfortunately, this is really the first time I play with this java api 
and I'm not even sure if the approach I've followed is correct.
Even if this is a bit off topic in this list, if you could provide 
suggestions on how to locate a lan printer (by printer name/address) 
using the javax.printer api, I promise I will fix that service.

David, if it is simpler for you, you could try to implement a simple 
Java class (following the pattern used in the above link) and try to 
print a file with it; once you understand how this can be done I'll move 
the code to the OFBiz service.
A second option could be to try to post this question ("How do I locate 
and print to a lan printer using javax.print api?") to one of the many 
Java forums in the Internet

Jacopo

David Shere wrote:
> I have tried this, and have had no luck.  I'm using this in 
> WorkWithShipmentPlans.bsh:
> 
> //----------
> Map screenInMap = UtilMisc.toMap("orderId", "WS10000");
> String printerName = "LaserJet-2420";
> Map inMap = UtilMisc.toMap("screenLocation",
> "component://order/widget/ordermgr/OrderPrintForms.xml#ShipGroupsPDF",
> "printerName", printerName,
> "userLogin", userLogin,
> "screenContext", screenInMap);
> 
> dispatcher.runAsync("sendPrintFromScreen", inMap);
> //------------
> 
> and I've modified this line in PrintServices.java:
> 
> //------------
> String errMsg = "The following printer was not found: [" + 
> printerUriObj.toString() + "].";
> //------------
> 
> and I've verified that I can print to this printer from Linux:
> 
> //------------
> admin@raptor:~$ lpstat -dP
> system default destination: LaserJet-2420
> admin@raptor:~$ lpr -P LaserJet-2420 planes
> //------------
> 
> and I get this error message in the OfBiz Log:
> 
> //------------
> 
> 2007-03-21 16:25:25,617 (default-invoker-Thread-2) [ 
> PrintServices.java:159:ERROR] The following printer was not found: 
> [LaserJet-2420].
> 2007-03-21 16:25:25,618 (default-invoker-Thread-2) [ 
> ServiceDispatcher.java:415:ERROR] Service Error [sendPrintFromScreen]: 
> The following printer was not found: [LaserJet-2420].
> 2007-03-21 16:25:25,618 (default-invoker-Thread-2) [ 
> TransactionUtil.java:252:ERROR]
> ---- exception report 
> ----------------------------------------------------------
> [TransactionUtil.rollback]
> Exception: java.lang.Exception
> Message: Stack Trace
> ---- stack trace 
> ---------------------------------------------------------------
> java.lang.Exception: Stack Trace
> org.ofbiz.entity.transaction.TransactionUtil.rollback(TransactionUtil.java:251) 
> 
> org.ofbiz.entity.transaction.TransactionUtil.rollback(TransactionUtil.java:233) 
> 
> org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:419)
> org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:211)
> org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:136)
> org.ofbiz.service.job.GenericServiceJob.exec(GenericServiceJob.java:70)
> org.ofbiz.service.job.JobInvoker.run(JobInvoker.java:221)
> java.lang.Thread.run(Thread.java:595)
> -------------------------------------------------------------------------------- 
> 
> 
> 2007-03-21 16:25:25,620 (default-invoker-Thread-2) [ 
> TransactionUtil.java:262:INFO ] [TransactionUtil.rollback] transaction 
> rolled back
> 2007-03-21 16:25:25,621 (default-invoker-Thread-2) [ 
> ServiceDispatcher.java:459:DEBUG] [[Sync service finished- 
> total:1.922,since last(Begin):1.923]] - 'JobDispatcher / 
> sendPrintFromScreen'
> 2007-03-21 16:25:25,621 (default-invoker-Thread-2) [ 
> GenericServiceJob.java:117:ERROR]
> ---- exception report 
> ----------------------------------------------------------
> Async-Service failed.
> Exception: java.lang.Exception
> Message: The following printer was not found: [LaserJet-2420].
> ---- stack trace 
> ---------------------------------------------------------------
> java.lang.Exception: The following printer was not found: [LaserJet-2420].
> org.ofbiz.service.job.GenericServiceJob.exec(GenericServiceJob.java:76)
> org.ofbiz.service.job.JobInvoker.run(JobInvoker.java:221)
> java.lang.Thread.run(Thread.java:595)
> -------------------------------------------------------------------------------- 
> 
> //-----------
> 
> Thoughts?
> 
> 
> Jacopo Cappellato wrote:
>> Yes, literally millions of examples.
>>
>> However, this morning I've committed a first draft of the service in 
>> svn so I'd suggest you to update your local copy with a clean trunk 
>> and then you can test it, for example, in this way:
>>
>> //============================
>> Map screenInMap = UtilMisc.toMap("orderId", orderId);
>> Map inMap = UtilMisc.toMap("screenLocation",
>> "component://order/widget/ordermgr/OrderPrintForms.xml#OrderPDF",
>> "printerName", "//server/printer",
>> "userLogin", userLogin,
>> "screenContext", screenInMap);
>>
>> dispatcher.runAsync("sendPrintFromScreen", inMap);
>> //============================
>>
>> A quick way to run this code is to copy it at the bottom of a bsh 
>> script, for example:
>> applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/WorkWithShipmentPlans.bsh 
>>
>>
>> then you'll submit the service call every time you'll visit the page:
>>
>> https://localhost:8443/manufacturing/control/WorkWithShipmentPlans
>>
>> You can edit the bsh script without the need to build and restart the 
>> server.
>>
>> Jacopo
>>
>>
>> Scott Gray wrote:
>>> I think it's a LocalDispatcher, but don't quote me on that.  Anyway 
>>> there's
>>> a million examples in code, just search for runSync
>>>
>>>
>>> On 20/03/07, David Shere <ds...@steelerubber.com> wrote:
>>>>
>>>> Thanks!  That's the line I was missing.  I must ask, though, what class
>>>> is "dispatcher" and how do I construct it?
>>>>
>>>> (I think I was dealing with ServiceXaWrapper)
>>>>
>>>> Scott Gray wrote:
>>>> > Map results = dispatcher.runSync("myService", inputMap);
>>>>
>>>>
>>>
>>
>>
> 



Re: Service calling a service

Posted by David Shere <ds...@steelerubber.com>.
I have tried this, and have had no luck.  I'm using this in 
WorkWithShipmentPlans.bsh:

//----------
Map screenInMap = UtilMisc.toMap("orderId", "WS10000");
String printerName = "LaserJet-2420";
Map inMap = UtilMisc.toMap("screenLocation",
"component://order/widget/ordermgr/OrderPrintForms.xml#ShipGroupsPDF",
"printerName", printerName,
"userLogin", userLogin,
"screenContext", screenInMap);

dispatcher.runAsync("sendPrintFromScreen", inMap);
//------------

and I've modified this line in PrintServices.java:

//------------
String errMsg = "The following printer was not found: [" + 
printerUriObj.toString() + "].";
//------------

and I've verified that I can print to this printer from Linux:

//------------
admin@raptor:~$ lpstat -dP
system default destination: LaserJet-2420
admin@raptor:~$ lpr -P LaserJet-2420 planes
//------------

and I get this error message in the OfBiz Log:

//------------

2007-03-21 16:25:25,617 (default-invoker-Thread-2) [ 
PrintServices.java:159:ERROR] The following printer was not found: 
[LaserJet-2420].
2007-03-21 16:25:25,618 (default-invoker-Thread-2) [ 
ServiceDispatcher.java:415:ERROR] Service Error [sendPrintFromScreen]: 
The following printer was not found: [LaserJet-2420].
2007-03-21 16:25:25,618 (default-invoker-Thread-2) [ 
TransactionUtil.java:252:ERROR]
---- exception report 
----------------------------------------------------------
[TransactionUtil.rollback]
Exception: java.lang.Exception
Message: Stack Trace
---- stack trace 
---------------------------------------------------------------
java.lang.Exception: Stack Trace
org.ofbiz.entity.transaction.TransactionUtil.rollback(TransactionUtil.java:251)
org.ofbiz.entity.transaction.TransactionUtil.rollback(TransactionUtil.java:233)
org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:419)
org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:211)
org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:136)
org.ofbiz.service.job.GenericServiceJob.exec(GenericServiceJob.java:70)
org.ofbiz.service.job.JobInvoker.run(JobInvoker.java:221)
java.lang.Thread.run(Thread.java:595)
--------------------------------------------------------------------------------

2007-03-21 16:25:25,620 (default-invoker-Thread-2) [ 
TransactionUtil.java:262:INFO ] [TransactionUtil.rollback] transaction 
rolled back
2007-03-21 16:25:25,621 (default-invoker-Thread-2) [ 
ServiceDispatcher.java:459:DEBUG] [[Sync service finished- 
total:1.922,since last(Begin):1.923]] - 'JobDispatcher / 
sendPrintFromScreen'
2007-03-21 16:25:25,621 (default-invoker-Thread-2) [ 
GenericServiceJob.java:117:ERROR]
---- exception report 
----------------------------------------------------------
Async-Service failed.
Exception: java.lang.Exception
Message: The following printer was not found: [LaserJet-2420].
---- stack trace 
---------------------------------------------------------------
java.lang.Exception: The following printer was not found: [LaserJet-2420].
org.ofbiz.service.job.GenericServiceJob.exec(GenericServiceJob.java:76)
org.ofbiz.service.job.JobInvoker.run(JobInvoker.java:221)
java.lang.Thread.run(Thread.java:595)
--------------------------------------------------------------------------------
//-----------

Thoughts?


Jacopo Cappellato wrote:
> Yes, literally millions of examples.
> 
> However, this morning I've committed a first draft of the service in svn 
> so I'd suggest you to update your local copy with a clean trunk and then 
> you can test it, for example, in this way:
> 
> //============================
> Map screenInMap = UtilMisc.toMap("orderId", orderId);
> Map inMap = UtilMisc.toMap("screenLocation",
> "component://order/widget/ordermgr/OrderPrintForms.xml#OrderPDF",
> "printerName", "//server/printer",
> "userLogin", userLogin,
> "screenContext", screenInMap);
> 
> dispatcher.runAsync("sendPrintFromScreen", inMap);
> //============================
> 
> A quick way to run this code is to copy it at the bottom of a bsh 
> script, for example:
> applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/WorkWithShipmentPlans.bsh 
> 
> 
> then you'll submit the service call every time you'll visit the page:
> 
> https://localhost:8443/manufacturing/control/WorkWithShipmentPlans
> 
> You can edit the bsh script without the need to build and restart the 
> server.
> 
> Jacopo
> 
> 
> Scott Gray wrote:
>> I think it's a LocalDispatcher, but don't quote me on that.  Anyway 
>> there's
>> a million examples in code, just search for runSync
>>
>>
>> On 20/03/07, David Shere <ds...@steelerubber.com> wrote:
>>>
>>> Thanks!  That's the line I was missing.  I must ask, though, what class
>>> is "dispatcher" and how do I construct it?
>>>
>>> (I think I was dealing with ServiceXaWrapper)
>>>
>>> Scott Gray wrote:
>>> > Map results = dispatcher.runSync("myService", inputMap);
>>>
>>>
>>
> 
> 

-- 
David Shere
Information Technology Services
Steele Rubber Products
www.SteeleRubber.com


Re: Service calling a service

Posted by Jacopo Cappellato <ti...@sastau.it>.
Yes, literally millions of examples.

However, this morning I've committed a first draft of the service in svn 
so I'd suggest you to update your local copy with a clean trunk and then 
you can test it, for example, in this way:

//============================
Map screenInMap = UtilMisc.toMap("orderId", orderId);
Map inMap = UtilMisc.toMap("screenLocation",
"component://order/widget/ordermgr/OrderPrintForms.xml#OrderPDF",
"printerName", "//server/printer",
"userLogin", userLogin,
"screenContext", screenInMap);

dispatcher.runAsync("sendPrintFromScreen", inMap);
//============================

A quick way to run this code is to copy it at the bottom of a bsh 
script, for example:
applications/manufacturing/webapp/manufacturing/WEB-INF/actions/jobshopmgt/WorkWithShipmentPlans.bsh

then you'll submit the service call every time you'll visit the page:

https://localhost:8443/manufacturing/control/WorkWithShipmentPlans

You can edit the bsh script without the need to build and restart the 
server.

Jacopo


Scott Gray wrote:
> I think it's a LocalDispatcher, but don't quote me on that.  Anyway there's
> a million examples in code, just search for runSync
> 
> 
> On 20/03/07, David Shere <ds...@steelerubber.com> wrote:
>>
>> Thanks!  That's the line I was missing.  I must ask, though, what class
>> is "dispatcher" and how do I construct it?
>>
>> (I think I was dealing with ServiceXaWrapper)
>>
>> Scott Gray wrote:
>> > Map results = dispatcher.runSync("myService", inputMap);
>>
>>
> 


Re: Service calling a service

Posted by Scott Gray <le...@gmail.com>.
I think it's a LocalDispatcher, but don't quote me on that.  Anyway there's
a million examples in code, just search for runSync


On 20/03/07, David Shere <ds...@steelerubber.com> wrote:
>
> Thanks!  That's the line I was missing.  I must ask, though, what class
> is "dispatcher" and how do I construct it?
>
> (I think I was dealing with ServiceXaWrapper)
>
> Scott Gray wrote:
> > Map results = dispatcher.runSync("myService", inputMap);
>
>

Re: Service calling a service

Posted by David Shere <ds...@steelerubber.com>.
Thanks!  That's the line I was missing.  I must ask, though, what class 
is "dispatcher" and how do I construct it?

(I think I was dealing with ServiceXaWrapper)

Scott Gray wrote:
> Map results = dispatcher.runSync("myService", inputMap);


Re: Service calling a service

Posted by Scott Gray <le...@gmail.com>.
Hi David

You need to put all the parameters into a map and then pass that map to the
service call.
I can't remember the exact code but it goes like:

Map inputMap = UtilMisc.toMap("param1", param1);
 Map inputMap = UtilMisc.toMap("param2", param2);
Map results = dispatcher.runSync("myService", inputMap);

runSync needs to be surrounded with try/catch of course.

Regards
Scott

On 20/03/07, David Shere <ds...@steelerubber.com> wrote:
>
> Maybe I should clarify/restate.
>
> Jacopo wrote a service that sends a screen definition directly to a
> printer.  It takes as input:
>
> 1. screen definition
> 2. path to (network shared?) printer
> 3. contentType
> 4. body parameters
>
> 1-3 are strings and 4 is a map.  We tested this Friday, with #4 being
> blank, and everything worked beautifully.  I now want to test it while
> passing parameters to it.  I'm trying to figure out how I can pass a map
> to this service -- just enough implementation to see if it works.  I
> want to test it with the screen definition
> component://product/widget/catalog/ProductScreens.xml#ProductBarCode.fo
> so my body parameters would be productId and productName.
>
> You can see the service at
>
> https://ofbiz.davidshere.com:8443/webtools/control/availableServices?sel_service_name=sendPrintFromScreen
> or you can look at JIRA 823.  Part of the attached patch contains this
> service.
>
> Jacopo has been very helpful to (and patient with) me on this issue, but
> he's on vacation for the next few days.
>
> Thanks for any help you can provide.
>
> David Shere wrote:
> > I'm trying to write a java service that will call another service.  The
> > other service takes three strings and a map as input.  This is what I
> > have so far.
> >
>
>

Re: Service calling a service

Posted by David Shere <ds...@steelerubber.com>.
Maybe I should clarify/restate.

Jacopo wrote a service that sends a screen definition directly to a 
printer.  It takes as input:

1. screen definition
2. path to (network shared?) printer
3. contentType
4. body parameters

1-3 are strings and 4 is a map.  We tested this Friday, with #4 being 
blank, and everything worked beautifully.  I now want to test it while 
passing parameters to it.  I'm trying to figure out how I can pass a map 
to this service -- just enough implementation to see if it works.  I 
want to test it with the screen definition 
component://product/widget/catalog/ProductScreens.xml#ProductBarCode.fo 
so my body parameters would be productId and productName.

You can see the service at 
https://ofbiz.davidshere.com:8443/webtools/control/availableServices?sel_service_name=sendPrintFromScreen 
or you can look at JIRA 823.  Part of the attached patch contains this 
service.

Jacopo has been very helpful to (and patient with) me on this issue, but 
he's on vacation for the next few days.

Thanks for any help you can provide.

David Shere wrote:
> I'm trying to write a java service that will call another service.  The 
> other service takes three strings and a map as input.  This is what I 
> have so far.
>