cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MagnusEd <mede...@gmail.com>
Subject Re: Getting lists as I want them...?
Date Fri, 27 Mar 2009 08:29:15 GMT

Thanks for your help. After testing with wrapper beans and XmlElementWrapper,
the only way I got it to work was the following (XmlElementWrapper is not
that much fore method INPUT parameters?):
 
1. Create a wrapper bean for the List<AttributeNameValueBean> 

public class Attributes {
	private List<AttributeNameValueBean> attributes;

	@XmlElement(name = "attribute") // Define each elements name in the list
	public List<AttributeNameValueBean> getAttributes() {
		return attributes;
	}

2. Replace the list with the new wrapper bean
@WebService(targetNamespace = ".....")
public interface ProductService
{ 
public ProductListBean findProducts(
	@WebParam(name = "catalog") String catalog, 
	@WebParam(name = "attributes") Attributes attributes);

Then it worked. Just to bad I have to create an unnecessary wrapper bean :-(
Shouldn't there be a way to define how list a represented? Just repeating
attribute directly, or grouped together?? 

Regards,
Magnus


dkulp wrote:
> 
> 
> 
> The ONLY way I can see to do this is to create a wrapper bean for the 
> findProducts method and add an @XmlElementWrapper annotation to the field.  
> It's a shame that that annotation isn't allowed on a parameter so we could
> map 
> it in when we build the wrapper types internally.    Just checked JAXB 2.2
> and 
> it's not allowed on the param there either.  :-(
> 
> Probably the easiest way to get going is to run:
> java2ws -wrapperbean ......
> 
> to produce the wrapper beans and copy the request bean into your project
> and 
> modify it.   You'll need to add the @RequestWrapper annotation to your
> method 
> to pick it up.
> 
> Dan
> 
> 
> On Thu March 26 2009 12:20:05 pm MagnusEd wrote:
>> Hi all. I am having trouble defining my WebService as I want it.
>>
>> Below is a sample how I want the XML to look like when I send it:
>>
>> <com:findProducts>
>> 	<catalog>myCatalog</catalog>
>> 	<attributes>
>> 		<attribute>
>> 			<name>?</name>
>> 			<value>?</value>
>> 		</attribute>
>> 		<attribute>
>> 			<name>?</name>
>> 			<value>?</value>
>> 		</attributes>
>> 	</attributes>
>> </com:findProducts>
>>
>> But after generating from my annotated Java files, I get a contract that
>> defines the XML like the following:
>>
>> <com:findProducts>
>> 	<catalog>myCatalog</catalog>
>> 	<attributes>
>> 		<name>?</name>
>> 		<value>?</value>
>> 	</attributes>
>> 	<attributes>
>> 		<name>?</name>
>> 		<value>?</value>
>> 	</attributes>
>> </com:findProducts>
>>
>>
>> The important Java files are as follows:
>>
>> @WebService(targetNamespace = ".....")
>> public interface ProductService
>> {
>> 	public ProductListBean findProducts(
>> 			@WebParam(name = "catalog") String catalog,
>> 			@WebParam(name = "attributes") List<AttributeNameValueBean>
>> attributes);
>>
>> and
>>
>> @XmlRootElement(name = "attribute")
>> public class AttributeNameValueBean
>> {
>> 	private String name;
>> 	private String value;
>>
>> 	@XmlElement(name = "name",required=true)
>> 	public String getName()
>> 	{
>> 		return name;
>> 	}
>>
>>
>> I thought that defining the list as "attributes" and the
>> AttributeNameValueBean as "attribute" would get me what I want. But
>> apparently not. Anybody got an idea of how to do it differently?
>>
>> Regards,
>> Magnus
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/Getting-lists-as-I-want-them...--tp22725382p22737661.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message