PDA

View Full Version : Java API sample publishrequestandwait


kevin
06-18-2003, 12:23
I'm trying to follow the documentation and build a Java program that will publish and wait for a document. In reading the Java API document it leads me to believe I don't need to build a callback method. However, I get an error if I don't.

Does anyone know the answer? How about some sample Java code?

Thanks in advance, ...Kevin

lsatkey
06-18-2003, 12:53
when you use the publishrequestandwait() you still need to implement the brokercallback interface and register a callback object, this is how the broker knows to send the document to you. this api saves you typing time for processing/handling all the tag related stuffs. however, this api blocks your process while waiting for reply, which sometimes may not be a good idea. you should find a java example in the enterprise sevrer installation directory on how to use it.

srdzak
06-18-2003, 13:09
You don't have to use a callback method, but not using one entails more administrative overhead in that you publish your request and then you have to poll your queue for the response. If your queue has multiple events in it, then it is up to you to reconcile which event matches up to your initial publish request.

By using callback methods, webMethods provides a much more efficient way to to do publish request and wait. It basically tags the event for match up and then delivers that matching reply right back to your doorstep saving you the hassle of polling and reconciling. Of course to do this requires that you register at least a General Callback handler.

So, if you want to use the BrokerClient.publishRequestAndWait() method your Java class needs to implement the BrokerCallback interface. Then before you invoke the publishRequestAndWait method, you need to registerCallback passing the "this" pointer of your Java object to the registerCallback method and you should be set!.

Hope this helps.

Steve

kevin
06-18-2003, 19:11
Thanks for all the information. It sure has helped!

Best Regards! ...Kevin

prasadba
11-06-2006, 16:15
Hi, Can you pls post a sample code for this issue. I am facing the same issue. it will be really helpful

prasadba
11-06-2006, 16:26
Below is my java code and i am getting the below error:
JavaCode:
import com.gepower.geps.common.eai.data.QueryPartLifeReplyStorage;
import com.gepower.geps.common.eai.data.QueryPartLifeRequestStorage;
import COM.activesw.api.client.BrokerClient;
import COM.activesw.api.client.BrokerConnectionDescriptor;
import COM.activesw.api.client.BrokerEvent;
import COM.activesw.api.client.*;
public class TestGenerator implements BrokerCallback {
public static void main(String args[]){
try{
System.out.println("******0000");
System.out.println("******1111");
QueryPartLifeRequestStorage objlQphRequest = new QueryPartLifeRequestStorage();
QueryPartLifeReplyStorage objlQphReply = new QueryPartLifeReplyStorage();
QueryPartLifeReplyStorage objlQphReplyFinal = null;
String strStatus = null;
String slStatus = null;
String temp = null;
BrokerClient client = new BrokerClient("3.209.5.12:6849",
"Broker #1", null, "IntegrationServer", "PLDB_EPDM_Service_Request_Client",null );
BrokerEvent document = new BrokerEvent(client,"wm::is::Canonical::QueryPartLife::QueryPartLifeRequestDoc");
objlQphRequest.PART_TYPE_ID = "GTTBRG001";
objlQphRequest.PART_TYPE = "BUCKET STAGE 1";
objlQphRequest.PART_SN = "C1SB083003";
objlQphRequest.PART_DWG = "103E5592P001";
document.fromObject(objlQphRequest);
System.out.println("****b4 publish ***" );
System.out.println("****after Setting ToObject***" );
client.publish(document);
System.out.println("****after publish 1***" );
BrokerEvent replyEvent[] = client.publishRequestAndWait(document, 600000);
System.out.println("after publish and wait");
System.out.println("****replyEvent[0] ***" + replyEvent[0].getBaseTypeName());
} catch (Exception me) {
me.printStackTrace();
}
}
Error:
Bad State (200-1001): Cannot register callback for a tag before registering a ge
neral callback
at COM.activesw.api.client.BrokerClient.registerCallbackForTagInternal(B
rokerClient.java:6328)
at COM.activesw.api.client.BrokerClient.publishRequestAndWaitInternal(Br
okerClient.java:2722)
at COM.activesw.api.client.BrokerClient.publishRequestAndWait(BrokerClie
nt.java:2635)