You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Maicon Stihler <st...@gmail.com> on 2007/12/01 02:22:35 UTC
Re: [Axis2] Calling a service from another service
Well, even though I use the muse API to craft a notification message,
I don't use it to invoke the remote service. If I try to send the
notification message from a command line client it works fine, that's
why I have a feeling that I'm doing something wrong in the way I call
the service inside this first service.
I'll make some tests with other kinds of services to make sure that
the problem isn't with Axis.
thank you
2007/11/30, Martin Gainty <mg...@hotmail.com>:
> Hi Maicon
>
> This is a muse webapp ..did you contact the muse folks at
> muse-user-subscribe@ws.apache.org
>
> ?
> M--
> ----- Original Message -----
> From: "Maicon Stihler" <st...@gmail.com>
> To: <ax...@ws.apache.org>
> Sent: Friday, November 30, 2007 4:50 PM
> Subject: Re: [Axis2] Calling a service from another service
>
>
> > 2007/11/30, Martin Gainty <mg...@hotmail.com>:
> > > Hi Maicon-
> > >
> > > 1)can we see the client code.. in particular the part which specifies
> the
> > > Action
> > The code is on the bottom of the email.
> >
> > > 2)Is there a reason why the client is not initiating all of the web
> service
> > > queries
> > I want the first service to notify this second service when being
> > invoked, this action must be transparent to the user because it's not
> > related to the application logic.
> >
> > Best regards,
> > Maicon
> >
> > obs: the code is really ugly, I just started to play with java+soap.
> >
> > This is the service that is called by the user, this service then
> > crafts a notification message and sends it to a second service.
> >
> > ----- code ----
> >
> > import org.apache.axiom.om.OMAbstractFactory;
> > import org.apache.axiom.om.OMElement;
> > import org.apache.axiom.om.OMFactory;
> > import org.apache.axiom.om.OMNamespace;
> > import org.apache.axis2.Constants;
> > import org.apache.axis2.addressing.EndpointReference;
> > import org.apache.axis2.client.Options;
> > import org.apache.axis2.client.ServiceClient;
> > import org.apache.axis2.util.XMLUtils;
> >
> > import org.apache.muse.ws.notification.impl.SimpleNotificationMessage;
> > import org.apache.muse.ws.notification.NotificationMessage;
> > import org.apache.muse.util.xml.XmlUtils;
> > import org.w3c.dom.Element;
> > import org.apache.axiom.soap.SOAPFault;
> >
> >
> >
> > import javax.xml.namespace.QName;
> >
> > public class PEP {
> >
> > private static String PREFIX = "tns";
> > private static String NAMESPACE_URI =
> "http://org.stihler.vo/guardian/wsn";
> > private static QName TOPIC = new QName(NAMESPACE_URI, "PEP", PREFIX);
> > private static QName messageName = new QName(NAMESPACE_URI,
> > "PEPNotification", PREFIX);
> >
> > public OMElement invoke(OMElement element) throws Exception {
> > try {
> >
> > element.build();
> > element.detach();
> >
> > OMElement msg = createNotification("This is a simple
> > Notification Message");
> >
> > element.addChild(publish(msg));
> >
> > return element;
> >
> > } catch (org.apache.axis2.AxisFault e) {
> > java.io.BufferedWriter bw =
> > new java.io.BufferedWriter(new
> > java.io.FileWriter("/tmp/erros-axis.xml"));
> > bw.write(e.getMessage());
> > bw.close();
> > return element;
> > }
> > }
> >
> > private OMElement createNotification(String content) {
> > try {
> > org.apache.muse.ws.addressing.EndpointReference
> EventBoxEPR =
> > new org.apache.muse.ws.addressing.EndpointReference(
> > new
> > java.net.URI("http://localhost:8080/axis2/services/EventBox"));
> >
> > org.apache.muse.ws.addressing.EndpointReference
> ProducerEPR =
> > new org.apache.muse.ws.addressing.EndpointReference(
> > new
> java.net.URI("http://localhost:8080/axis2/services/PEP"));
> >
> >
> > NotificationMessage msg = new SimpleNotificationMessage();
> > msg.setSubscriptionReference(EventBoxEPR);
> > msg.setProducerReference(ProducerEPR);
> > msg.setTopic(TOPIC);
> >
> > Element payload = XmlUtils.createElement(messageName,
> > content);
> > msg.addMessageContent(payload);
> > return XMLUtils.toOM( msg.toXML() );
> > }
> > catch(Exception e) {
> > return null;
> > }
> > }
> >
> > private OMElement publish(OMElement msg) throws Exception{
> > EndpointReference EventBoxEPR =
> > new EndpointReference(
> > "http://localhost:8080/axis2/services/EventBox");
> >
> > Options options = new Options();
> > options.setTo(EventBoxEPR);
> > options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
> > ServiceClient sender = new ServiceClient();
> > sender.setOptions(options);
> > OMElement rq = makeRequest(msg);
> > sender.sendReceive(rq);
> > return msg;
> > }
> >
> > private static OMElement makeRequest(OMElement payload) {
> > try {
> > OMFactory fac = OMAbstractFactory.getOMFactory();
> > OMNamespace omNs = fac.createOMNamespace(
> > "http://org.stihler.vo/EventBox", "omNs");
> > OMElement method = fac.createOMElement("publish", omNs);
> > method.addChild(payload);
> > return method;
> > }
> > catch(Exception e) {
> > return null;
> > }
> > }
> >
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: [Axis2] Calling a service from another service
Posted by Maicon Stihler <st...@gmail.com>.
Thank you Alberto,
your message was of great help, I looked up on the wsdl generated for
the second service and then used that information to set the options
with setAction("urn:publish"), I also set the SoapVersionURI to match
the one contained on the wsdl. After these changes the problem
disapeared.
Best regards
2007/11/30, Alberto Patino <pa...@gmail.com>:
> Hi!
>
> I got a similar problem under the same pattern you are trying to
> execute, and it was basically a problem related with WS-Addressing (
> The ServiceConfig in the axis2 service it has WS-Addresing enabled by
> default, so when you create a Serviceclinet inside the server you are
> using the same ServiceConfig instantiated in the server). Please be
> sure that your second web service has a soapAction entry with a valid
> content. I fix this problem republishing the second web service after
> I added the soapActionEntry in my wsdl file. ( I do first contract
> development)
>
> Alberto Patino
>
> On 11/30/07, Maicon Stihler <st...@gmail.com> wrote:
> > Well, even though I use the muse API to craft a notification message,
> > I don't use it to invoke the remote service. If I try to send the
> > notification message from a command line client it works fine, that's
> > why I have a feeling that I'm doing something wrong in the way I call
> > the service inside this first service.
> >
> > I'll make some tests with other kinds of services to make sure that
> > the problem isn't with Axis.
> >
> > thank you
> >
> > 2007/11/30, Martin Gainty <mg...@hotmail.com>:
> > > Hi Maicon
> > >
> > > This is a muse webapp ..did you contact the muse folks at
> > > muse-user-subscribe@ws.apache.org
> > >
> > > ?
> > > M--
> > > ----- Original Message -----
> > > From: "Maicon Stihler" <st...@gmail.com>
> > > To: <ax...@ws.apache.org>
> > > Sent: Friday, November 30, 2007 4:50 PM
> > > Subject: Re: [Axis2] Calling a service from another service
> > >
> > >
> > > > 2007/11/30, Martin Gainty <mg...@hotmail.com>:
> > > > > Hi Maicon-
> > > > >
> > > > > 1)can we see the client code.. in particular the part which specifies
> > > the
> > > > > Action
> > > > The code is on the bottom of the email.
> > > >
> > > > > 2)Is there a reason why the client is not initiating all of the web
> > > service
> > > > > queries
> > > > I want the first service to notify this second service when being
> > > > invoked, this action must be transparent to the user because it's not
> > > > related to the application logic.
> > > >
> > > > Best regards,
> > > > Maicon
> > > >
> > > > obs: the code is really ugly, I just started to play with java+soap.
> > > >
> > > > This is the service that is called by the user, this service then
> > > > crafts a notification message and sends it to a second service.
> > > >
> > > > ----- code ----
> > > >
> > > > import org.apache.axiom.om.OMAbstractFactory;
> > > > import org.apache.axiom.om.OMElement;
> > > > import org.apache.axiom.om.OMFactory;
> > > > import org.apache.axiom.om.OMNamespace;
> > > > import org.apache.axis2.Constants;
> > > > import org.apache.axis2.addressing.EndpointReference;
> > > > import org.apache.axis2.client.Options;
> > > > import org.apache.axis2.client.ServiceClient;
> > > > import org.apache.axis2.util.XMLUtils;
> > > >
> > > > import org.apache.muse.ws.notification.impl.SimpleNotificationMessage;
> > > > import org.apache.muse.ws.notification.NotificationMessage;
> > > > import org.apache.muse.util.xml.XmlUtils;
> > > > import org.w3c.dom.Element;
> > > > import org.apache.axiom.soap.SOAPFault;
> > > >
> > > >
> > > >
> > > > import javax.xml.namespace.QName;
> > > >
> > > > public class PEP {
> > > >
> > > > private static String PREFIX = "tns";
> > > > private static String NAMESPACE_URI =
> > > "http://org.stihler.vo/guardian/wsn";
> > > > private static QName TOPIC = new QName(NAMESPACE_URI, "PEP", PREFIX);
> > > > private static QName messageName = new QName(NAMESPACE_URI,
> > > > "PEPNotification", PREFIX);
> > > >
> > > > public OMElement invoke(OMElement element) throws Exception {
> > > > try {
> > > >
> > > > element.build();
> > > > element.detach();
> > > >
> > > > OMElement msg = createNotification("This is a simple
> > > > Notification Message");
> > > >
> > > > element.addChild(publish(msg));
> > > >
> > > > return element;
> > > >
> > > > } catch (org.apache.axis2.AxisFault e) {
> > > > java.io.BufferedWriter bw =
> > > > new java.io.BufferedWriter(new
> > > > java.io.FileWriter("/tmp/erros-axis.xml"));
> > > > bw.write(e.getMessage());
> > > > bw.close();
> > > > return element;
> > > > }
> > > > }
> > > >
> > > > private OMElement createNotification(String content) {
> > > > try {
> > > > org.apache.muse.ws.addressing.EndpointReference
> > > EventBoxEPR =
> > > > new org.apache.muse.ws.addressing.EndpointReference(
> > > > new
> > > > java.net.URI("http://localhost:8080/axis2/services/EventBox"));
> > > >
> > > > org.apache.muse.ws.addressing.EndpointReference
> > > ProducerEPR =
> > > > new org.apache.muse.ws.addressing.EndpointReference(
> > > > new
> > > java.net.URI("http://localhost:8080/axis2/services/PEP"));
> > > >
> > > >
> > > > NotificationMessage msg = new SimpleNotificationMessage();
> > > > msg.setSubscriptionReference(EventBoxEPR);
> > > > msg.setProducerReference(ProducerEPR);
> > > > msg.setTopic(TOPIC);
> > > >
> > > > Element payload = XmlUtils.createElement(messageName,
> > > > content);
> > > > msg.addMessageContent(payload);
> > > > return XMLUtils.toOM( msg.toXML() );
> > > > }
> > > > catch(Exception e) {
> > > > return null;
> > > > }
> > > > }
> > > >
> > > > private OMElement publish(OMElement msg) throws Exception{
> > > > EndpointReference EventBoxEPR =
> > > > new EndpointReference(
> > > > "http://localhost:8080/axis2/services/EventBox");
> > > >
> > > > Options options = new Options();
> > > > options.setTo(EventBoxEPR);
> > > > options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
> > > > ServiceClient sender = new ServiceClient();
> > > > sender.setOptions(options);
> > > > OMElement rq = makeRequest(msg);
> > > > sender.sendReceive(rq);
> > > > return msg;
> > > > }
> > > >
> > > > private static OMElement makeRequest(OMElement payload) {
> > > > try {
> > > > OMFactory fac = OMAbstractFactory.getOMFactory();
> > > > OMNamespace omNs = fac.createOMNamespace(
> > > > "http://org.stihler.vo/EventBox", "omNs");
> > > > OMElement method = fac.createOMElement("publish", omNs);
> > > > method.addChild(payload);
> > > > return method;
> > > > }
> > > > catch(Exception e) {
> > > > return null;
> > > > }
> > > > }
> > > >
> > > > }
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > >
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>
> --
> Don't be evil!!!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: [Axis2] Calling a service from another service
Posted by Alberto Patino <pa...@gmail.com>.
Hi!
I got a similar problem under the same pattern you are trying to
execute, and it was basically a problem related with WS-Addressing (
The ServiceConfig in the axis2 service it has WS-Addresing enabled by
default, so when you create a Serviceclinet inside the server you are
using the same ServiceConfig instantiated in the server). Please be
sure that your second web service has a soapAction entry with a valid
content. I fix this problem republishing the second web service after
I added the soapActionEntry in my wsdl file. ( I do first contract
development)
Alberto Patino
On 11/30/07, Maicon Stihler <st...@gmail.com> wrote:
> Well, even though I use the muse API to craft a notification message,
> I don't use it to invoke the remote service. If I try to send the
> notification message from a command line client it works fine, that's
> why I have a feeling that I'm doing something wrong in the way I call
> the service inside this first service.
>
> I'll make some tests with other kinds of services to make sure that
> the problem isn't with Axis.
>
> thank you
>
> 2007/11/30, Martin Gainty <mg...@hotmail.com>:
> > Hi Maicon
> >
> > This is a muse webapp ..did you contact the muse folks at
> > muse-user-subscribe@ws.apache.org
> >
> > ?
> > M--
> > ----- Original Message -----
> > From: "Maicon Stihler" <st...@gmail.com>
> > To: <ax...@ws.apache.org>
> > Sent: Friday, November 30, 2007 4:50 PM
> > Subject: Re: [Axis2] Calling a service from another service
> >
> >
> > > 2007/11/30, Martin Gainty <mg...@hotmail.com>:
> > > > Hi Maicon-
> > > >
> > > > 1)can we see the client code.. in particular the part which specifies
> > the
> > > > Action
> > > The code is on the bottom of the email.
> > >
> > > > 2)Is there a reason why the client is not initiating all of the web
> > service
> > > > queries
> > > I want the first service to notify this second service when being
> > > invoked, this action must be transparent to the user because it's not
> > > related to the application logic.
> > >
> > > Best regards,
> > > Maicon
> > >
> > > obs: the code is really ugly, I just started to play with java+soap.
> > >
> > > This is the service that is called by the user, this service then
> > > crafts a notification message and sends it to a second service.
> > >
> > > ----- code ----
> > >
> > > import org.apache.axiom.om.OMAbstractFactory;
> > > import org.apache.axiom.om.OMElement;
> > > import org.apache.axiom.om.OMFactory;
> > > import org.apache.axiom.om.OMNamespace;
> > > import org.apache.axis2.Constants;
> > > import org.apache.axis2.addressing.EndpointReference;
> > > import org.apache.axis2.client.Options;
> > > import org.apache.axis2.client.ServiceClient;
> > > import org.apache.axis2.util.XMLUtils;
> > >
> > > import org.apache.muse.ws.notification.impl.SimpleNotificationMessage;
> > > import org.apache.muse.ws.notification.NotificationMessage;
> > > import org.apache.muse.util.xml.XmlUtils;
> > > import org.w3c.dom.Element;
> > > import org.apache.axiom.soap.SOAPFault;
> > >
> > >
> > >
> > > import javax.xml.namespace.QName;
> > >
> > > public class PEP {
> > >
> > > private static String PREFIX = "tns";
> > > private static String NAMESPACE_URI =
> > "http://org.stihler.vo/guardian/wsn";
> > > private static QName TOPIC = new QName(NAMESPACE_URI, "PEP", PREFIX);
> > > private static QName messageName = new QName(NAMESPACE_URI,
> > > "PEPNotification", PREFIX);
> > >
> > > public OMElement invoke(OMElement element) throws Exception {
> > > try {
> > >
> > > element.build();
> > > element.detach();
> > >
> > > OMElement msg = createNotification("This is a simple
> > > Notification Message");
> > >
> > > element.addChild(publish(msg));
> > >
> > > return element;
> > >
> > > } catch (org.apache.axis2.AxisFault e) {
> > > java.io.BufferedWriter bw =
> > > new java.io.BufferedWriter(new
> > > java.io.FileWriter("/tmp/erros-axis.xml"));
> > > bw.write(e.getMessage());
> > > bw.close();
> > > return element;
> > > }
> > > }
> > >
> > > private OMElement createNotification(String content) {
> > > try {
> > > org.apache.muse.ws.addressing.EndpointReference
> > EventBoxEPR =
> > > new org.apache.muse.ws.addressing.EndpointReference(
> > > new
> > > java.net.URI("http://localhost:8080/axis2/services/EventBox"));
> > >
> > > org.apache.muse.ws.addressing.EndpointReference
> > ProducerEPR =
> > > new org.apache.muse.ws.addressing.EndpointReference(
> > > new
> > java.net.URI("http://localhost:8080/axis2/services/PEP"));
> > >
> > >
> > > NotificationMessage msg = new SimpleNotificationMessage();
> > > msg.setSubscriptionReference(EventBoxEPR);
> > > msg.setProducerReference(ProducerEPR);
> > > msg.setTopic(TOPIC);
> > >
> > > Element payload = XmlUtils.createElement(messageName,
> > > content);
> > > msg.addMessageContent(payload);
> > > return XMLUtils.toOM( msg.toXML() );
> > > }
> > > catch(Exception e) {
> > > return null;
> > > }
> > > }
> > >
> > > private OMElement publish(OMElement msg) throws Exception{
> > > EndpointReference EventBoxEPR =
> > > new EndpointReference(
> > > "http://localhost:8080/axis2/services/EventBox");
> > >
> > > Options options = new Options();
> > > options.setTo(EventBoxEPR);
> > > options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
> > > ServiceClient sender = new ServiceClient();
> > > sender.setOptions(options);
> > > OMElement rq = makeRequest(msg);
> > > sender.sendReceive(rq);
> > > return msg;
> > > }
> > >
> > > private static OMElement makeRequest(OMElement payload) {
> > > try {
> > > OMFactory fac = OMAbstractFactory.getOMFactory();
> > > OMNamespace omNs = fac.createOMNamespace(
> > > "http://org.stihler.vo/EventBox", "omNs");
> > > OMElement method = fac.createOMElement("publish", omNs);
> > > method.addChild(payload);
> > > return method;
> > > }
> > > catch(Exception e) {
> > > return null;
> > > }
> > > }
> > >
> > > }
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
--
Don't be evil!!!
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org