GWT RPC - WebServiceClient

286 views
Skip to first unread message

Stijn Bienkens

unread,
Apr 20, 2011, 3:17:42 AM4/20/11
to Google Web Toolkit
Hello

We are currently looking to optimize some of our GWT projects but we
ran into a few issues.

Most if not all of our data is coming from an OSGI backend.
Communication between the GWT client - GWT RPC - OSGI backend is far
from optimal as we have to write a lot of boiler plate code. To
optimize this we were thinking of including one ( or multiple)
webservices in our OSGI backend using Apache CXF.

On the GWT RPC side we implemented a webservice client using Apache
CXF 2 as well. However the real challenge we are facing is how to use
the CXF generated objects for communication between GWT client and GWT
RPC.

I've came across several posts claiming this was perfectly possible
but so far we haven't been successful.

The Apache CXF generated classes have references to JAXBElement, when
compiling this results in: "No source code is available for type
javax.xml.bind.JAXBElement<T>;"
Using the <super-source> tag we provided the source for JAXBElement,
however this results in more of the same issues for:
javax.xml.namespace.Qname, java.io.ObjectInputStream,
java.lang.ClassNotFoundException, ...

Is there anyway to accomplish this or another path we can follow?

Thank you in advance
Stijn

Chris

unread,
Apr 21, 2011, 8:40:43 PM4/21/11
to Google Web Toolkit
Like you, I read that it was possible but ran into the same issues. I
ended up having to strip down the generated classes to POJO, which
clearly reduces the advantages of using something like JAX-B in the
first place. My understanding is that there are some classes in
javax.xml that will never work correctly in GWT and that it was better
to avoid it at all possible.

If anyone else wants to chime in and prove that we are wrong here,
please feel free to do so.

On Apr 20, 3:17 am, Stijn Bienkens <stijn.bienk...@k2-solutions.eu>
wrote:

Chris

unread,
Apr 22, 2011, 1:18:54 AM4/22/11
to Google Web Toolkit
I can't speak to the CXF issue but I use many JAXB generated objects
across GWT-RPC . The solution I used is detailed here: http://goo.gl/VK2JY
which strictly deals with JAXB annotations (extracting the annotations
into a separate jar).

If for some reason that doesn't suffice I've also had excellent luck
with http://dozer.sourceforge.net/ for translating to DTOs.

Sunit Katkar

unread,
Apr 22, 2011, 11:13:41 AM4/22/11
to google-we...@googlegroups.com
We have exact same situation and it all works. 

We use apache cxf as the communication between the GWT servlets and the API layer on another server.
When the WSDLs are created for the apache cxf, we generate a client side jar and include it in the GWT project. This allows us access to the java objects which are created on API layer side, then transmitted as XML and finally reconstructed on GWT (UI) server side.

Basically the idea is similar to generating a Java client for using your web service and then use it in your GWT servlet.

I would have shared code with you but cannot as its company code and company policy, etc.

Thank you,
Sunit Katkar





--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Armishev, Sergey

unread,
Apr 22, 2011, 5:01:25 PM4/22/11
to google-we...@googlegroups.com

I did this GWT-RPC-WSDL integration and it works fine. Maybe not very much efficient but it works and I made quicly what I needed. I used wscompile to generate POJO java classes from WSDL. That are classes that Web server user for web services communication. They are server side classes. Then I copied server classes to client package and manually editted generated POJO classes to be  GWT RPC compatible. Yes, it is duplication and bad and I would like to have the same classes for both sides but… don’t have time to develop full solution  Then ,Cxf knows nothing about GWT so even POJO classes has references on unsupported Java classes such as Calendar (see below example). I manually editted those file to be GWT RPC compatible. Not a big deal Then I add  “ implements java.io.Serializable”  implementation to class definition. And then in run time translate server side classes to client and back.

Below is POJO file generated by cxf and corresponding class which is GWT-RPC compatible. See Calendar class that is not supported.

 

Let me know if you need more help

-Sergey

 

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

 

package com.idirect.webnms.server.toolkit;

 

 

public class NmsErrorCondition extends com.idirect.webnms.server.toolkit.NmsObject {

    protected java.util.Calendar timeStamp;

    protected com.idirect.webnms.client.toolkit.NmsErrorSeverity errorSeverity;

    protected java.lang.String errorMessage;

   

    public NmsErrorCondition() {

    }

   

    public NmsErrorCondition(int objectType, boolean initialized, java.util.Calendar timeStamp, com.idirect.webnms.client.toolkit.NmsErrorSeverity errorSeverity, java.lang.String errorMessage) {

        this.objectType = objectType;

        this.initialized = initialized;

        this.timeStamp = timeStamp;

        this.errorSeverity = errorSeverity;

        this.errorMessage = errorMessage;

    }

   

    public java.util.Calendar getTimeStamp() {

        return timeStamp;

    }

   

    public void setTimeStamp(java.util.Calendar timeStamp) {

        this.timeStamp = timeStamp;

    }

   

    public com.idirect.webnms.client.toolkit.NmsErrorSeverity getErrorSeverity() {

        return errorSeverity;

    }

   

    public void setErrorSeverity(com.idirect.webnms.client.toolkit.NmsErrorSeverity errorSeverity) {

        this.errorSeverity = errorSeverity;

    }

   

    public java.lang.String getErrorMessage() {

        return errorMessage;

    }

   

    public void setErrorMessage(java.lang.String errorMessage) {

        this.errorMessage = errorMessage;

    }

}

 

And you translate it to

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

 

package com.idirect.webnms.client.toolkit;

 

 

public class NmsErrorCondition extends com.idirect.webnms.client.toolkit.NmsObject {

    protected java.util.Date timeStamp;

    protected com.idirect.webnms.client.toolkit.NmsErrorSeverity errorSeverity;

    protected java.lang.String errorMessage;

    public NmsErrorCondition() {

    }

   

    public NmsErrorCondition(int objectType, boolean initialized, java.util.Date timeStamp, com.idirect.webnms.client.toolkit.NmsErrorSeverity errorSeverity, java.lang.String errorMessage) {

        this.objectType = objectType;

        this.initialized = initialized;

        this.timeStamp = timeStamp;

        this.errorSeverity = errorSeverity;

        this.errorMessage = errorMessage;

    }

   

    public java.util.Date getTimeStamp() {

        return timeStamp;

    }

   

    public void setTimeStamp(java.util.Date timeStamp) {

        this.timeStamp = timeStamp;

    }

   

    public com.idirect.webnms.client.toolkit.NmsErrorSeverity getErrorSeverity() {

        return errorSeverity;

    }

   

    public void setErrorSeverity(com.idirect.webnms.client.toolkit.NmsErrorSeverity errorSeverity) {

        this.errorSeverity = errorSeverity;

    }

   

    public java.lang.String getErrorMessage() {

        return errorMessage;

    }

   

    public void setErrorMessage(java.lang.String errorMessage) {

        this.errorMessage = errorMessage;

    }

 

}

 

And then you need  Calendar – Date translation

                public static java.util.Date get(java.util.Calendar in) {

                                return in.getTime();

                }

 

                public static java.util.Calendar get(java.util.Date in) {

                                Calendar calendar = java.util.Calendar.getInstance();

                                calendar.setTime(in);

                                return calendar;


_____________________________________________________
This electronic message and any files transmitted with it contains
information from iDirect, which may be privileged, proprietary
and/or confidential. It is intended solely for the use of the individual
or entity to whom they are addressed. If you are not the original
recipient or the person responsible for delivering the email to the
intended recipient, be advised that you have received this email
in error, and that any use, dissemination, forwarding, printing, or
copying of this email is strictly prohibited. If you received this email
in error, please delete it and immediately notify the sender.
_____________________________________________________

Sunit Katkar

unread,
Apr 24, 2011, 12:18:01 PM4/24/11
to google-we...@googlegroups.com
Since Apache CXF or any other web service creates POJOs which are not directly usable by GWT, we have taken extra pains to replicate the same POJOs as GWT side POJOs. When servlet makes a call to the web service, whatever objects we get back are anaylysed and then their 'copy' is made into GWT side POJOs. Its tedious, but hey it works and scales too.

Thank you,
Sunit Katkar
Reply all
Reply to author
Forward
0 new messages