You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Koen Thomeer <ko...@thomeer.be> on 2011/02/21 14:26:25 UTC
CXF dynamic clients
Hello,
I've to admit: I'm a beginning Java Developer. I'm comming from the PHP
world.
Can someone help me: I get this error:
> java.lang.NoSuchMethodException:
> be.smals.ehealth.codage.beans.OriginalDataType.setApplicationName(java.lang.String)
> at java.lang.Class.getMethod(Class.java:1605)
> at cxfehealth.Main.main(Main.java:47)
>
Thx,
Koen
package cxfehealth;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.cxf.endpoint.Client;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import java.net.URL;
import java.lang.reflect.Method;
/**
*
* @author Koen Thomeer, MD, http://koen.thomeer.be
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// configure logging
BasicConfigurator.configure();
Logger.getLogger("org").setLevel(Level.WARN);
java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING);
// point to private wdsl
URL wsdlURL;
File wsdlFile = new File("src/codage.wsdl");
wsdlURL = wsdlFile.toURL();
System.out.println(wsdlURL);
// use CXF dynamic clients
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
Client client = dcf.createClient(wsdlURL, classloader);
Object EncodeRequestType =
Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
//System.out.println(EncodeRequestType);
Method m =
EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
m.invoke(EncodeRequestType, "WWM");
// configure security settings
Map<String, Object> props = new HashMap<String, Object>();
props.put(WSHandlerConstants.ACTION, "Timestamp Signature");
props.put(WSHandlerConstants.TTL_TIMESTAMP, "15");
props.put(WSHandlerConstants.USER, "wwm_eh_key");
props.put(WSHandlerConstants.PW_CALLBACK_CLASS,
ClientCallbackHandler.class.getName());
props.put(WSHandlerConstants.SIG_PROP_FILE,
"client_sign.properties");
props.put(WSHandlerConstants.SIGNATURE_PARTS, "{Element}{
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;Token;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body
");
props.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
client.getEndpoint().getOutInterceptors().add(new
WSS4JOutInterceptor(props));
// call the WebService
System.out.println(client.invoke("encode",
EncodeRequestType)[0]);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
--
*Koen Thomeer*, MD, MSc
http://koen.thomeer.be
Re: CXF dynamic clients
Posted by Koen Thomeer <ko...@thomeer.be>.
That is indeed possible, but I wanted to use the classloader.
2011/2/22 Willem Jiang <wi...@gmail.com>
> On 2/21/11 10:38 PM, Koen Thomeer wrote:
>
>> Sorry for bothering:
>> the first two issues have been resolved: simple Java errors.
>>
>> The third thing is a little bit complex:
>>
>> The instance OriginalDataType has three values: Id, Randomize and
>> InputData.
>> They are all set up: no problem.
>>
>> The instance EncodeRequesType has two values: applicationName and
>> "OriginalDataType".
>>
>> How do I put an instance in another instance?
>>
>> Something like this?
>> Method m2 = EncodeRequestType.getClass().getMethod("getOriginalData.add",
>> Object.class);
>> m2.invoke(EncodeRequestType, OriginalDataType);
>> (It doesn't work.)
>>
> As you already get the class file, can you just use new EncodeRequestType()
> to create the object that you want ?
>
>
>
>
>> The EncodeRequestType.java file from wsdl2java says this;
>> /**
>> * Gets the value of the originalData property.
>> *
>> *<p>
>> * This accessor method returns a reference to the live list,
>> * not a snapshot. Therefore any modification you make to the
>> * returned list will be present inside the JAXB object.
>> * This is why there is not a<CODE>set</CODE> method for the
>> originalData property.
>> *
>> *<p>
>> * For example, to add a new item, do as follows:
>> *<pre>
>> * getOriginalData().add(newItem);
>> *</pre>
>> *
>> *
>> *<p>
>> * Objects of the following type(s) are allowed in the list
>> * {@link OriginalDataType }
>> *
>> *
>> */
>> public List<OriginalDataType> getOriginalData() {
>> if (originalData == null) {
>> originalData = new ArrayList<OriginalDataType>();
>> }
>> return this.originalData;
>> }
>>
>>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
--
*Koen Thomeer*, MD, MSc
http://koen.thomeer.be
Re: CXF dynamic clients
Posted by Willem Jiang <wi...@gmail.com>.
On 2/21/11 10:38 PM, Koen Thomeer wrote:
> Sorry for bothering:
> the first two issues have been resolved: simple Java errors.
>
> The third thing is a little bit complex:
>
> The instance OriginalDataType has three values: Id, Randomize and InputData.
> They are all set up: no problem.
>
> The instance EncodeRequesType has two values: applicationName and
> "OriginalDataType".
>
> How do I put an instance in another instance?
>
> Something like this?
> Method m2 = EncodeRequestType.getClass().getMethod("getOriginalData.add",
> Object.class);
> m2.invoke(EncodeRequestType, OriginalDataType);
> (It doesn't work.)
As you already get the class file, can you just use new
EncodeRequestType() to create the object that you want ?
>
> The EncodeRequestType.java file from wsdl2java says this;
> /**
> * Gets the value of the originalData property.
> *
> *<p>
> * This accessor method returns a reference to the live list,
> * not a snapshot. Therefore any modification you make to the
> * returned list will be present inside the JAXB object.
> * This is why there is not a<CODE>set</CODE> method for the
> originalData property.
> *
> *<p>
> * For example, to add a new item, do as follows:
> *<pre>
> * getOriginalData().add(newItem);
> *</pre>
> *
> *
> *<p>
> * Objects of the following type(s) are allowed in the list
> * {@link OriginalDataType }
> *
> *
> */
> public List<OriginalDataType> getOriginalData() {
> if (originalData == null) {
> originalData = new ArrayList<OriginalDataType>();
> }
> return this.originalData;
> }
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Re: CXF dynamic clients
Posted by Koen Thomeer <ko...@thomeer.be>.
Sorry for bothering:
the first two issues have been resolved: simple Java errors.
The third thing is a little bit complex:
The instance OriginalDataType has three values: Id, Randomize and InputData.
They are all set up: no problem.
The instance EncodeRequesType has two values: applicationName and
"OriginalDataType".
How do I put an instance in another instance?
Something like this?
Method m2 = EncodeRequestType.getClass().getMethod("getOriginalData.add",
Object.class);
m2.invoke(EncodeRequestType, OriginalDataType);
(It doesn't work.)
The EncodeRequestType.java file from wsdl2java says this;
/**
* Gets the value of the originalData property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the
originalData property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getOriginalData().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link OriginalDataType }
*
*
*/
public List<OriginalDataType> getOriginalData() {
if (originalData == null) {
originalData = new ArrayList<OriginalDataType>();
}
return this.originalData;
}
Re: CXF dynamic clients
Posted by Koen Thomeer <ko...@thomeer.be>.
I have inserted the two java classes from wsdl2java.
2011/2/21 Koen Thomeer <ko...@thomeer.be>
> 1. I did do something wrong:
>
>
> Object EncodeRequestType =
> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
>
> has to be:
> Object EncodeRequestType =
> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.EncodeRequestType").newInstance();
>
> 2. I changed the whole code:
>
>
> //OriginalDataType
> Object OriginalDataType =
> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
> Method d = OriginalDataType.getClass().getMethod("setId",
> String.class);
> d.invoke(OriginalDataType, "1");
> Method d2 =
> OriginalDataType.getClass().getMethod("setRandomize", Boolean.class);
> d2.invoke(OriginalDataType, false);
> Method d3 =
> OriginalDataType.getClass().getMethod("setInputData", String.class);
> d3.invoke(OriginalDataType, "Ik ben gek");
>
> //EncodeRequestType
> Object EncodeRequestType =
> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.EncodeRequestType").newInstance();
>
> Method m =
> EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
> m.invoke(EncodeRequestType, "WWM");
>
>
> But this gives errors to:
> A. Method d2 = OriginalDataType.getClass().getMethod("setRandomize",
> Boolean.class);
>
> Gives error:
> java.lang.NoSuchMethodException:
> be.smals.ehealth.codage.beans.OriginalDataType.setRandomize(java.lang.Boolean)
>
> at java.lang.Class.getMethod(Class.java:1605)
> at cxfehealth.Main.main(Main.java:49)
>
> This is strange, because the method 'setId' has no errors, but is in the
> same contect!
>
> B. Object EncodeRequestType =
> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.EncodeRequestType").newInstance();
>
> Gives error:
> java.lang.ClassNotFoundException:
> be.smals.ehealth.codage.beans.EncodeRequestType
> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at cxfehealth.Main.main(Main.java:55)
>
> That is also strange, because it finds the precedent class
> 'OriginalDataType': why it doesn't find EncodeRequestType?
>
> C. After that, I've to integrate OriginalDataType in EncodeRequestType ...
>
> Sincerely,
>
>
> Koen
>
>
> 2011/2/21 Koen Thomeer <ko...@thomeer.be>
>
>> The WSDL is: http://wwwacc.ehealth.fgov.be/codage_1_0/codage?WSDL
>>
>> Koen
>>
>> 2011/2/21 Koen Thomeer <ko...@thomeer.be>
>>
>> Hello,
>>>
>>> I've to admit: I'm a beginning Java Developer. I'm comming from the PHP
>>> world.
>>>
>>> Can someone help me: I get this error:
>>>
>>>> java.lang.NoSuchMethodException:
>>>> be.smals.ehealth.codage.beans.OriginalDataType.setApplicationName(java.lang.String)
>>>> at java.lang.Class.getMethod(Class.java:1605)
>>>> at cxfehealth.Main.main(Main.java:47)
>>>>
>>>
>>> Thx,
>>>
>>> Koen
>>>
>>>
>>> package cxfehealth;
>>>
>>> import org.apache.log4j.BasicConfigurator;
>>> import org.apache.log4j.Logger;
>>> import org.apache.log4j.Level;
>>> import org.apache.ws.security.handler.WSHandlerConstants;
>>> import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
>>> import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
>>> import org.apache.cxf.endpoint.Client;
>>> import java.util.HashMap;
>>> import java.util.Map;
>>> import java.io.File;
>>> import java.net.URL;
>>> import java.lang.reflect.Method;
>>>
>>> /**
>>> *
>>> * @author Koen Thomeer, MD, http://koen.thomeer.be
>>> */
>>> public class Main {
>>>
>>> /**
>>> * @param args the command line arguments
>>> */
>>> public static void main(String[] args) {
>>> try {
>>> // configure logging
>>> BasicConfigurator.configure();
>>> Logger.getLogger("org").setLevel(Level.WARN);
>>>
>>> java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING);
>>> // point to private wdsl
>>> URL wsdlURL;
>>> File wsdlFile = new File("src/codage.wsdl");
>>> wsdlURL = wsdlFile.toURL();
>>> System.out.println(wsdlURL);
>>> // use CXF dynamic clients
>>> DynamicClientFactory dcf =
>>> DynamicClientFactory.newInstance();
>>> ClassLoader classloader =
>>> Thread.currentThread().getContextClassLoader();
>>> Client client = dcf.createClient(wsdlURL, classloader);
>>> Object EncodeRequestType =
>>> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
>>> //System.out.println(EncodeRequestType);
>>> Method m =
>>> EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
>>> m.invoke(EncodeRequestType, "WWM");
>>>
>>>
>>> // configure security settings
>>> Map<String, Object> props = new HashMap<String, Object>();
>>> props.put(WSHandlerConstants.ACTION, "Timestamp Signature");
>>> props.put(WSHandlerConstants.TTL_TIMESTAMP, "15");
>>> props.put(WSHandlerConstants.USER, "wwm_eh_key");
>>> props.put(WSHandlerConstants.PW_CALLBACK_CLASS,
>>> ClientCallbackHandler.class.getName());
>>> props.put(WSHandlerConstants.SIG_PROP_FILE,
>>> "client_sign.properties");
>>> props.put(WSHandlerConstants.SIGNATURE_PARTS, "{Element}{
>>> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;Token;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body
>>> ");
>>> props.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
>>> client.getEndpoint().getOutInterceptors().add(new
>>> WSS4JOutInterceptor(props));
>>>
>>> // call the WebService
>>> System.out.println(client.invoke("encode",
>>> EncodeRequestType)[0]);
>>> } catch (Exception ex) {
>>> ex.printStackTrace();
>>> }
>>> }
>>> }
>>>
>>>
>>> --
>>> *Koen Thomeer*, MD, MSc
>>> http://koen.thomeer.be
>>>
>>
>>
>>
>> --
>> *Koen Thomeer*, MD, MSc
>> http://koen.thomeer.be
>>
>
>
>
> --
> *Koen Thomeer*, MD, MSc
> http://koen.thomeer.be
>
--
*Koen Thomeer*, MD, MSc
http://koen.thomeer.be
Re: CXF dynamic clients
Posted by Koen Thomeer <ko...@thomeer.be>.
1. I did do something wrong:
Object EncodeRequestType =
Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
has to be:
Object EncodeRequestType =
Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.EncodeRequestType").newInstance();
2. I changed the whole code:
//OriginalDataType
Object OriginalDataType =
Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
Method d = OriginalDataType.getClass().getMethod("setId",
String.class);
d.invoke(OriginalDataType, "1");
Method d2 =
OriginalDataType.getClass().getMethod("setRandomize", Boolean.class);
d2.invoke(OriginalDataType, false);
Method d3 =
OriginalDataType.getClass().getMethod("setInputData", String.class);
d3.invoke(OriginalDataType, "Ik ben gek");
//EncodeRequestType
Object EncodeRequestType =
Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.EncodeRequestType").newInstance();
Method m =
EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
m.invoke(EncodeRequestType, "WWM");
But this gives errors to:
A. Method d2 = OriginalDataType.getClass().getMethod("setRandomize",
Boolean.class);
Gives error:
java.lang.NoSuchMethodException:
be.smals.ehealth.codage.beans.OriginalDataType.setRandomize(java.lang.Boolean)
at java.lang.Class.getMethod(Class.java:1605)
at cxfehealth.Main.main(Main.java:49)
This is strange, because the method 'setId' has no errors, but is in the
same contect!
B. Object EncodeRequestType =
Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.EncodeRequestType").newInstance();
Gives error:
java.lang.ClassNotFoundException:
be.smals.ehealth.codage.beans.EncodeRequestType
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at cxfehealth.Main.main(Main.java:55)
That is also strange, because it finds the precedent class
'OriginalDataType': why it doesn't find EncodeRequestType?
C. After that, I've to integrate OriginalDataType in EncodeRequestType ...
Sincerely,
Koen
2011/2/21 Koen Thomeer <ko...@thomeer.be>
> The WSDL is: http://wwwacc.ehealth.fgov.be/codage_1_0/codage?WSDL
>
> Koen
>
> 2011/2/21 Koen Thomeer <ko...@thomeer.be>
>
> Hello,
>>
>> I've to admit: I'm a beginning Java Developer. I'm comming from the PHP
>> world.
>>
>> Can someone help me: I get this error:
>>
>>> java.lang.NoSuchMethodException:
>>> be.smals.ehealth.codage.beans.OriginalDataType.setApplicationName(java.lang.String)
>>> at java.lang.Class.getMethod(Class.java:1605)
>>> at cxfehealth.Main.main(Main.java:47)
>>>
>>
>> Thx,
>>
>> Koen
>>
>>
>> package cxfehealth;
>>
>> import org.apache.log4j.BasicConfigurator;
>> import org.apache.log4j.Logger;
>> import org.apache.log4j.Level;
>> import org.apache.ws.security.handler.WSHandlerConstants;
>> import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
>> import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
>> import org.apache.cxf.endpoint.Client;
>> import java.util.HashMap;
>> import java.util.Map;
>> import java.io.File;
>> import java.net.URL;
>> import java.lang.reflect.Method;
>>
>> /**
>> *
>> * @author Koen Thomeer, MD, http://koen.thomeer.be
>> */
>> public class Main {
>>
>> /**
>> * @param args the command line arguments
>> */
>> public static void main(String[] args) {
>> try {
>> // configure logging
>> BasicConfigurator.configure();
>> Logger.getLogger("org").setLevel(Level.WARN);
>>
>> java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING);
>> // point to private wdsl
>> URL wsdlURL;
>> File wsdlFile = new File("src/codage.wsdl");
>> wsdlURL = wsdlFile.toURL();
>> System.out.println(wsdlURL);
>> // use CXF dynamic clients
>> DynamicClientFactory dcf = DynamicClientFactory.newInstance();
>> ClassLoader classloader =
>> Thread.currentThread().getContextClassLoader();
>> Client client = dcf.createClient(wsdlURL, classloader);
>> Object EncodeRequestType =
>> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
>> //System.out.println(EncodeRequestType);
>> Method m =
>> EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
>> m.invoke(EncodeRequestType, "WWM");
>>
>>
>> // configure security settings
>> Map<String, Object> props = new HashMap<String, Object>();
>> props.put(WSHandlerConstants.ACTION, "Timestamp Signature");
>> props.put(WSHandlerConstants.TTL_TIMESTAMP, "15");
>> props.put(WSHandlerConstants.USER, "wwm_eh_key");
>> props.put(WSHandlerConstants.PW_CALLBACK_CLASS,
>> ClientCallbackHandler.class.getName());
>> props.put(WSHandlerConstants.SIG_PROP_FILE,
>> "client_sign.properties");
>> props.put(WSHandlerConstants.SIGNATURE_PARTS, "{Element}{
>> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;Token;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body
>> ");
>> props.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
>> client.getEndpoint().getOutInterceptors().add(new
>> WSS4JOutInterceptor(props));
>>
>> // call the WebService
>> System.out.println(client.invoke("encode",
>> EncodeRequestType)[0]);
>> } catch (Exception ex) {
>> ex.printStackTrace();
>> }
>> }
>> }
>>
>>
>> --
>> *Koen Thomeer*, MD, MSc
>> http://koen.thomeer.be
>>
>
>
>
> --
> *Koen Thomeer*, MD, MSc
> http://koen.thomeer.be
>
--
*Koen Thomeer*, MD, MSc
http://koen.thomeer.be
Re: CXF dynamic clients
Posted by Glen Mazza <gm...@talend.com>.
I'm unsure if you're making things harder than they have to be with a
Dynamic client.
Generating your client via the WSDL2Java tool[1] should be much easier,
after which from the WSDL it looks like you need X.509 security which
you can do via [2] or [3]. But I would try to get [1] nailed down first
(even though the service will return some authentication failed error)
before doing [2] or [3].
HTH,
Glen
[1] http://www.jroller.com/gmazza/entry/soap_client_tutorial
[2] http://www.jroller.com/gmazza/entry/cxf_x509_profile
[3] http://www.jroller.com/gmazza/entry/cxf_x509_profile_secpol
On 2/21/2011 8:29 AM, Koen Thomeer wrote:
> The WSDL is: http://wwwacc.ehealth.fgov.be/codage_1_0/codage?WSDL
>
> Koen
>
> 2011/2/21 Koen Thomeer<ko...@thomeer.be>
>
>> Hello,
>>
>> I've to admit: I'm a beginning Java Developer. I'm comming from the PHP
>> world.
>>
>> Can someone help me: I get this error:
>>
>>> java.lang.NoSuchMethodException:
>>> be.smals.ehealth.codage.beans.OriginalDataType.setApplicationName(java.lang.String)
>>> at java.lang.Class.getMethod(Class.java:1605)
>>> at cxfehealth.Main.main(Main.java:47)
>>>
>> Thx,
>>
>> Koen
>>
>>
>> package cxfehealth;
>>
>> import org.apache.log4j.BasicConfigurator;
>> import org.apache.log4j.Logger;
>> import org.apache.log4j.Level;
>> import org.apache.ws.security.handler.WSHandlerConstants;
>> import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
>> import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
>> import org.apache.cxf.endpoint.Client;
>> import java.util.HashMap;
>> import java.util.Map;
>> import java.io.File;
>> import java.net.URL;
>> import java.lang.reflect.Method;
>>
>> /**
>> *
>> * @author Koen Thomeer, MD, http://koen.thomeer.be
>> */
>> public class Main {
>>
>> /**
>> * @param args the command line arguments
>> */
>> public static void main(String[] args) {
>> try {
>> // configure logging
>> BasicConfigurator.configure();
>> Logger.getLogger("org").setLevel(Level.WARN);
>>
>> java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING);
>> // point to private wdsl
>> URL wsdlURL;
>> File wsdlFile = new File("src/codage.wsdl");
>> wsdlURL = wsdlFile.toURL();
>> System.out.println(wsdlURL);
>> // use CXF dynamic clients
>> DynamicClientFactory dcf = DynamicClientFactory.newInstance();
>> ClassLoader classloader =
>> Thread.currentThread().getContextClassLoader();
>> Client client = dcf.createClient(wsdlURL, classloader);
>> Object EncodeRequestType =
>> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
>> //System.out.println(EncodeRequestType);
>> Method m =
>> EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
>> m.invoke(EncodeRequestType, "WWM");
>>
>>
>> // configure security settings
>> Map<String, Object> props = new HashMap<String, Object>();
>> props.put(WSHandlerConstants.ACTION, "Timestamp Signature");
>> props.put(WSHandlerConstants.TTL_TIMESTAMP, "15");
>> props.put(WSHandlerConstants.USER, "wwm_eh_key");
>> props.put(WSHandlerConstants.PW_CALLBACK_CLASS,
>> ClientCallbackHandler.class.getName());
>> props.put(WSHandlerConstants.SIG_PROP_FILE,
>> "client_sign.properties");
>> props.put(WSHandlerConstants.SIGNATURE_PARTS, "{Element}{
>> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;Token;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body
>> ");
>> props.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
>> client.getEndpoint().getOutInterceptors().add(new
>> WSS4JOutInterceptor(props));
>>
>> // call the WebService
>> System.out.println(client.invoke("encode",
>> EncodeRequestType)[0]);
>> } catch (Exception ex) {
>> ex.printStackTrace();
>> }
>> }
>> }
>>
>>
>> --
>> *Koen Thomeer*, MD, MSc
>> http://koen.thomeer.be
>>
>
>
Re: CXF dynamic clients
Posted by Koen Thomeer <ko...@thomeer.be>.
The WSDL is: http://wwwacc.ehealth.fgov.be/codage_1_0/codage?WSDL
Koen
2011/2/21 Koen Thomeer <ko...@thomeer.be>
> Hello,
>
> I've to admit: I'm a beginning Java Developer. I'm comming from the PHP
> world.
>
> Can someone help me: I get this error:
>
>> java.lang.NoSuchMethodException:
>> be.smals.ehealth.codage.beans.OriginalDataType.setApplicationName(java.lang.String)
>> at java.lang.Class.getMethod(Class.java:1605)
>> at cxfehealth.Main.main(Main.java:47)
>>
>
> Thx,
>
> Koen
>
>
> package cxfehealth;
>
> import org.apache.log4j.BasicConfigurator;
> import org.apache.log4j.Logger;
> import org.apache.log4j.Level;
> import org.apache.ws.security.handler.WSHandlerConstants;
> import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
> import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
> import org.apache.cxf.endpoint.Client;
> import java.util.HashMap;
> import java.util.Map;
> import java.io.File;
> import java.net.URL;
> import java.lang.reflect.Method;
>
> /**
> *
> * @author Koen Thomeer, MD, http://koen.thomeer.be
> */
> public class Main {
>
> /**
> * @param args the command line arguments
> */
> public static void main(String[] args) {
> try {
> // configure logging
> BasicConfigurator.configure();
> Logger.getLogger("org").setLevel(Level.WARN);
>
> java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING);
> // point to private wdsl
> URL wsdlURL;
> File wsdlFile = new File("src/codage.wsdl");
> wsdlURL = wsdlFile.toURL();
> System.out.println(wsdlURL);
> // use CXF dynamic clients
> DynamicClientFactory dcf = DynamicClientFactory.newInstance();
> ClassLoader classloader =
> Thread.currentThread().getContextClassLoader();
> Client client = dcf.createClient(wsdlURL, classloader);
> Object EncodeRequestType =
> Thread.currentThread().getContextClassLoader().loadClass("be.smals.ehealth.codage.beans.OriginalDataType").newInstance();
> //System.out.println(EncodeRequestType);
> Method m =
> EncodeRequestType.getClass().getMethod("setApplicationName", String.class);
> m.invoke(EncodeRequestType, "WWM");
>
>
> // configure security settings
> Map<String, Object> props = new HashMap<String, Object>();
> props.put(WSHandlerConstants.ACTION, "Timestamp Signature");
> props.put(WSHandlerConstants.TTL_TIMESTAMP, "15");
> props.put(WSHandlerConstants.USER, "wwm_eh_key");
> props.put(WSHandlerConstants.PW_CALLBACK_CLASS,
> ClientCallbackHandler.class.getName());
> props.put(WSHandlerConstants.SIG_PROP_FILE,
> "client_sign.properties");
> props.put(WSHandlerConstants.SIGNATURE_PARTS, "{Element}{
> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;Token;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body
> ");
> props.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
> client.getEndpoint().getOutInterceptors().add(new
> WSS4JOutInterceptor(props));
>
> // call the WebService
> System.out.println(client.invoke("encode",
> EncodeRequestType)[0]);
> } catch (Exception ex) {
> ex.printStackTrace();
> }
> }
> }
>
>
> --
> *Koen Thomeer*, MD, MSc
> http://koen.thomeer.be
>
--
*Koen Thomeer*, MD, MSc
http://koen.thomeer.be