You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by liw <pa...@yahoo.com> on 2009/06/19 07:29:49 UTC

How to generate wsdl programmatically using cxf?

Hi, we are migrating from xfire to cxf. In xfire, we have the following code
for generating wsdl.

 XFire xfire = (XFire)BeanFactory.getBeanInstance("xfire");
 Service origRegisteredService =
xfire.getServiceRegistry().getService(serviceName); 
 origRegisteredService.getWSDLWriter().write(os);

We need to migrate the above code from xfire to CXF.

1) Is JavaToWSDLProcessor.generate() the right API to use for generating
wsdl in CXF?
2) If so, given a serviceName, what are the APIs we need to use to get the
ServiceInfo, so we can pass it to JavaToWSDLProcessor.generate() method?

Thanks very much in advice,

Li









-- 
View this message in context: http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24105734.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to generate wsdl programmatically using cxf?

Posted by liw <pa...@yahoo.com>.
Hi,

Thanks for the reply.

We want to do this with a live service. Let me take a look at
AbstractAegisTest. 

Thanks,

Li

bimargulies wrote:
> 
> Do you want to do this with a live service, or just 'on the side'? There
> are
> lots of unit tests that do the former you can copy from. In fact,
> AbstractAegisTest might be what you want to see.
> 
> On Fri, Jun 19, 2009 at 1:29 AM, liw <pa...@yahoo.com> wrote:
> 
>>
>> Hi, we are migrating from xfire to cxf. In xfire, we have the following
>> code
>> for generating wsdl.
>>
>>  XFire xfire = (XFire)BeanFactory.getBeanInstance("xfire");
>>  Service origRegisteredService =
>> xfire.getServiceRegistry().getService(serviceName);
>>  origRegisteredService.getWSDLWriter().write(os);
>>
>> We need to migrate the above code from xfire to CXF.
>>
>> 1) Is JavaToWSDLProcessor.generate() the right API to use for generating
>> wsdl in CXF?
>> 2) If so, given a serviceName, what are the APIs we need to use to get
>> the
>> ServiceInfo, so we can pass it to JavaToWSDLProcessor.generate() method?
>>
>> Thanks very much in advice,
>>
>> Li
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24105734.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24151653.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to generate wsdl programmatically using cxf?

Posted by Benson Margulies <bi...@gmail.com>.
Do you want to do this with a live service, or just 'on the side'? There are
lots of unit tests that do the former you can copy from. In fact,
AbstractAegisTest might be what you want to see.

On Fri, Jun 19, 2009 at 1:29 AM, liw <pa...@yahoo.com> wrote:

>
> Hi, we are migrating from xfire to cxf. In xfire, we have the following
> code
> for generating wsdl.
>
>  XFire xfire = (XFire)BeanFactory.getBeanInstance("xfire");
>  Service origRegisteredService =
> xfire.getServiceRegistry().getService(serviceName);
>  origRegisteredService.getWSDLWriter().write(os);
>
> We need to migrate the above code from xfire to CXF.
>
> 1) Is JavaToWSDLProcessor.generate() the right API to use for generating
> wsdl in CXF?
> 2) If so, given a serviceName, what are the APIs we need to use to get the
> ServiceInfo, so we can pass it to JavaToWSDLProcessor.generate() method?
>
> Thanks very much in advice,
>
> Li
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24105734.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: How to generate wsdl programmatically using cxf?

Posted by jim ma <ma...@gmail.com>.
Feeds ToolContext with "ToolConstants.CFG_WSDL", it will add the
WSDLGenerator .
Jim.

On Fri, Jul 10, 2009 at 2:02 AM, liw <pa...@yahoo.com> wrote:

>
> Hi Jim,
>
> It was turned out that the generators list is empty when
> JavaToWSDLProcessor.generate() API is invoked. That's why the wsdl file is
> empty.
>
> The service is build from spring bean definition. I am able to generate
> wsdl
> using WSDLWriter.
>
> Thanks for your inputs,
>
> Li
>
> jim ma wrote:
> >
> > On Thu, Jul 9, 2009 at 7:50 AM, liw <pa...@yahoo.com> wrote:
> >
> >>
> >> Hi Jim,
> >>
> >> Since I have the service object already, is there any way that I can get
> >> the
> >> ServiceInfo for the service instead of creating a one?
> >>
> >> If I have to create a ServiceInfo instance, what are the minimum fields
> I
> >> need to add before passing it to JavaToWSDLProcessor.
> >>
> >
> > yes. you can . What is this service built from ?  Do you use
> > ReflectionServiceFactoryBean to build it ?
> >
> >
> >>
> >>
> >> Here is the code I have. Unfortunately, the wdl file generated is empty.
> >>
> >>
> >>  private void generateCXFWsdlStream(String serviceName, OutputStream os)
> >> throws IOException
> >>    {
> >>        Service service = getCXFServiceObject(serviceName);
> >>        List serviceInfos = service.getServiceInfos();
> >>
> >>        for (ServiceInfo serviceInfo : service.getServiceInfos()) {
> >>                System.out.println("serviceInfo targetNamespace" +
> >> serviceInfo.getTargetNamespace());
> >>        }
> >>
> >>        File tempFile = new File(outdir, serviceName + ".wsdl");
> >>        JavaToWSDLProcessor wsdlProcessor = new JavaToWSDLProcessor();
> >>
> >>        wsdlProcessor.generate((ServiceInfo)
> >> serviceInfos.get(0),tempFile);
> >>    }
> >>
> >
> > Did you see some errors when you generate wsdl ? The JavaToWSDLprocessor
> > will invoke ServiceWSDLBuilder to convert the ServiceInfo to Wsdl
> > definition. You can debug this class to get more information.
> >
> >
> > Jim.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24415033.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>

Re: How to generate wsdl programmatically using cxf?

Posted by liw <pa...@yahoo.com>.
Hi Jim,

It was turned out that the generators list is empty when
JavaToWSDLProcessor.generate() API is invoked. That's why the wsdl file is
empty.

The service is build from spring bean definition. I am able to generate wsdl
using WSDLWriter.

Thanks for your inputs,

Li

jim ma wrote:
> 
> On Thu, Jul 9, 2009 at 7:50 AM, liw <pa...@yahoo.com> wrote:
> 
>>
>> Hi Jim,
>>
>> Since I have the service object already, is there any way that I can get
>> the
>> ServiceInfo for the service instead of creating a one?
>>
>> If I have to create a ServiceInfo instance, what are the minimum fields I
>> need to add before passing it to JavaToWSDLProcessor.
>>
> 
> yes. you can . What is this service built from ?  Do you use
> ReflectionServiceFactoryBean to build it ?
> 
> 
>>
>>
>> Here is the code I have. Unfortunately, the wdl file generated is empty.
>>
>>
>>  private void generateCXFWsdlStream(String serviceName, OutputStream os)
>> throws IOException
>>    {
>>        Service service = getCXFServiceObject(serviceName);
>>        List serviceInfos = service.getServiceInfos();
>>
>>        for (ServiceInfo serviceInfo : service.getServiceInfos()) {
>>                System.out.println("serviceInfo targetNamespace" +
>> serviceInfo.getTargetNamespace());
>>        }
>>
>>        File tempFile = new File(outdir, serviceName + ".wsdl");
>>        JavaToWSDLProcessor wsdlProcessor = new JavaToWSDLProcessor();
>>
>>        wsdlProcessor.generate((ServiceInfo)
>> serviceInfos.get(0),tempFile);
>>    }
>>
> 
> Did you see some errors when you generate wsdl ? The JavaToWSDLprocessor
> will invoke ServiceWSDLBuilder to convert the ServiceInfo to Wsdl
> definition. You can debug this class to get more information.
> 
> 
> Jim.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24415033.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to generate wsdl programmatically using cxf?

Posted by jim ma <ma...@gmail.com>.
On Thu, Jul 9, 2009 at 7:50 AM, liw <pa...@yahoo.com> wrote:

>
> Hi Jim,
>
> Since I have the service object already, is there any way that I can get
> the
> ServiceInfo for the service instead of creating a one?
>
> If I have to create a ServiceInfo instance, what are the minimum fields I
> need to add before passing it to JavaToWSDLProcessor.
>

yes. you can . What is this service built from ?  Do you use
ReflectionServiceFactoryBean to build it ?


>
>
> Here is the code I have. Unfortunately, the wdl file generated is empty.
>
>
>  private void generateCXFWsdlStream(String serviceName, OutputStream os)
> throws IOException
>    {
>        Service service = getCXFServiceObject(serviceName);
>        List serviceInfos = service.getServiceInfos();
>
>        for (ServiceInfo serviceInfo : service.getServiceInfos()) {
>                System.out.println("serviceInfo targetNamespace" +
> serviceInfo.getTargetNamespace());
>        }
>
>        File tempFile = new File(outdir, serviceName + ".wsdl");
>        JavaToWSDLProcessor wsdlProcessor = new JavaToWSDLProcessor();
>
>        wsdlProcessor.generate((ServiceInfo) serviceInfos.get(0),tempFile);
>    }
>

Did you see some errors when you generate wsdl ? The JavaToWSDLprocessor
will invoke ServiceWSDLBuilder to convert the ServiceInfo to Wsdl
definition. You can debug this class to get more information.


Jim.

Re: How to generate wsdl programmatically using cxf?

Posted by liw <pa...@yahoo.com>.
Hi Jim,

Since I have the service object already, is there any way that I can get the
ServiceInfo for the service instead of creating a one?

If I have to create a ServiceInfo instance, what are the minimum fields I
need to add before passing it to JavaToWSDLProcessor.


Here is the code I have. Unfortunately, the wdl file generated is empty.


  private void generateCXFWsdlStream(String serviceName, OutputStream os)
throws IOException
    {
        Service service = getCXFServiceObject(serviceName);
        List serviceInfos = service.getServiceInfos();
    	
    	for (ServiceInfo serviceInfo : service.getServiceInfos()) {
    		System.out.println("serviceInfo targetNamespace" +
serviceInfo.getTargetNamespace());
    	}
    	
    	File tempFile = new File(outdir, serviceName + ".wsdl");
    	JavaToWSDLProcessor wsdlProcessor = new JavaToWSDLProcessor();
    	
    	wsdlProcessor.generate((ServiceInfo) serviceInfos.get(0),tempFile);
    }


Thanks in advance,

Li





jim ma wrote:
> 
> On Fri, Jun 19, 2009 at 1:29 PM, liw <pa...@yahoo.com> wrote:
> 
>>
>> Hi, we are migrating from xfire to cxf. In xfire, we have the following
>> code
>> for generating wsdl.
>>
>>  XFire xfire = (XFire)BeanFactory.getBeanInstance("xfire");
>>  Service origRegisteredService =
>> xfire.getServiceRegistry().getService(serviceName);
>>  origRegisteredService.getWSDLWriter().write(os);
>>
>> We need to migrate the above code from xfire to CXF.
>>
>> 1) Is JavaToWSDLProcessor.generate() the right API to use for generating
>> wsdl in CXF?
> 
> 
> Yes. You can also look at JavaToWSDLProcessor.generate(ServiceInfo
> service,
> File output)  if you already
> created a serviceInfo instance.
> 
> 
>>
>> 2) If so, given a serviceName, what are the APIs we need to use to get
>> the
>> ServiceInfo, so we can pass it to JavaToWSDLProcessor.generate() method?
> 
> 
> JavaToWSDLProcessor uses serviceBuilder to create service . It only create
> one serviceInfo for the given serviceClass.  So you can create ServiceInfo
> first and pass it to the generate(serviceInfo, outputFile) api.
> Dose this help ?
> 
> 
> Jim.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-generate-wsdl-programmatically-using-cxf--tp24105734p24401484.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to generate wsdl programmatically using cxf?

Posted by jim ma <ma...@gmail.com>.
On Fri, Jun 19, 2009 at 1:29 PM, liw <pa...@yahoo.com> wrote:

>
> Hi, we are migrating from xfire to cxf. In xfire, we have the following
> code
> for generating wsdl.
>
>  XFire xfire = (XFire)BeanFactory.getBeanInstance("xfire");
>  Service origRegisteredService =
> xfire.getServiceRegistry().getService(serviceName);
>  origRegisteredService.getWSDLWriter().write(os);
>
> We need to migrate the above code from xfire to CXF.
>
> 1) Is JavaToWSDLProcessor.generate() the right API to use for generating
> wsdl in CXF?


Yes. You can also look at JavaToWSDLProcessor.generate(ServiceInfo service,
File output)  if you already
created a serviceInfo instance.


>
> 2) If so, given a serviceName, what are the APIs we need to use to get the
> ServiceInfo, so we can pass it to JavaToWSDLProcessor.generate() method?


JavaToWSDLProcessor uses serviceBuilder to create service . It only create
one serviceInfo for the given serviceClass.  So you can create ServiceInfo
first and pass it to the generate(serviceInfo, outputFile) api.
Dose this help ?


Jim.