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.