Topic
  • 8 replies
  • Latest Post - ‏2011-08-25T15:58:49Z by izhd
izhd
izhd
27 Posts

Pinned topic implementation.osgi & binding.ws

‏2011-08-19T00:14:45Z |
Is it possible to define binding.ws for services in component that has implementation.osgi and exposed OSGi services?

Thanks,
Igor
Updated on 2011-08-25T15:58:49Z at 2011-08-25T15:58:49Z by izhd
  • SystemAdmin
    SystemAdmin
    126 Posts

    Re: implementation.osgi & binding.ws

    ‏2011-08-19T00:34:04Z  
    Hi Igor.

    Yes, you can. Take a look at the following link:
    http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.jpafep.multiplatform.doc/info/ae/ae/tsca_osgi_impl.html

    In fact, if you are using RAD 8.0.x, you can download the SCA OSGi Sample included in the help. In order to download you need to go to Help > Help Contents. The Help window will appear. In the left you'll see the navigator, go to Samples > SCA and click on SCA OSGi Sample, then you click on Import Sample and that will bring the sample into your workspace.

    Hope this helps.

    "Software development has been, is, and will remain fundamentally hard"
    - Grady Booch
  • izhd
    izhd
    27 Posts

    Re: implementation.osgi & binding.ws

    ‏2011-08-19T00:39:32Z  
    Hi Igor.

    Yes, you can. Take a look at the following link:
    http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.jpafep.multiplatform.doc/info/ae/ae/tsca_osgi_impl.html

    In fact, if you are using RAD 8.0.x, you can download the SCA OSGi Sample included in the help. In order to download you need to go to Help > Help Contents. The Help window will appear. In the left you'll see the navigator, go to Samples > SCA and click on SCA OSGi Sample, then you click on Import Sample and that will bring the sample into your workspace.

    Hope this helps.

    "Software development has been, is, and will remain fundamentally hard"
    - Grady Booch
    Thank you, Victor.
    I remember using that sample..
    I guess my problem is that I have http.binding and trying to add ws.binding. After that SCA just doesn't deploy anymore.
    In the sample they have duplicated interface from OSGi in SCA component, that I just eliminated. Anyways, I'll take that sample and take another look..

    Thanks,
    Igor
  • izhd
    izhd
    27 Posts

    Re: implementation.osgi & binding.ws

    ‏2011-08-19T22:03:44Z  
    • izhd
    • ‏2011-08-19T00:39:32Z
    Thank you, Victor.
    I remember using that sample..
    I guess my problem is that I have http.binding and trying to add ws.binding. After that SCA just doesn't deploy anymore.
    In the sample they have duplicated interface from OSGi in SCA component, that I just eliminated. Anyways, I'll take that sample and take another look..

    Thanks,
    Igor
    Ok, so here's the update.
    I took sample scaOSGiRadioService as a base and tried to work my way from it.
    1) In sample they have defined interface for the OSGi service defined as interface.java and have copy of interface in SCA. Based on my previous experience I just deleted it and everything worked fine. Good.
    2) Sample uses simple parameters in interfaces like public String requestLicense(String name). I've tried to add public ComplexTypeTestImpl test(ComplexTypeTestImpl testParam), where
    ComplexTypeTestImpl
    public class ComplexTypeTestImpl implements ComplexTypeTest {

    public ComplexTypeTestImpl(){

    }
    private int intVal;
    private String stringVal;

    @Override
    public String getStringVal() {
    // TODO Auto-generated method stub
    return stringVal;
    }

    @Override
    public int getIntVal() {
    // TODO Auto-generated method stub
    return intVal;
    }

    public void setIntVal(int intVal) {
    this.intVal = intVal;
    }

    public void setStringVal(String stringVal) {
    this.stringVal = stringVal;
    }

    }

    That worked fine as well.

    Unfortunately,that has not much in common with real OSGi scenario, where based on best practices we keep interfaces and implementations separately, and methods usually accept parameters of type interface, not class. If we replace in previous example classes with interfaces in method signature, we'll get

    • <soapenv:Fault>
    <faultcode>soapenv:Server</faultcode>
    <faultstring>com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions com.radioserv.ComplexTypeTest is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at com.radioserv.ComplexTypeTest at protected com.radioserv.ComplexTypeTest com.radioserv.jaxws.TestResponse._return at com.radioserv.jaxws.TestResponse com.radioserv.ComplexTypeTest does not have a no-arg default constructor. this problem is related to the following location: at com.radioserv.ComplexTypeTest at protected com.radioserv.ComplexTypeTest com.radioserv.jaxws.TestResponse._return at com.radioserv.jaxws.TestResponse</faultstring>
    <detail />
    </soapenv:Fault>

    as expected.

    So here's real question : how should we expose OSGi services with complex in/out parameters over WS?
    We had the similar issue with http binding, but solved it by exposing interface that accepts JSONObjects.
  • izhd
    izhd
    27 Posts

    Re: implementation.osgi &#38; binding.ws

    ‏2011-08-19T23:43:56Z  
    • izhd
    • ‏2011-08-19T22:03:44Z
    Ok, so here's the update.
    I took sample scaOSGiRadioService as a base and tried to work my way from it.
    1) In sample they have defined interface for the OSGi service defined as interface.java and have copy of interface in SCA. Based on my previous experience I just deleted it and everything worked fine. Good.
    2) Sample uses simple parameters in interfaces like public String requestLicense(String name). I've tried to add public ComplexTypeTestImpl test(ComplexTypeTestImpl testParam), where
    ComplexTypeTestImpl
    public class ComplexTypeTestImpl implements ComplexTypeTest {

    public ComplexTypeTestImpl(){

    }
    private int intVal;
    private String stringVal;

    @Override
    public String getStringVal() {
    // TODO Auto-generated method stub
    return stringVal;
    }

    @Override
    public int getIntVal() {
    // TODO Auto-generated method stub
    return intVal;
    }

    public void setIntVal(int intVal) {
    this.intVal = intVal;
    }

    public void setStringVal(String stringVal) {
    this.stringVal = stringVal;
    }

    }

    That worked fine as well.

    Unfortunately,that has not much in common with real OSGi scenario, where based on best practices we keep interfaces and implementations separately, and methods usually accept parameters of type interface, not class. If we replace in previous example classes with interfaces in method signature, we'll get

    • <soapenv:Fault>
    <faultcode>soapenv:Server</faultcode>
    <faultstring>com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions com.radioserv.ComplexTypeTest is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at com.radioserv.ComplexTypeTest at protected com.radioserv.ComplexTypeTest com.radioserv.jaxws.TestResponse._return at com.radioserv.jaxws.TestResponse com.radioserv.ComplexTypeTest does not have a no-arg default constructor. this problem is related to the following location: at com.radioserv.ComplexTypeTest at protected com.radioserv.ComplexTypeTest com.radioserv.jaxws.TestResponse._return at com.radioserv.jaxws.TestResponse</faultstring>
    <detail />
    </soapenv:Fault>

    as expected.

    So here's real question : how should we expose OSGi services with complex in/out parameters over WS?
    We had the similar issue with http binding, but solved it by exposing interface that accepts JSONObjects.
    Another update
    After careful studying of JAXB documentation, it looks like it is possible to use interfaces in method calls
    We need to define Adapter
    public static class Adapter extends XmlAdapter<Document,DocumentInterface> {
    @Override
    public DocumentInterface unmarshal(Document v) throws Exception {
    // TODO Auto-generated method stub
    return v;
    }
    @Override
    public Document marshal(DocumentInterface v) throws Exception {
    // TODO Auto-generated method stub
    return (Document)v;
    }
    }
    Than annotate interface with following:
    @XmlJavaTypeAdapter(value=com.jaxb.test.Document.Adapter.class,type=com.jaxb.test.DocumentInterface.class)
    That works perfect

    Still problem, we can't have interface and implementation in different packages (interface will point to implementation)..

    There's another option to specify this annotation : use package-info.java
    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters
    ({
    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=com.jaxb.test.Document.Adapter.class,type=com.jaxb.test.DocumentInterface.class)
    })

    For some reason it doesn't work. i put it to all possible packages - still no luck.. Maybe OSGi ignores package-info.java?
  • SystemAdmin
    SystemAdmin
    126 Posts

    Re: implementation.osgi &#38; binding.ws

    ‏2011-08-23T14:27:55Z  
    • izhd
    • ‏2011-08-19T23:43:56Z
    Another update
    After careful studying of JAXB documentation, it looks like it is possible to use interfaces in method calls
    We need to define Adapter
    public static class Adapter extends XmlAdapter<Document,DocumentInterface> {
    @Override
    public DocumentInterface unmarshal(Document v) throws Exception {
    // TODO Auto-generated method stub
    return v;
    }
    @Override
    public Document marshal(DocumentInterface v) throws Exception {
    // TODO Auto-generated method stub
    return (Document)v;
    }
    }
    Than annotate interface with following:
    @XmlJavaTypeAdapter(value=com.jaxb.test.Document.Adapter.class,type=com.jaxb.test.DocumentInterface.class)
    That works perfect

    Still problem, we can't have interface and implementation in different packages (interface will point to implementation)..

    There's another option to specify this annotation : use package-info.java
    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters
    ({
    @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=com.jaxb.test.Document.Adapter.class,type=com.jaxb.test.DocumentInterface.class)
    })

    For some reason it doesn't work. i put it to all possible packages - still no luck.. Maybe OSGi ignores package-info.java?
    Hi izhd,

    I don't know the answer off the top of my head. However, even if you make this work, like you noted, your interface still ends up with a dependency (via the annotation) on a specific impl class.

    Since this probably isn't what you want, let me suggest a different approach.

    Why don't you use the impl class, Document, as the parameter type for services that you intend to expose remotely using SCA bindings, while using DocumentInterface for OSGi-level services within the OSGi application?

    There are some fundamental issues with mapping Java interfaces to and from XML and XSD, and JAXB (the standard which SCA uses to define the mapping) does not attempt to solve them.

    I recognize that the RAD OSGI+SCA sample doesn't go into the depth necessary to appreciate this approach. It's useful in showing some of the actions necessary to use an OSGi application as an SCA component impl, but it doesn't address this important aspect of app development.

    You could certainly, however, use the bottom-up approach outlined in this tutorial to expose the new remotable SCA service (the one exposing the Document impl class) as a Web Service without having to generate WSDL at development time.

    The net is that you lose the ability to have a single interface and a single parameter type used in both the SCA, remotable, as well as the OSGi, pass-by-reference services. The distinction between local and remotables services becomes visible and something you have to pay attention to.

    Along these lines, let me link to a devWorks article giving some perspective on how to think about the different technologies and how to combine them.

    http://www.ibm.com/developerworks/webservices/library/ws-soa-granularity/

    (Substitute "OSGi" for "Spring" when reading this.. I'm not aware of a more up to date article. I know it doesn't go into detail like we're discussing but hopefully at least provides an interesting mindset for approaching the problem).

    I'll be interested to hear your thoughts on this idea. Please let me know if it's not clear what I'm suggesting.
  • izhd
    izhd
    27 Posts

    Re: implementation.osgi &#38; binding.ws

    ‏2011-08-23T18:29:51Z  
    Hi izhd,

    I don't know the answer off the top of my head. However, even if you make this work, like you noted, your interface still ends up with a dependency (via the annotation) on a specific impl class.

    Since this probably isn't what you want, let me suggest a different approach.

    Why don't you use the impl class, Document, as the parameter type for services that you intend to expose remotely using SCA bindings, while using DocumentInterface for OSGi-level services within the OSGi application?

    There are some fundamental issues with mapping Java interfaces to and from XML and XSD, and JAXB (the standard which SCA uses to define the mapping) does not attempt to solve them.

    I recognize that the RAD OSGI+SCA sample doesn't go into the depth necessary to appreciate this approach. It's useful in showing some of the actions necessary to use an OSGi application as an SCA component impl, but it doesn't address this important aspect of app development.

    You could certainly, however, use the bottom-up approach outlined in this tutorial to expose the new remotable SCA service (the one exposing the Document impl class) as a Web Service without having to generate WSDL at development time.

    The net is that you lose the ability to have a single interface and a single parameter type used in both the SCA, remotable, as well as the OSGi, pass-by-reference services. The distinction between local and remotables services becomes visible and something you have to pay attention to.

    Along these lines, let me link to a devWorks article giving some perspective on how to think about the different technologies and how to combine them.

    http://www.ibm.com/developerworks/webservices/library/ws-soa-granularity/

    (Substitute "OSGi" for "Spring" when reading this.. I'm not aware of a more up to date article. I know it doesn't go into detail like we're discussing but hopefully at least provides an interesting mindset for approaching the problem).

    I'll be interested to hear your thoughts on this idea. Please let me know if it's not clear what I'm suggesting.
    Hi Scott,

    Actually my intent was to include that annotation into implementation bundle via package-info, and the problem is that I couldn't do it.
    I'm not aware of problems with JAXB - do you have any reference where I can find more info about it?
    The article you mentioned is pretty good for high-level understanding of the problem.
    One of the things I was looking in SCA is transport independence. The documentation states that it's really to expose service using any binding. However, it's not entirely true, and I believe all limitations should be listed somewhere. So far I worked with http.binding and ws.binding. The http.binding has limitation (described in documentation) that it cannot be used to upload files. Fine - we have workaround for that. Another problem - can't have complex types in the interfaces - that one I believe is not mentioned anywhere. Just because of that I had to create & expose another interface, that accepts JSONObject.
    Ok, now we need to expose some of the services as Web Services. Another problem - can't use parameters of type interface. The article you referred me to mentions, that it is better to use document-style parameters for course-grained services. However it shies away from providing sample for it. I would guess that SDO is good fit here and that it would solve my problem with interfaces. But can I use it with http.binding? If yes, I can probably create one service and have 2 bindings, but if not - (and I believe it's not possible) - I will end up with 2 interfaces and 2 implementations created just to provide transport support.
    Next, I will probably need JMS or EJB binding for the same service, will I end up creating interfaces & implementations for them as well? Don't you think that it's kind of defeat the whole purpose "transport independence"?

    So is that technology or implementation problem? Is SCA & OSGi tandem as implemented by IBM ready for the prime-time?

    Thanks,
    Igor
  • SteveKinder
    SteveKinder
    14 Posts

    Re: implementation.osgi &#38; binding.ws

    ‏2011-08-25T13:09:34Z  
    • izhd
    • ‏2011-08-23T18:29:51Z
    Hi Scott,

    Actually my intent was to include that annotation into implementation bundle via package-info, and the problem is that I couldn't do it.
    I'm not aware of problems with JAXB - do you have any reference where I can find more info about it?
    The article you mentioned is pretty good for high-level understanding of the problem.
    One of the things I was looking in SCA is transport independence. The documentation states that it's really to expose service using any binding. However, it's not entirely true, and I believe all limitations should be listed somewhere. So far I worked with http.binding and ws.binding. The http.binding has limitation (described in documentation) that it cannot be used to upload files. Fine - we have workaround for that. Another problem - can't have complex types in the interfaces - that one I believe is not mentioned anywhere. Just because of that I had to create & expose another interface, that accepts JSONObject.
    Ok, now we need to expose some of the services as Web Services. Another problem - can't use parameters of type interface. The article you referred me to mentions, that it is better to use document-style parameters for course-grained services. However it shies away from providing sample for it. I would guess that SDO is good fit here and that it would solve my problem with interfaces. But can I use it with http.binding? If yes, I can probably create one service and have 2 bindings, but if not - (and I believe it's not possible) - I will end up with 2 interfaces and 2 implementations created just to provide transport support.
    Next, I will probably need JMS or EJB binding for the same service, will I end up creating interfaces & implementations for them as well? Don't you think that it's kind of defeat the whole purpose "transport independence"?

    So is that technology or implementation problem? Is SCA & OSGi tandem as implemented by IBM ready for the prime-time?

    Thanks,
    Igor
    Hi Igor,

    A couple of us IBMers from SCA and OSGi got together this morning to discuss a good approach for addressing the issues you are experiencing. We have a couple of ideas, but depending on your usage and what design or architectural perspective you are coming from, one or another may be better suited for you. We felt like a teleconference might help get us to a quicker answer for you and reduce some of the frustration you might be feeling going back and forth on the forum. Since this thread may also be followed by other parties now or after the fact -- we would also post a summary of salient points made in the call as we come to some conclusions.

    If a teleconference is an attractive alternative for you, please contact me: kinder@us.ibm.com with a few available times and I will arrange the particulars. If you'd rather prefer to keep to the forum, we are happy to also continue the discussion here -- just post that is your desire.

    Thanks,
    Steve
  • izhd
    izhd
    27 Posts

    Re: implementation.osgi &#38; binding.ws

    ‏2011-08-25T15:58:49Z  
    Hi Igor,

    A couple of us IBMers from SCA and OSGi got together this morning to discuss a good approach for addressing the issues you are experiencing. We have a couple of ideas, but depending on your usage and what design or architectural perspective you are coming from, one or another may be better suited for you. We felt like a teleconference might help get us to a quicker answer for you and reduce some of the frustration you might be feeling going back and forth on the forum. Since this thread may also be followed by other parties now or after the fact -- we would also post a summary of salient points made in the call as we come to some conclusions.

    If a teleconference is an attractive alternative for you, please contact me: kinder@us.ibm.com with a few available times and I will arrange the particulars. If you'd rather prefer to keep to the forum, we are happy to also continue the discussion here -- just post that is your desire.

    Thanks,
    Steve
    Thank you Steve
    I've sent you email.

    Regards,
    Igor