Ok, I got it to build. My next problem comes when I deploy my SA. I'm
getting a null pointer exception in my invokeIdentityService method that I
call from poll method. Any ideas? Thanks.
private boolean invokeIdentityService() throws MessagingException {
ComponentContext ctx =
getServiceUnit().getComponent().getComponentContext();
QName identityService = new QName("NSR:NSRService", "service");
InOut identityExchange = exchangeFactory.createInOutExchange();
configureTarget("Identity Service", identityExchange, ctx,
null, identityService, "soap", "");
NormalizedMessage in = identityExchange.createMessage();
in.setContent(new StringSource("<hello>Testing</hello>"));
identityExchange.setInMessage(in);
sendSync(identityExchange);
NormalizedMessage out = identityExchange.getOutMessage();
boolean login = false;
if (out != null) {
//login = support.parseIdentityOutMessage(out.getContent());
} else {
// TODO: how should we handle faults
}
done(identityExchange);
return login;
}
public void configureTarget(String serviceDesc, MessageExchange
exchange, ComponentContext context, QName _interface, QName service,
String endpoint, String uri) throws MessagingException {
if (_interface == null && service == null && uri == null) {
throw new MessagingException(serviceDesc + ": interface,
service or uri should be specified");
}
if (_interface != null) {
exchange.setInterfaceName(_interface);
}
if (service != null) {
exchange.setService(service);
if (endpoint != null) {
ServiceEndpoint se = context.getEndpoint(service,
endpoint);
exchange.setEndpoint(se);
}
}
}
ERROR - MyComponent - Caught exception while polling:
java.lang.NullPointerException
java.lang.NullPointerException
at
org.apache.servicemix.common.endpoints.SimpleEndpoint.sendSync(SimpleEndpoint.java:71)
at
org.apache.servicemix.samples.serviceManagerAssembly.MyEndpoint.invokeIdentityService(MyEndpoint.java:289)
at
org.apache.servicemix.samples.serviceManagerAssembly.MyEndpoint.poll(MyEndpoint.java:274)
at
org.apache.servicemix.common.endpoints.PollingEndpoint$PollSchedulerTask$1.run(PollingEndpoint.java:155)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
at java.lang.Thread.run(Thread.java:595)
ERROR - MyComponent - Caught exception while polling:
java.lang.NullPointerException
java.lang.NullPointerException
at
org.apache.servicemix.common.endpoints.SimpleEndpoint.sendSync(SimpleEndpoint.java:71)
at
org.apache.servicemix.samples.serviceManagerAssembly.MyEndpoint.invokeIdentityService(MyEndpoint.java:289)
at
org.apache.servicemix.samples.serviceManagerAssembly.MyEndpoint.poll(MyEndpoint.java:274)
at
org.apache.servicemix.common.endpoints.PollingEndpoint$PollSchedulerTask$1.run(PollingEndpoint.java:155)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
gnodet wrote:
>
> The problem is not related to your code, but to the test configuration.
> The PollingEndpoint is a consumer endpoint, which means it will create
> and send JBI exchanges. Thus, you have to tell where the exchange go.
> Hence the error you see.
> You should set this property in java or xml depending on the way the test
> is wired:
> endpoint.setTargetService(new QName("urn:test", "svc"));
> or
> <xxx:endpoint targetService="test:svc" >
>
> I guess you will have to rewrite the test somehow, as it may have been
> designed to test a provider endpoint rather than a consumer.
>
> On 5/17/07, Benamin <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>> gnodet wrote:
>> >
>> > On 5/16/07, Benamin <[EMAIL PROTECTED]> wrote
>> >
>> >
>> >> I think you will want to inherit the PollingEndpoint instead. It will
>> >> take
>> >> care of periodically
>> >> call the poll() method that you need to implement. Else you can start
>> a
>> >> thread in the start()
>> >> method and kill it in the stop() method.
>> >
>> >
>> >
>>
>> I am using your advice and tyring the PollingEndpoint class and use
>> Bruce's
>> code to send data to an http provider. At the moment I have left out my
>> custom logic. I am just trying to get a simple example to send a message
>> to
>> the http provider. My code compiles, MySpringComponent test fails. I am
>> posting my code so far to see if somebody can find the problem. I'll be
>> glad to post a completed example of this if I can get it to work.
>> Thanks.
>>
>>
>> public class MyEndpoint extends PollingEndpoint implements
>> ExchangeProcessor
>> {
>> private ServiceEndpoint activated;
>> private DeliveryChannel channel;
>> private MessageExchangeFactory exchangeFactory;
>>
>> public void activate() throws Exception {
>>
>> logger = this.serviceUnit.getComponent().getLogger();
>> ComponentContext ctx =
>> getServiceUnit().getComponent().getComponentContext();
>> channel = ctx.getDeliveryChannel();
>> exchangeFactory = channel.createExchangeFactory();
>> activated = ctx.activateEndpoint(service, endpoint);
>> start();
>> }
>>
>> public String getLocationURI() {
>> return getService() + "#" + getEndpoint();
>> }
>>
>> public void process(MessageExchange exchange) throws Exception {
>>
>> if (exchange.getRole() == MessageExchange.Role.PROVIDER) {
>>
>> // Check here if the mep is supported by this component
>> if (exchange instanceof InOut == false) {
>> throw new UnsupportedOperationException("Unsupported MEP:
>> "
>> +
>> exchange.getPattern());
>> }
>> // In message
>> if (exchange.getMessage("in") != null) {
>> NormalizedMessage in = exchange.getMessage("in");
>>
>> NormalizedMessage out = exchange.createMessage();
>> out.setContent(in.getContent());
>> exchange.setMessage(out, "out");
>> channel.send(exchange);
>> // Fault message
>> } else if (exchange.getFault() != null) {
>> // TODO ... handle the fault
>> exchange.setStatus(ExchangeStatus.DONE);
>> channel.send(exchange);
>> // This is not compliant with the default MEPs
>> } else {
>> throw new java.lang.IllegalStateException("Provider
>> exchange
>> is ACTIVE, but no in or fault is provided");
>> }
>> }
>>
>> }
>>
>> public void poll() throws Exception
>> {
>> invokeIdentityService();
>> }
>>
>> private boolean invokeIdentityService() throws MessagingException {
>> ComponentContext ctx =
>> getServiceUnit().getComponent().getComponentContext();
>> QName identityService = new QName("NSR:NSRService", "service");
>>
>> InOut identityExchange = exchangeFactory.createInOutExchange();
>> configureTarget("Identity Service", identityExchange, ctx,
>> null, identityService, "soap", "");
>>
>> NormalizedMessage in = identityExchange.createMessage();
>> in.setContent(new StringSource("<hello>Testing</hello>"));
>> identityExchange.setInMessage(in);
>> sendSync(identityExchange);
>>
>> NormalizedMessage out = identityExchange.getOutMessage();
>> boolean login = false;
>> if (out != null) {
>> //login = support.parseIdentityOutMessage(out.getContent());
>> } else {
>> // TODO: how should we handle faults
>> }
>> done(identityExchange);
>>
>> return login;
>> }
>>
>> public void configureTarget(String serviceDesc, MessageExchange
>> exchange, ComponentContext context, QName _interface, QName service,
>> String endpoint, String uri) throws MessagingException {
>>
>> if (_interface == null && service == null && uri == null) {
>> throw new MessagingException(serviceDesc + ": interface,
>> service or uri should be specified");
>> }
>>
>> if (_interface != null) {
>> exchange.setInterfaceName(_interface);
>> }
>>
>> if (service != null) {
>> exchange.setService(service);
>> if (endpoint != null) {
>> ServiceEndpoint se = context.getEndpoint(service,
>> endpoint);
>> exchange.setEndpoint(se);
>> }
>> }
>> }
>> }
>>
>>
>> The error I am getting is:
>>
>> test(
>> org.apache.servicemix.samples.serviceManagerAssembly.MySpringComponentTest
>> )
>> Time elapsed: 1.951 sec <<< ERROR!
>> org.springframework.beans.factory.BeanCreationException: Error creating
>> bean
>> with name 'jbi' defined in class path resource [spring.xml]: Invocation
>> of
>> init method failed; nested exception is
>> javax.jbi.management.DeploymentException: targetInterface, targetService
>> or
>> targetUri should be specified
>> Caused by: javax.jbi.management.DeploymentException: targetInterface,
>> targetService or targetUri should be specified
>> --
>> View this message in context:
>> http://www.nabble.com/SE-that-continually-reads-and-sends-data-tf3764809s12049.html#a10656682
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Principal Engineer, IONA
> Blog: http://gnodet.blogspot.com/
>
>
--
View this message in context:
http://www.nabble.com/SE-that-continually-reads-and-sends-data-tf3764809s12049.html#a10657542
Sent from the ServiceMix - User mailing list archive at Nabble.com.