Camel CDI exception...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Camel CDI exception...

Brad Johnson
Granted I'm new to Camel CDI but I'm a bit flummoxed by a problem that I don't have a clue about.  Any help is appreciated.

When I start up CamelCDI test runner I get an error that an interface on one of my classes doesn't have a valid constructor. Surprisingly when I run the test I see the injection of the items into my test class (even though I don't need them there it helps verify that they are getting constructed).  Below are the top of the test class, the Echo implementation and the Echo interface.  I'm bewildered why Weld would think it should be finding a constructor in the interface. It smells a bit like test framework bug but I'd only say that if I knew the stack better. 

The error is surprisingly from org.apache.cxf.service.factory but that isn't what should be calling the initialize anyway.

@RunWith(CamelCdiRunner.class)
public class RestTest  {

Logger logger = Logger.getLogger(RestTest.class);
@Inject
RestServer restServer;
@Inject
EchoService echoService;
@Before
public void init()
{
System.out.println("Rest Server: " + restServer);
System.out.println("Echo Service: " + echoService);
}
....

org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke public void org.enjekt.osgi.echo.internal.impl.EchoImpl.initialize() on org.enjekt.osgi.echo.internal.impl.EchoImpl@48e92c5c
Caused by: java.lang.reflect.InvocationTargetException
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
Caused by: java.lang.RuntimeException: Resource class interface org.enjekt.osgi.echo.api.EchoService has no valid constructor

The impl class, shown below, has an initialize method on it to register the interface on the injected servers.  And that works.  

The println from the init method.
Injected Rest Server in EchoImpl: org.enjekt.osgi.microserver.internal.impl.RestServerImpl@5b7a7f33

Yes, this has both SCR and CDI annotations so that I can test with Camel CDI which is very fast but deploy to karaf.  The impl class looks like as follows:

public class EchoImpl implements EchoService{

@Reference
@Inject
SoapServer soapServer;
@Reference
@Inject
RestServer restServer;
public EchoImpl(){
}
@PostConstruct
public void initialize(){
System.out.println("Injected Rest Server: "+ restServer);
restServer.register(EchoService.class, this);
soapServer.register(EchoService.class, this);

}

The interface looks like the following:


/**
 * The Interface EchoService is for testing deployment of a microservice bundle.
 */
@WebService
@Path("/resources/echo")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public interface EchoService  {
/**
* Echo a string back in either SOAP or REST
*
* @param echoString the echo string
* @return the string
*/
@GET
@Path("/{echoID}")
@WebMethod(operationName = "echoString")
public String echoString(@WebParam(name = "echoID", targetNamespace = "") @PathParam("echoID") String echoString);
/**
* Echo object uses a message wrapper for request/responses in SOAP or REST.
*
* @param echoObject the echo object
* @return the echo response message
*/
@GET
@Path("/")
@WebMethod(operationName = "echoObject")
public EchoResponseMessage echoObject(@WebParam(name = "echoObject", targetNamespace = "") @QueryParam("") EchoRequestMessage echoObject);

}


Reply | Threaded
Open this post in threaded view
|

Re: Camel CDI exception...

John Poth-2
Hi Brad,

Your stack trace suggests that an exception is thrown in EchoImpl.initialize() which calls 

restServer.register(EchoService.class, this);

and seems to be the problem here. Have you tried calling instead:

restServer.register(EchoServiceImpl.class, this);
soapServer.register(EchoServiceImpl.class, this);


Not sure what RestServer and SoapServer are so a small example project might help here.

Cheers,

John.


On Tue, Sep 6, 2016 at 5:07 PM, Brad Johnson <[hidden email]> wrote:
Granted I'm new to Camel CDI but I'm a bit flummoxed by a problem that I don't have a clue about.  Any help is appreciated.

When I start up CamelCDI test runner I get an error that an interface on one of my classes doesn't have a valid constructor. Surprisingly when I run the test I see the injection of the items into my test class (even though I don't need them there it helps verify that they are getting constructed).  Below are the top of the test class, the Echo implementation and the Echo interface.  I'm bewildered why Weld would think it should be finding a constructor in the interface. It smells a bit like test framework bug but I'd only say that if I knew the stack better. 

The error is surprisingly from org.apache.cxf.service.factory but that isn't what should be calling the initialize anyway.

@RunWith(CamelCdiRunner.class)
public class RestTest  {

Logger logger = Logger.getLogger(RestTest.class);
@Inject
RestServer restServer;
@Inject
EchoService echoService;
@Before
public void init()
{
System.out.println("Rest Server: " + restServer);
System.out.println("Echo Service: " + echoService);
}
....

org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke public void org.enjekt.osgi.echo.internal.impl.EchoImpl.initialize() on org.enjekt.osgi.echo.internal.impl.EchoImpl@48e92c5c
Caused by: java.lang.reflect.InvocationTargetException
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
Caused by: java.lang.RuntimeException: Resource class interface org.enjekt.osgi.echo.api.EchoService has no valid constructor

The impl class, shown below, has an initialize method on it to register the interface on the injected servers.  And that works.  

The println from the init method.
Injected Rest Server in EchoImpl: org.enjekt.osgi.microserver.internal.impl.RestServerImpl@5b7a7f33

Yes, this has both SCR and CDI annotations so that I can test with Camel CDI which is very fast but deploy to karaf.  The impl class looks like as follows:

public class EchoImpl implements EchoService{

@Reference
@Inject
SoapServer soapServer;
@Reference
@Inject
RestServer restServer;
public EchoImpl(){
}
@PostConstruct
public void initialize(){
System.out.println("Injected Rest Server: "+ restServer);
restServer.register(EchoService.class, this);
soapServer.register(EchoService.class, this);

}

The interface looks like the following:


/**
 * The Interface EchoService is for testing deployment of a microservice bundle.
 */
@WebService
@Path("/resources/echo")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public interface EchoService  {
/**
* Echo a string back in either SOAP or REST
*
* @param echoString the echo string
* @return the string
*/
@GET
@Path("/{echoID}")
@WebMethod(operationName = "echoString")
public String echoString(@WebParam(name = "echoID", targetNamespace = "") @PathParam("echoID") String echoString);
/**
* Echo object uses a message wrapper for request/responses in SOAP or REST.
*
* @param echoObject the echo object
* @return the echo response message
*/
@GET
@Path("/")
@WebMethod(operationName = "echoObject")
public EchoResponseMessage echoObject(@WebParam(name = "echoObject", targetNamespace = "") @QueryParam("") EchoRequestMessage echoObject);

}