Hi,
I want to configure a ServiceMixClient that can send Normalized Messages to
the endpoint I create in an running servicemix3.2.1(thus I don't need to
write a bc everytime to invoke a onMessageExchange method where I always
write sending code and can send messages by running a java program)
But I have some questions about this and acutally don't know how to
configure one.
>From the web http://servicemix.apache.org/client-api.html here ,I want to
know how:
1.Using DefaultServiceMixClient
It seems a spring-like syntax. But How can I get that construct arg defining
a jbi container? The following code:
<bean id="client"
class="org.apache.servicemix.client.DefaultServiceMixClient">
  <constructor-arg ref="jbi" />
</bean>
Where should I put the above code, in the servicemix.xml? Then How can I
access the bean from a java program?

2."ServiceMixClient client = new ServiceMixClientFacade(context);"
Where should this code be?How can I get the context arg?
It says you have to be in a jbi component. Then how can I in a Jbi
component?

3.RemoteServiceMixClient
The code " ServiceMixClient client = new
RemoteServiceMixClient("tcp://localhost:61616"); "
must be the most straightforward way to me. But when hopefully got them
started, I got the errors as:
Exception in thread "main" java.lang.NullPointerException
        at
org.apache.servicemix.client.DefaultInterServiceMixClient.createInOnlyExchange(DefaultInterEsbClient.java:79)
        at my.test.ESBClient.main(ESBClient.java:24)

The complete code is like this:
public class ESBClient {
        
public static void main(String[] args) throws Exception{
                ServiceMixClient client = getClient();
                InOnly exchange = client.createInOnlyExchange();
                NormalizedMessage message = exchange.getInMessage();
                message.setProperty("name", "lichen782");
                message.setContent(new StreamSource(new
StringReader("<hello>world</hello>")));

                // lets use a specific service to dispatch to
                QName service = new QName("http://test";, "jmsProvider");
                exchange.setService(service);
                client.send(exchange);
        }
        public static ServiceMixClient getClient() { 
        RemoteServiceMixClient rc = new
RemoteServiceMixClient("tcp://localhost:61616"); 
        return rc; 
} 

}

And I didn't do any change to Servicemix itself(Should I? But jms flow is
sure to be enabled,which I can see jconsole).

4.Using ClientFactory
I copied the code:
ClientFactory factory = new
InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
ServiceMixClient client = factory.createClient();
...
client.close();

and got the exception:
Exception in thread "main" javax.naming.NoInitialContextException: Need to
specify class name in environment or system property, or as an applet
parameter, or in an application resource file:  java.naming.factory.initial
        at 
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
        at 
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
It appears I need configure a jndi file or sth like. But I don't know how.Is
there any example available?

Thank you and sorry for my ignorance.

-- 
View this message in context: 
http://www.nabble.com/How-Can-I-Configure-a-ServiceMixClient-tp19154581p19154581.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to