0

I have a Jar, Helper project, which has a process manager, which controls the execution of threads etal. Where it receives an interface that performs the execution when fired.

I have another Jar, Service project, which implements the interface Helper, and injects a factory Service project itself.

The error occurs when you run the code

processor = statementProcFactory.getProduct(modelMessage.getProcessType ()); 

when executed via Helper. I tried calling the processMessage StatementToPRocessDequeueable within the Application Service, mocando the message, and it worked without problems. The error occurs only when the processMessage is called by SQSQueueRunnable.

The structure of Helper:

├── src
│   ├── main
│   │   ├── java
│   │   │   └── br
│   │   │       └── com
│   │   │           └── aws
│   │   │               └── sqs
│   │   │                   ├── ISQSDequeueable.java
│   │   │                   ├── SQSDequeueableException.java
│   │   │                   ├── SQSQueueManager.java
│   │   │                   └── SQSQueueRunnable.java
│   │   └── resources
│   │       └── META-INF
│   │           └── beans.xml

And the structure of the Service

├── src
│   ├── main
│   │   ├── java
│   │   │   └── br
│   │   │       └── com
│   │   │           └── reconciliation
│   │   │               ├── service
│   │   │               │   ├── Application.java
│   │   │               │   ├── MainService.java
│   │   │               │   └── statement
│   │   │               │       └── processor
│   │   │               │           ├── IStatementProcessor.java
│   │   │               │           ├── processors
│   │   │               │           │   ├── BanriProcessor.java
│   │   │               │           │   ├── CieloProcessor.java
│   │   │               │           │   ├── RedeCreditProcessor.java
│   │   │               │           │   └── RedeDebitProcessor.java
│   │   │               │           ├── StatementProcessorFactory.java
│   │   │               │           ├── StatementProcessorType.java
│   │   │               │           └── StatementProcessorTypeLiteral.java
│   │   │               └── sqsdequeueable
│   │   │                   ├── StatementToProcessDequeueable.java
│   │   │                   └── StatementToProcessModel.java
│   │   └── resources
│   │       ├── aws.properties
│   │       └── META-INF
│   │           └── beans.xml

Main Service:

public static void main(String[] args) {
    timer = new Timer();
    timer.schedule(new EchoTask(), 0, 1000);

    Weld weld = new Weld();
    WeldContainer container = weld.initialize();
    Application application = container.instance().select(Application.class).get();
    application.run();
    weld.shutdown();
}

Class Application:

@Singleton
public class Application {

    @Inject
    private SQSQueueManager queueManager;

    @Inject
    private Provider<StatementToProcessDequeueable> statementProcDequeueProvider;


    public void run() {

        queueManager.addSQSDequeueable(statementProcDequeueProvider.get());
    }
}

Method of addSQSDequeueable SQSQueueManager:

public void addSQSDequeueable(ISQSDequeueable dequeueable) {

    SQSQueueRunnable runnable = runnableProvider.get();

    runnable.setDequeueable(dequeueable);

    Thread th = new Thread(runnable);

    dictionaryDequeueables.put(dequeueable, runnable);

    dequeueable.startRunning();

    th.start();
}

SQSRunnable the run method:

public void run() {
    ReceiveMessageRequest request = new ReceiveMessageRequest(
            dequeueable.getQueue());

    do {

        List<Message> messages = sqsAmazon.receiveMessage(request)
                .getMessages();

        for (Message message : messages) {
            processed = true;

            Thread th = new Thread(new Runnable() {

                private Message message;

                public void run() {
                    try {
                        dequeueable.processMessage(message);
                    } catch (SQSDequeueableException e) {
                        // TODO Mover mensagem para fila de erros
                        e.printStackTrace();
                    }

                    sqsAmazon.deleteMessage(new DeleteMessageRequest(
                            dequeueable.getQueue(), message
                                    .getReceiptHandle()));
                }

                public Runnable setMessage(Message message) {
                    this.message = message;
                    return this;
                }

            }.setMessage(message));

            th.run();
        }

        try {
            Thread.sleep(this.getSleepThread());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if (isRunning == false)
            dequeueable.stopRunning();

    } while (isRunning);
}

method processMessage of StatementToProcessDequeueable that implements the interface ISQSDequeueable

public void processMessage(Message message) throws SQSDequeueableException {

    logger.debug("Processando mensagem");

    StatementToProcessModel modelMessage = this.generateModel(message.getBody());

    if (modelMessage != null) {
        processor = statementProcFactory.getProduct(modelMessage.getProcessType());

        logger.debug("Processor gerado: " + processor);

        if (processor != null) {

            Statement statement = new Statement();

            Retail retail = repoRetail.getRetailByID(modelMessage.getRetailId());

            List<OperationCard> operations = processor.process(
                    statement.getInputStream(), retail);

            for (OperationCard operation : operations) {

            }

        } else {
            throw new SQSDequeueableException(String.format(
                    "O tipo de processador %s está inválido", processor));
        }
    } else {
        logger.debug("Atributos inválidos da mensagem");

        throw new SQSDequeueableException(
                "Mensagem não possuí todos atributos necessários");
    }
}

Class StatementProcessorFactory

@Singleton
public class StatementProcessorFactory {

@Inject
@Any
private Instance<IStatementProcessor> products;

public IStatementProcessor getProduct(String type) {
    StatementProcessorTypeLiteral literal = new StatementProcessorTypeLiteral(type);
    Instance<IStatementProcessor> typeProducts = products.select(literal);
    return typeProducts.get();
}
}

Class StatementProcessorTypeLiteral

@SuppressWarnings("serial")
public class StatementProcessorTypeLiteral extends
    AnnotationLiteral<StatementProcessorType> implements StatementProcessorType {

private String type;

public StatementProcessorTypeLiteral(String type) {
    this.type = type;
}

public String value() {
    return type;
}
}

Interface StatementProcessorType

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface StatementProcessorType {
    public String value();
}

Class that implements the IStatmentProcessor and has the qualifier StatementProcessorType

@StatementProcessorType("Banri")
@Stateless
public class BanriProcessor implements IStatementProcessor {
    public List<OperationCard> process(InputStream statementFile, Retail retail) {
    // TODO Auto-generated method stub
    return null;
}

}

Error:

Exception in thread "Thread-2" org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Types: [interface br.com.agilebox.gestorfiscal.reconciliation.service.statement.processor.IStatementProcessor]; Bindings: [QualifierInstance{annotationClass=interface br.com.agilebox.gestorfiscal.reconciliation.service.statement.processor.StatementProcessorType, values={[BackedAnnotatedMethod] public abstract br.com.agilebox.gestorfiscal.reconciliation.service.statement.processor.StatementProcessorType.value()=Banri}, hashCode=-1507802905}, QualifierInstance{annotationClass=interface javax.enterprise.inject.Any, values={}, hashCode=-2093968819}]
at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:854)
at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:75)
at br.com.agilebox.gestorfiscal.reconciliation.service.statement.processor.StatementProcessorFactory.getProduct(StatementProcessorFactory.java:19)
at br.com.agilebox.gestorfiscal.reconciliation.sqsdequeueable.StatementToProcessDequeueable.processMessage(StatementToProcessDequeueable.java:31)
at br.com.agilebox.gestorfisccal.aws.sqs.SQSQueueRunnable.run(SQSQueueRunnable.java:64)
at java.lang.Thread.run(Thread.java:745)
  • Is there a reason why `BanriProcessor` should be a Stateless Session Bean rather than just a CDI Bean? I'm not 100% sure but I think that if you remove the `@Stateless` annotation, the injection will work. – rubenlop88 Jul 04 '14 at 18:41
  • I removed, but the error continues – giovanibarili Jul 04 '14 at 22:54
  • One more comment, I realized now that if I run it works. If I do not debug. Have any explanation? – giovanibarili Jul 05 '14 at 00:07
  • I put a example code at github https://github.com/giovanibarili/InjectBetweenJars . If you run, ok... but if you debug... error! – giovanibarili Jul 05 '14 at 02:12
  • How are these JARs packaged? in a WAR? EAR? Also please include your `beans.xml` files. Please also specify what version of weld you're running. – John Ament Jul 05 '14 at 20:05

0 Answers0