[
https://issues.apache.org/jira/browse/KARAF-6727?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17232984#comment-17232984
]
Nicolas Duminil commented on KARAF-6727:
----------------------------------------
Hello,
I'm coming back to this issue after a long absence, sorry. I have an SCR REST
service as follows:
{code:java}
@Path("/")
@Produces("application/json")
@Consumes("application/json")
public class MyRestService implements MyRestAPI
{
@Reference
private MyBusinessDelegate myBusinessDelegate;
...
@Override
@POST
public void post(MyPojo myPojo)
{
myBusinessDelegate.doSomething(myPojo);
...
}
}
{code}
where MyBusinessDelegate is defined as below:
{code:java}
@Transactional
@Component(service = MyBusinessDelegate.class, immediate = true)
@Slf4j
public class MyBusinessDelegateImpl implements MyBusinessDelegate
{
@PersistenceContext(unitName = "press-release")
private EntityManager em;
...
@Activate
public void start()
{
log.debug("...");
}
@Deactivate
public void stop()
{
log.debug("...");
}
public void doSomething(MyPojo myPojo)
{
...
}
...
}
{code}
I'm calling the REST service like this:
{code:java}
@Service
@Command(scope = "...", name = "...", description = "...")
public class MyCommand implements Action
{
...
WebClient webClient = WebClient.create("http:...", List.of(new
JacksonJsonProvider()));
webClient.header("Content-Type", MediaType.APPLICATION_JSON).post(myPojo);
...
}
{code}
The "post()" method in the REST service gets called as expected but it raises
NPE when trying to execute "myBusinessDelegate.doSomething(myPojo);" 'cause
myBusinessDelegate is always NULL. I tried to annotate with @Component
MyBusinessDelegateImpl but it didn't seem to change anything. I tried also to
remove the @Reference annotation, with the same result. Did I miss something
here ?
Many thanks in advance.
Nicolas
> @Reference always null in business delegate
> -------------------------------------------
>
> Key: KARAF-6727
> URL: https://issues.apache.org/jira/browse/KARAF-6727
> Project: Karaf
> Issue Type: Question
> Components: karaf
> Affects Versions: 4.2.8
> Reporter: Nicolas Duminil
> Assignee: Jean-Baptiste Onofré
> Priority: Minor
>
> Hello,
> In a REST service deployed on Karaf 4.28, I'm trying to use a business
> delegate. The REST service starts well and I'm able to display the WADL, etc.
> But the business delegate reference is always null. Here is a code excerpt:
> {color:#9e880d}@Path{color}({color:#067d17}"/customers"{color})
> {color:#9e880d} @Produces{color}({color:#067d17}"application/xml"{color})
> {color:#9e880d} @Consumes{color}({color:#067d17}"application/xml"{color})
> {color:#0033b3} public class {color}{color:#000000}CustomerAPI
> {color} {
> {color:#9e880d}@Reference
> {color} {color:#0033b3}private {color}{color:#000000}CustomerDataService
> {color}{color:#871094}customerDataService{color};
> {color:#9e880d}@GET
> {color} {color:#0033b3}public {color}{color:#000000}Response
> {color}{color:#00627a}getCustomers{color}()
> {
> {color:#0033b3}return
> {color}{color:#000000}Response{color}.ok().entity({color:#000000}Objects{color}.requireNonNull({color:#871094}customerDataService{color},
> {color:#067d17}"CustomerDataService is
> null"{color}).getCustomers().stream().map({color:#000000}CustomerDto{color}::
> {color:#0033b3}new{color}).collect({color:#000000}Collectors{color}.toList())).build();
> }
> ...
> }
> Here above, an NPE is raised as the customersDataService property is null.
> The logfile displays the following:
> java.lang.NullPointerException: CustomerDataService is null
> at java.util.Objects.requireNonNull(Objects.java:246) ~[?:?]
> at
> fr.simplex_software.red_hat.fuse.osgi.standalone.customers.rest.CustomerAPI.getCustomers(CustomerAPI.java:26)
> ~[?:?]
> ...
> What did I miss here ? Many thanks in advance.
> Kind regards,
> Nicolas
--
This message was sent by Atlassian Jira
(v8.3.4#803005)