Great!

For sure, would be nice see a public version of your project. Can you share
a gist or a public git repo?

Thanks ;-)

Em 26 de jul de 2017 1:04 AM, "Matthew Shaw" <
[email protected]> escreveu:

> Hi,
>
> For anyone that's interested I got a working solution integrating an ejb2
> running on a remote instance of weblogic10.3.6 using karaf and camel as my
> client.
>
> The fundamental issue was that when using weblogic's t3 protocol (whatever
> you do don't try this with CORBA), the jndi lookup and other jndi like
> innvocations use the thread context class loader. So wherever you make jndi
> innvocations you must set the thread context class loader to the bundle
> class loader.
>
> This took me weeks to solve with a lot of pain in between. So if you are
> experiencing similar reqs let me know and I'd be happy to share the source
> code with you.
>
> I also removed bluerprint and use declarative services only, this made
> debugging a heck a lot of easier rather than sifting through proxy stack
> traces.
>
> Anyhow, hope it helps someone. My life and understanding of osgi are a lot
> better now! :-) lol
>
> Cheers,
> Matt.
>
> -----Original Message-----
> From: Claus Ibsen [mailto:[email protected]]
> Sent: Monday, 10 July 2017 5:07 PM
> To: [email protected]
> Subject: Re: camel route to remote EJB using karaf blueprint
>
> You can try from camelContext there is a getApplicationContextClassLoader
> method you can try using.
>
> On Mon, Jul 10, 2017 at 1:37 AM, Matthew Shaw <[email protected].
> gov.au> wrote:
> > Thanks Claus, I can't change the source system, so I have to consume the
> ejb from osgi unfortunately. In the scenario below, I do have it working,
> partially, as you say, I'm now battling classloader issues. Trawling the
> posts I have read about setting the 
> Thread.currentThread().setClassContextLoader()
> to the bundle context, but that does nothing to help me.
> >
> > Would I be correct in assuming that because I am loading the camel
> context via a blueprint and apache aries that I would need to get a hold of
> that classloader? I think my manifest looks pretty good below as I'm
> referencing all the weblogic client stuff correctly through my imports.
> >
> > -----Original Message-----
> > From: Claus Ibsen [mailto:[email protected]]
> > Sent: Sunday, 9 July 2017 5:26 PM
> > To: [email protected]
> > Subject: Re: camel route to remote EJB using karaf blueprint
> >
> > Hi
> >
> > I think you are going on a path where nobody really goes - calling
> remote EJBs (... from OSGi).
> > Then classloading is much more problematic to setup. You would need to
> install the WebLogic EJB client and also make sure to have all the right
> package imports in your application bundle etc.
> >
> > I really don't recommend using remote EJB calls, you end up with a tight
> coupling on Java, Java serialization etc. Are you not able to use another
> protocol in the communication to WebLogic?
> >
> > If you really must, then try first to get a non OSGi example / unit test
> etc up and running so you at least know that this part works.
> > Then its "fighting" the OSGi classloading and get all that sorted.
> >
> >
> >
> > On Fri, Jul 7, 2017 at 3:51 AM, Matthew Shaw <
> [email protected]> wrote:
> >> As an addendum, I think the issue maybe that using jndi and the
> weblogic initial context is outside the camel context, but the way I am
> invoking it. Which in turn, will be trying to load the same classes
> required again, through a completely separate class loader?
> >>
> >> -----Original Message-----
> >> From: Matthew Shaw [mailto:[email protected]]
> >> Sent: Friday, 7 July 2017 11:07 AM
> >> To: [email protected]
> >> Subject: camel route to remote EJB using karaf blueprint
> >>
> >> Hi All,
> >>
> >> I've been banging my head against the wall now for a week, trying to
> get a camel route going which consumes a remote service on an EJB2
> container in weblogic 10.3. I keep getting class versioning issues between
> my client and the server.I have the exact same versions of the server jars
> in karaf as bundles and I import them through my manifest.  My bundle
> installs ok into karaf with a state of "Active" and the camel routes start
> up. I'm a newbie in the osgi, camel world.
> >>
> >> I'm running camel 2.19.1 in apache karaf 4.1.1.
> >>
> >> My blueprint looks like this:
> >>
> >> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
> >>            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> >>            xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-
> cm/v1.0.0"
> >>            xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws";
> >>            xmlns:cxf="http://cxf.apache.org/blueprint/core";
> >>            xmlns:camel="http://camel.apache.org/schema/blueprint";
> >>            xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf
> "
> >>            xsi:schemaLocation="
> >>              http://www.osgi.org/xmlns/blueprint/v1.0.0
> https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
> >>              http://cxf.apache.org/blueprint/jaxws
> http://cxf.apache.org/schemas/blueprint/jaxws.xsd
> >>              http://cxf.apache.org/blueprint/core
> http://cxf.apache.org/schemas/blueprint/core.xsd
> >>              ">
> >>
> >>   <bean id="eTimesheetMediationRoutes"
> >> class="au.gov.qld.ambulance.services.legacywrapper.eTimesheetMediatio
> >> n
> >> "/>
> >>
> >>   <bean id="eTimesheetEJB2Bean"
> >> class="au.gov.qld.ambulance.services.legacywrapper.eTimesheetEJB2Bean"
> >> />
> >>
> >>   <camelContext id="camel" xmlns="http://camel.apache.
> org/schema/blueprint">
> >>     <routeBuilder ref="eTimesheetMediationRoutes"/>
> >>   </camelContext>
> >>
> >> </blueprint>
> >>
> >> My manifest is as follows:
> >>
> >> Manifest-Version: 1.0
> >> Bnd-LastModified: 1499385820689
> >> Build-Jdk: 1.8.0_131
> >> Built-By: mshaw
> >> Bundle-Blueprint: OSGI-INF/blueprint/camel-context.xml
> >> Bundle-ManifestVersion: 2
> >> Bundle-Name: legacywrapper
> >> Bundle-SymbolicName: au.gov.qld.ambulance.tams.legacywrapper
> >> Bundle-Version: 0.0.1.SNAPSHOT
> >> Created-By: Apache Maven Bundle Plugin
> >> Export-Package:
> >> au.gov.qld.ambulance.services.legacywrapper;uses:="au.go
> >> v.qld.des.aftimesheet.dto,javax.naming,org.apache.camel.builder";vers
> >> i
> >> o
> >> n="0.0.1",au.gov.qld.ambulance.services.legacywrapper.domain;uses:="j
> >> a v ax.xml.bind,javax.xml.bind.annotation";version="0.0.1"
> >> Import-Package:
> >> au.gov.qld.des.aftimesheet.dto;version="0.0.0",au.gov.ql
> >> d.des.aftimesheet.ejb;version="0.0.0",au.gov.qld.des.aftimesheet.exce
> >> p
> >> t
> >> ion;version="0.0.0",com.fasterxml.jackson.annotation;version="[2.8,3)"
> >> ,
> >> com.fasterxml.jackson.databind;version="[2.8,3)",javax.ejb,javax.nami
> >> n
> >> g
> >> ,javax.rmi,javax.xml.bind,javax.xml.bind.annotation,javax.xml.namespa
> >> c
> >> e
> >> ,org.apache.camel;version="[2.19,3)",org.apache.camel.builder;version="
> >> [2.19,3)",org.apache.camel.model;version="[2.19,3)",org.apache.camel.
> >> m
> >> o
> >> del.rest;version="[2.19,3)",org.osgi.service.blueprint;version="[1.0.
> >> 0
> >> ,
> >> 2.0.0)",org.restlet.data,org.slf4j;version="[1.7,2)",au.gov.qld.des.a
> >> f
> >> t
> >> imesheet.officer.dto;version="0.0.0",weblogic.jndi,javax.rmi.CORBA,org.
> >> omg.CORBA,org.omg.CORBA.portable,org.omg.CORBA_2_3,org.omg.CORBA_2_3.
> >> p
> >> o
> >> rtable
> >> Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
> >> Tool: Bnd-3.3.0.201609221906
> >>
> >> My route builder impl class:
> >>
> >>
> >> public class eTimesheetMediation extends RouteBuilder {
> >>
> >>     Logger logger =
> >> LoggerFactory.getLogger(eTimesheetMediation.class);
> >>
> >>     @BeanInject("eTimesheetEJB2Bean")
> >>     eTimesheetEJB2Bean eTimesheetEJB2Bean;
> >>
> >>     @Override
> >>     public void configure() throws Exception {
> >>
> >>
> >> restConfiguration().component("restlet").host("localhost").port(8095).
> >> bindingMode(RestBindingMode.json);
> >>
> >>         rest("/services/legacywrapper/etimesheet")
> >>                 .post()
> >>                 .consumes(MediaType.APPLICATION_JSON.getName())
> >>                 .type(ETimesheetRequest.class)
> >>                 .to("direct:extractTimesheetId");
> >>
> >>         from("direct:extractTimesheetId")
> >>                 .process(new Processor() {
> >>                     @Override
> >>                     public void process(Exchange exchange) throws
> Exception {
> >>                         ETimesheetRequest eTimesheetRequest =
> exchange.getIn().getBody(ETimesheetRequest.class);
> >>                         exchange.getIn().setBody(eTimesheetRequest.
> getTimesheetId());
> >>                     }
> >>                 })
> >>                 .to("direct:etimesheetGet");
> >>
> >>
> >>         from("direct:etimesheetGet")
> >>                 .doTry()
> >>                     .bean(eTimesheetEJB2Bean, "mediate")
> >>                     .log(LoggingLevel.INFO,"Timesheet successfully
> transformed")
> >>                     .convertBodyTo(String.class, "UTF-8")
> >>                 .doCatch(Exception.class)
> >>                     .log(LoggingLevel.ERROR
> ,exceptionMessage().toString())
> >>                     .throwException(new RuntimeException(
> exceptionMessage().toString()))
> >>                 .endDoTry();
> >>
> >>
> >>     }
> >> }
> >>
> >>
> >> My ejb client code / bean:
> >>
> >>
> >> public class eTimesheetEJB2Bean {
> >>
> >>     public String mediate(Integer eTimesheetId) {
> >>
> >>         Hashtable env = new Hashtable();
> >>         env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.
> WLInitialContextFactory");
> >>         env.put(Context.PROVIDER_URL, "t3://poldesaps02:5013");
> >>         env.put(Context.SECURITY_PRINCIPAL, "testuser4");
> >>         env.put(Context.SECURITY_CREDENTIALS, "passw0rd");
> >>
> >>         Context ic = null;
> >>
> >>         try {
> >>             ic = new InitialContext(env);
> >>         }catch (NamingException e) {
> >>             throw new RuntimeException(e);
> >>         }
> >>
> >>         return marshallTimesheetToJSON(ic ,getTimesheet(ic,
> >> eTimesheetId));
> >>
> >>     }
> >>
> >>
> >>
> >>     public TimesheetTransferObject getTimesheet (Context ic, Integer
> eTimesheetId) {
> >>         Object homeObject = null;
> >>
> >>         try {
> >>             homeObject = ic.lookup(TimesheetSessionFacadeHome.
> JNDI_NAME);
> >>         } catch (NamingException e) {
> >>             throw new RuntimeException(e);
> >>         }
> >>
> >>         TimesheetSessionFacadeHome home =
> >> (TimesheetSessionFacadeHome) PortableRemoteObject.narrow(homeObject,
> >> TimesheetSessionFacadeHome.class);
> >>
> >>         TimesheetSessionFacade remote = null;
> >>         try {
> >>             remote = (TimesheetSessionFacade)
> PortableRemoteObject.narrow(home.create(), TimesheetSessionFacade.class);
> >>             TimesheetTransferObject result = remote.getTimesheet(
> eTimesheetId);
> >> //            TimesheetTransferObject result = new
> TimesheetTransferObject();
> >>
> >>             return result;
> >>         } catch (ClassCastException e) {
> >>             throw new RuntimeException(e);
> >>         } catch (RemoteException e) {
> >>             throw new RuntimeException(e);
> >>         } catch (CreateException e) {
> >>             throw new RuntimeException(e);
> >>         }catch (AFTimesheetException e) {
> >>             throw new RuntimeException(e);
> >>         }
> >>     }
> >>
> >>     private String marshallTimesheet (Context ic,
> >> TimesheetTransferObject timesheet) {
> >>
> >>         String xml = "";
> >>         ByteArrayOutputStream baos = new ByteArrayOutputStream();
> >>
> >>         try {
> >>             JAXBContext jc = JAXBContext.newInstance(String.class,
> TimesheetTransferObject.class);
> >>             JAXBIntrospector introspector = jc.createJAXBIntrospector();
> >>             Marshaller marshaller = jc.createMarshaller();
> >>             marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
> >>             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
> true);
> >>             if (null == introspector.getElementName(timesheet)) {
> >>                 JAXBElement jaxbElement = new JAXBElement(new
> >> QName("http://services.ambulance.qld.gov.au/data/services/corporate/h
> >> r i/timeandattendance", "Timesheet", "ta"), timesheet.getClass(),
> >> timesheet);
> >>
> >>                 marshaller.marshal(jaxbElement, baos);
> >>             } else {
> >>                 marshaller.marshal(timesheet, baos);
> >>             }
> >>             xml += baos.toString();
> >>         } catch (JAXBException e) {
> >>             throw new RuntimeException(e);
> >>         }
> >>         return xml;
> >>     }
> >>
> >>     private String marshallTimesheetToJSON (Context ic,
> >> TimesheetTransferObject timesheet) {
> >>
> >>         try {
> >>             ObjectMapper objectMapper = new ObjectMapper();
> >>             objectMapper.setSerializationInclusion(
> JsonInclude.Include.NON_NULL);
> >>             objectMapper.addMixIn(MealBrokenTransferObject.class,
> MealBrokenTransferObjectMixIn.class);
> >>             objectMapper.addMixIn(ShiftTransferObject.class,
> ShiftTransferObjectMixIn.class);
> >>             objectMapper.addMixIn(TimesheetTransferObject.class,
> TimesheetTransferObjectMixIn.class);
> >>             objectMapper.addMixIn(CallOutTransferObject.class,
> CalloutTransferObjectMixIn.class);
> >>             objectMapper.addMixIn(CallOutCaseTransferObject.class,
> CallOutCaseTransferObjectMixIn.class);
> >>             objectMapper.addMixIn(AllowanceTransferObject.class,
> AllowanceTransferObjectMixIn.class);
> >>             return objectMapper.writeValueAsString(timesheet);
> >>         } catch (Exception e) {
> >>             throw new RuntimeException(e);
> >>         }
> >>
> >>     }
> >>
> >> }
> >>
> >>
> >> Any help / insight would be really appreciated.
> >>
> >> Cheers,
> >> Matt.
> >>
> >>
> >>
> >>
> >>
> >> This email, including any attachments sent with it, is confidential and
> for the sole use of the intended recipient(s). This confidentiality is not
> waived or lost, if you receive it and you are not the intended
> recipient(s), or if it is transmitted/received in error.
> >>
> >> Any unauthorised use, alteration, disclosure, distribution or review of
> this email is strictly prohibited. The information contained in this email,
> including any attachment sent with it, may be subject to a statutory duty
> of confidentiality if it relates to health service matters.
> >>
> >> If you are not the intended recipient(s), or if you have received this
> email in error, you are asked to immediately notify the sender. You should
> also delete this email, and any copies, from your computer system network
> and destroy any hard copies produced.
> >>
> >> If not an intended recipient of this email, you must not copy,
> distribute or take any action(s) that relies on it; any form of disclosure,
> modification, distribution and/or publication of this email is also
> prohibited.
> >>
> >> Although the Queensland Ambulance Service takes all reasonable steps to
> ensure this email does not contain malicious software, the Queensland
> Ambulance Service does not accept responsibility for the consequences if
> any person's computer inadvertently suffers any disruption to services,
> loss of information, harm or is infected with a virus, other malicious
> computer programme or code that may occur as a consequence of receiving
> this email.
> >>
> >> Unless stated otherwise, this email represents only the views of the
> sender and not the views of the Queensland Government.
> >>
> >> *********************************************************************
> >> *
> >> **********
> >>
> >> The content presented in this publication is distributed by the
> Queensland Government as an information source only. The State of
> Queensland makes no statements, representations or warranties about the
> accuracy, completeness or reliability of any information contained in this
> publication. The State of Queensland disclaims all responsibility and all
> liability (including without limitation for liability in negligence) for
> all expenses, losses, damages and costs you might incur as a result of the
> information being inaccurate or incomplete in any way, and for any reason
> reliance was placed on such information.
> >> This email, including any attachments sent with it, is confidential and
> for the sole use of the intended recipient(s). This confidentiality is not
> waived or lost, if you receive it and you are not the intended
> recipient(s), or if it is transmitted/received in error.
> >>
> >> Any unauthorised use, alteration, disclosure, distribution or review of
> this email is strictly prohibited. The information contained in this email,
> including any attachment sent with it, may be subject to a statutory duty
> of confidentiality if it relates to health service matters.
> >>
> >> If you are not the intended recipient(s), or if you have received this
> email in error, you are asked to immediately notify the sender. You should
> also delete this email, and any copies, from your computer system network
> and destroy any hard copies produced.
> >>
> >> If not an intended recipient of this email, you must not copy,
> distribute or take any action(s) that relies on it; any form of disclosure,
> modification, distribution and/or publication of this email is also
> prohibited.
> >>
> >> Although the Queensland Ambulance Service takes all reasonable steps to
> ensure this email does not contain malicious software, the Queensland
> Ambulance Service does not accept responsibility for the consequences if
> any person's computer inadvertently suffers any disruption to services,
> loss of information, harm or is infected with a virus, other malicious
> computer programme or code that may occur as a consequence of receiving
> this email.
> >>
> >> Unless stated otherwise, this email represents only the views of the
> sender and not the views of the Queensland Government.
> >>
> >> *********************************************************************
> >> *
> >> **********
> >>
> >> The content presented in this publication is distributed by the
> Queensland Government as an information source only. The State of
> Queensland makes no statements, representations or warranties about the
> accuracy, completeness or reliability of any information contained in this
> publication. The State of Queensland disclaims all responsibility and all
> liability (including without limitation for liability in negligence) for
> all expenses, losses, damages and costs you might incur as a result of the
> information being inaccurate or incomplete in any way, and for any reason
> reliance was placed on such information.
> >>
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > http://davsclaus.com @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >
> > This email, including any attachments sent with it, is confidential and
> for the sole use of the intended recipient(s). This confidentiality is not
> waived or lost, if you receive it and you are not the intended
> recipient(s), or if it is transmitted/received in error.
> >
> > Any unauthorised use, alteration, disclosure, distribution or review of
> this email is strictly prohibited. The information contained in this email,
> including any attachment sent with it, may be subject to a statutory duty
> of confidentiality if it relates to health service matters.
> >
> > If you are not the intended recipient(s), or if you have received this
> email in error, you are asked to immediately notify the sender. You should
> also delete this email, and any copies, from your computer system network
> and destroy any hard copies produced.
> >
> > If not an intended recipient of this email, you must not copy,
> distribute or take any action(s) that relies on it; any form of disclosure,
> modification, distribution and/or publication of this email is also
> prohibited.
> >
> > Although the Queensland Ambulance Service takes all reasonable steps to
> ensure this email does not contain malicious software, the Queensland
> Ambulance Service does not accept responsibility for the consequences if
> any person's computer inadvertently suffers any disruption to services,
> loss of information, harm or is infected with a virus, other malicious
> computer programme or code that may occur as a consequence of receiving
> this email.
> >
> > Unless stated otherwise, this email represents only the views of the
> sender and not the views of the Queensland Government.
> >
> > **********************************************************************
> > **********
> >
> > The content presented in this publication is distributed by the
> Queensland Government as an information source only. The State of
> Queensland makes no statements, representations or warranties about the
> accuracy, completeness or reliability of any information contained in this
> publication. The State of Queensland disclaims all responsibility and all
> liability (including without limitation for liability in negligence) for
> all expenses, losses, damages and costs you might incur as a result of the
> information being inaccurate or incomplete in any way, and for any reason
> reliance was placed on such information.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
> This email, including any attachments sent with it, is confidential and
> for the sole use of the intended recipient(s). This confidentiality is not
> waived or lost, if you receive it and you are not the intended
> recipient(s), or if it is transmitted/received in error.
>
> Any unauthorised use, alteration, disclosure, distribution or review of
> this email is strictly prohibited. The information contained in this email,
> including any attachment sent with it, may be subject to a statutory duty
> of confidentiality if it relates to health service matters.
>
> If you are not the intended recipient(s), or if you have received this
> email in error, you are asked to immediately notify the sender. You should
> also delete this email, and any copies, from your computer system network
> and destroy any hard copies produced.
>
> If not an intended recipient of this email, you must not copy, distribute
> or take any action(s) that relies on it; any form of disclosure,
> modification, distribution and/or publication of this email is also
> prohibited.
>
> Although the Queensland Ambulance Service takes all reasonable steps to
> ensure this email does not contain malicious software, the Queensland
> Ambulance Service does not accept responsibility for the consequences if
> any person's computer inadvertently suffers any disruption to services,
> loss of information, harm or is infected with a virus, other malicious
> computer programme or code that may occur as a consequence of receiving
> this email.
>
> Unless stated otherwise, this email represents only the views of the
> sender and not the views of the Queensland Government.
>
> ************************************************************
> ********************
>
> The content presented in this publication is distributed by the Queensland
> Government as an information source only. The State of Queensland makes no
> statements, representations or warranties about the accuracy, completeness
> or reliability of any information contained in this publication. The State
> of Queensland disclaims all responsibility and all liability (including
> without limitation for liability in negligence) for all expenses, losses,
> damages and costs you might incur as a result of the information being
> inaccurate or incomplete in any way, and for any reason reliance was placed
> on such information.
>

Reply via email to