mardi 27 mai 2014

services Web - CXF JAXB DynamicClientFactory génère java.lang.ArrayOfString de champ de tableau String - Stack Overflow


I'm trying to generate a generic web service client using CXF's DynamicClientFactory. The standard wsdls are working fine. But in this particular case I've got a serie of "old style" web services programmed in the Java v1.4 era. They work just fine and SoapUI, for example, has no problems creating a client and communicating with them.


Just for the reference this is how I create the client:


DynamicClientFactory factory = DynamicClientFactory.newInstance();
Client client = factory.createClient(SOME_WSDL_URL);

One of the objects in the service has a String[] field. So CXF using the JAXB implementation automatically converts the array to:


/**
* Java class for ArrayOfString complex type.
*
* The following schema fragment specifies the expected content contained within
* this class.
*
* <pre>
* &lt;complexType name="ArrayOfString">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="String" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfString", propOrder = { "string" })
public class ArrayOfString {

@XmlElement(name = "String", nillable = true)
protected List<String> string;

...

and wraps it into the JAXBElement:


protected JAXBElement<ArrayOfString> someStringArrayField;

I would have no problems with the code above if not for the ArrayOfString class declared in java.lang package. Obviously as soon as the factory tries to initialize the client the following exception throws out:


Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.lang

which is 100% valid per Java restrictions on package naming.


If I understand correctly my problem is more JAXB related. But since we are talking about a DynamicClientFactory I can't just correct my local client implementation (there is none, that's the idea) but left limited to certain parameters that would affect the autogeneration process, and this is where I might look for the answer I think.


My questions are:



  1. Why this could happen in the first place? I'm referring to the java.lang package for a String array wrapper class. (The rest of autogenerated classes seem to reside in valid packages.)


  2. Is there any way to override the package or the object generation process? I've noticed some few attributes the factory can take in like *JAXBRIContext.SUBCLASS_REPLACEMENTS* from DynamicClientFactory.setJaxbContextProperties(Map jaxbContextProperties). There's also an access to the org.apache.cxf.Bus object which can be passed as a parameter to the DynamicClientFactory.newInstance(Bus b) method. Maybe some of JAXB's own configuration xmls could be used, I don't know...



Any ideas?



I'm trying to generate a generic web service client using CXF's DynamicClientFactory. The standard wsdls are working fine. But in this particular case I've got a serie of "old style" web services programmed in the Java v1.4 era. They work just fine and SoapUI, for example, has no problems creating a client and communicating with them.


Just for the reference this is how I create the client:


DynamicClientFactory factory = DynamicClientFactory.newInstance();
Client client = factory.createClient(SOME_WSDL_URL);

One of the objects in the service has a String[] field. So CXF using the JAXB implementation automatically converts the array to:


/**
* Java class for ArrayOfString complex type.
*
* The following schema fragment specifies the expected content contained within
* this class.
*
* <pre>
* &lt;complexType name="ArrayOfString">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="String" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfString", propOrder = { "string" })
public class ArrayOfString {

@XmlElement(name = "String", nillable = true)
protected List<String> string;

...

and wraps it into the JAXBElement:


protected JAXBElement<ArrayOfString> someStringArrayField;

I would have no problems with the code above if not for the ArrayOfString class declared in java.lang package. Obviously as soon as the factory tries to initialize the client the following exception throws out:


Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.lang

which is 100% valid per Java restrictions on package naming.


If I understand correctly my problem is more JAXB related. But since we are talking about a DynamicClientFactory I can't just correct my local client implementation (there is none, that's the idea) but left limited to certain parameters that would affect the autogeneration process, and this is where I might look for the answer I think.


My questions are:



  1. Why this could happen in the first place? I'm referring to the java.lang package for a String array wrapper class. (The rest of autogenerated classes seem to reside in valid packages.)


  2. Is there any way to override the package or the object generation process? I've noticed some few attributes the factory can take in like *JAXBRIContext.SUBCLASS_REPLACEMENTS* from DynamicClientFactory.setJaxbContextProperties(Map jaxbContextProperties). There's also an access to the org.apache.cxf.Bus object which can be passed as a parameter to the DynamicClientFactory.newInstance(Bus b) method. Maybe some of JAXB's own configuration xmls could be used, I don't know...



Any ideas?


0 commentaires:

Enregistrer un commentaire