axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Simioni <brunosimi...@gmail.com>
Subject Re: JAXB and JAXWS annotations (marshall and unmarshall) problems with ArrayLists
Date Thu, 09 Jun 2011 03:04:46 GMT
Thank you in advance for your reply. I'm replying for the list.

I do understand the use of three main args in JAXBWrapperTool: The class to
be wrapped, a list of expected child names in XML, and a hashmap linking the
expected names in XML and the instances of objects.

But, isn't there an easiest way of doing the same thing only using Java 1.6
spec, instead of using a custom Axis2 wrapper tool (that makes me spend a
lot of work for just getting some classes to be sent to the service side). ?

I do appreciate some conversation around this.

Thanks!
Bruno


On Mon, Jun 6, 2011 at 11:12 PM, Martin Gainty <mgainty@hotmail.com> wrote:

>  here is an example first the service side
> public class GetPrice {
>     @XmlElement(required = true)
>     protected String fund;
>     @XmlElement(name = "holdings.", required = true)
>     protected String holdings;
>     @XmlElement(required = true)
>     protected String nav;
>  <snip>
> }
>
> the client calls GetPrice but you will need to use JAXBWrapperTool to wrap
> the composite type first
>     try{
>             JAXBWrapperTool wrapper = new JAXBWrapperToolImpl();
> //put your Service Stub class name here
>             String jaxbClassName = "org.test.stock1.GetPrice";
>             Class jaxbClass;
>             try {
>                 jaxbClass = Class.forName(jaxbClassName, false,
> ClassLoader.getSystemClassLoader());
>             } catch (Exception e){
>                 jaxbClass = Class.forName(jaxbClassName, false,
> this.getClass().getClassLoader());
>             }
> //in the schema the getPrice complexDataType looks like:
> //<complexType name="getPrice">
> //  <complexContent>
> //    <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
> //      <sequence>
> //        <element name="fund" type="{
> http://www.w3.org/2001/XMLSchema}string"/>
> //        <element name="holdings." type="{
> http://www.w3.org/2001/XMLSchema}string"/>
> //        <element name="nav" type="{
> http://www.w3.org/2001/XMLSchema}string"/>
> //      </sequence>
> //    </restriction>
> //  </complexContent>
> //</complexType>
>             ArrayList<String> childNames = new ArrayList<String>();
>             String fund ="fund";
>             String fundName = new String("PRGFX");
>             String holding = "holdings.";
>             String topHolding = new String("GE");
>             String nav ="nav";
>             String navInMillion = new String("700");
>             childNames.add(fund);
>             childNames.add(holding);
>             childNames.add(nav);
>             Map<String, Object> childObjects= new WeakHashMap<String,
> Object>();
>             childObjects.put(fund, fundName);
>             childObjects.put(holding, topHolding);
>             childObjects.put(nav, navInMillion);
> //call org.test.stock1.GetPrice of ArrayList<String> populated with "fund",
> "holdings","nav" in childNames
>             Object jaxbObject = wrapper.wrap(jaxbClass, childNames,
> childObjects);
>             org.test.stock1.GetPrice getPrice =
> (org.test.stock1.GetPrice)jaxbObject;
>
>         }catch(JAXBWrapperException e){
>             e.printStackTrace();
>         }catch(ClassNotFoundException e){
>             e.printStackTrace();
>         }
>
> Martin Gainty
> ______________________________________________
> Jogi és Bizalmassági kinyilatkoztatás/Verzicht und
> Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> Ez az üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
> jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának készítése
> nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és semmiféle jogi
> alkalmazhatósága sincs.  Mivel az electronikus üzenetek könnyen
> megváltoztathatóak, ezért minket semmi felelöség nem terhelhet ezen üzenet
> tartalma miatt.
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
> Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
> dient lediglich dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.
>
>
>
>
>
>
> ------------------------------
> From: brunosimioni@gmail.com
> Date: Mon, 6 Jun 2011 21:43:51 -0300
> Subject: JAXB and JAXWS annotations (marshall and unmarshall) problems with
> ArrayLists
> To: java-user@axis.apache.org
>
>
> Hi,
>
> I'm developing a client-server application with messaging transmission
> through JAX-WS and JAXB annotations, but I'm having some trouble on that
> process. I'm needing help to understand and solve a set of problems in this
> process.
>
> On Axis2 1.5.4;
>
> Server JAX-WS annotated webservice.
>
> @WebService(name="Persons.Info", serviceName="Persons", portName="Info")
> @BindingType(value="http://www.w3.org/2003/05/soap/bindings/HTTP/") //
> yes, SOAP1.2
> public class Info
> {
>     @WebMethod
>     public @WebResult Person aPersonInfoSerivceTest (@WebParam Person p)
> throws Exception
>     {
>         System.out.println(p); // returns Object
>         System.out.println(p.name); // returns something correct
>         System.out.println(p.pets); // its an ArrayList<String>, and
> returns Null.
>
>         p.serviceTested = true;
>
>         return p;
>     }
> }
>
> SOAPMonitor gives me the sent message, and it is correct. I'm just
> unmarshalling all classes through Dispatcher client, but when service
> executes no error occur, and the "Person p" parameter is not created
> correctly.
>
> I've tried the same thing only using JAXB to marshall and unmarshall this
> objects, thought storing XML into files, instead of using JAXWS and
> Dispatcher, locally, and it works correctly.
>
> The problem occurs when mounting ArrayList from XML SOAP message.
>
> Thats the client snippet.
> Service service = Service.create(serviceName);
> service.addPort(portName, SOAPBinding.SOAP12HTTP_BINDING, endpointAddress);
> JAXBContext jaxbcontext = JAXBContext.newInstance(Person.class);
> Dispatch<Object> dispatch = service.createDispatch(portName, jaxbcontext,
> Service.Mode.PAYLOAD);
> BindingProvider bp = (BindingProvider) dispatch;
> Map<String, Object> rc = bp.getRequestContext();
> rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
> rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, "aServiceTest");
> Object res = dispatch.invoke(per);
>
> Does someone has example files with a working example of JAXB and JAXWS
> service-client simple application, using ArrayLists<T> ?
>
> Thanks.
> Bruno.
>

Mime
View raw message