larjohn wrote:
I managed to get the response back, but I need your help anyway. Well I have
the following scenario:
1. A user navigates to a web page and sends a request to Service 1 (which is
exposed to the bus using cxf-se). The request is transfered to the service
through a cxf-bc SU. The cxf-se based Service1 is described by a wsdl file,
exactly like the included example.
The request arrives to Service1 but before it replies 'OK' or return a
response, it must notify another cxf-se based service, let's say Service 2.
So while processing the request, Service1 uses a servicemixclient to send a
normalised message to Service2. Service2 doesn't have a wsdl description. It
is a straight implementation with an annotated class and an annotated method
inside it, just like the one that comes by default in the cxf-se archetype.
No additional cxf-bc is used. Service1 sent the message using sendsync, so
it waits for a response.
3. Service2 responds, after querying a local database. Service1 then
unblocks and using the Service2 response, makes a response and sends it back
to the cxf-bc and the user.

I tried to do the above, but I couldn't make it in the servicemixClient
part.
Service 1 is like the following:

package org.apache.servicemix.samples.wsdl_first;

import java.io.StringReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.jws.WebService;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Holder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.api.ClientFactory;
import org.apache.servicemix.jbi.api.ServiceMixClient;
import org.apache.servicemix.samples.wsdl_first.types.GetPerson;
import org.apache.servicemix.samples.wsdl_first.types.GetPersonResponse;
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.context.support.AbstractXmlApplicationContext;

@WebService(serviceName = "PersonService", targetNamespace =
"http://servicemix.apache.org/samples/wsdl-first";, endpointInterface =
"org.apache.servicemix.samples.wsdl_first.Person")
public class PersonImpl implements Person {

    private static final Log log = LogFactory.getLog(PersonImpl.class);
    protected ServiceMixClient client;

    public void getPerson(Holder<String> personId, Holder<String> ssn,
Holder<String> name)
            throws UnknownPersonFault {
        if (personId.value == null || personId.value.length() == 0) {
org.apache.servicemix.samples.wsdl_first.types.UnknownPersonFault fault =
new org.apache.servicemix.samples.wsdl_first.types.UnknownPersonFault();
            fault.setPersonId(personId.value);
            throw new UnknownPersonFault(null, fault);
        }
        try {
            setUp();
            SendSomething();
        } catch (Exception ex) {
            Logger.getLogger(PersonImpl.class.getName()).log(Level.SEVERE,
"Setup Exception Here!", ex.getMessage());
        }

        log.info("Hello there!");
        name.value = "Larry";
        ssn.value = "000-000-0000";

    }
    private void SendSomething() {
        try {
            InOut exchange = client.createInOutExchange();
            NormalizedMessage inMessage = exchange.getInMessage();
            inMessage.setProperty("name", "James");
            inMessage.setContent(new StreamSource(new
StringReader("<hello>world</hello>")));
// optionally specify the endpoint
          exchange.setService(new
QName("service:http://servicemix.apache.org/samples/wsdl_first/SecondService";));
          exchange.setOperation(new QName("sayHello"));
          client.sendSync(exchange);
          NormalizedMessage outMessage = exchange.getOutMessage();
        } catch (MessagingException ex) {
            Logger.getLogger(PersonImpl.class.getName()).log(Level.SEVERE,
"Message Exception here!", ex);
        }
    }
    protected void setUp() throws Exception {


        ClientFactory factory = (ClientFactory) new
InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
        client = factory.createClient();
    }
}


Service2 is :

package org.apache.servicemix.samples.wsdl_first;

import javax.jws.WebMethod;
import javax.jws.WebService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@WebService(serviceName = "SecondService", targetNamespace =
"http://servicemix.apache.org/samples/wsdl_first";)
public class ExampleService {
    private static final Log log = LogFactory.getLog(ExampleService.class);
        @WebMethod
        public String sayHello() {
log.info("------------------LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL!!!!!----------------");
                return "Hello ";
        }
}

When I send a message to Service1 it doesn't fail, but I don't know how to
invoke the specific sayHello method of Service2, with parameters and take
back the result. What should I enter in the exchange var?
If you want to invoke service2 from service1, you can inject the proxy of service2 into service1, take a look at [1], the Proxies part. It's so easy that you only need invoke a java object and get rid of the servicemix client api as well as marshall/unmarshal message yourself.

[1]http://servicemix.apache.org/servicemix-cxf-se.html
Also, I have a camel component that takes the request from the cxf-bc and
routes it to the cxf-se (I know it is not needed, just testing!). How can I
send the same request to Service2? If it responds somehow (by the way,
how?), which response will be returned to cxf-bc Service1 or Service2 ?

Finally, if I want to return the response in a html page, using eg a
transform, how can I do this, and how to define the webpage? Do I need
another SU?

Thanks in advance!

Larry Johnson


Freeman Fang wrote:
Hi,

Couldn't tell you more unless you post more details about your workflow, your configuration.

Regards
Freeman







Reply via email to