Home » Language IDEs » ServerTools (WTP) » Generating a WSDL File from a WSDL Model instance ?
Generating a WSDL File from a WSDL Model instance ? [message #225731] |
Sun, 28 December 2008 21:54 |
Eclipse User |
|
|
|
Originally posted by: mosser.polytech.unice.fr
Hi guys.
I'm new to webtools project, but this project seems to be exactly what I
was looking for !
For my research work, I develop a a code generation tools able to
automatically produce interface (XSD & WSDL) of BPEL Orchestration.
So, following a "generation" model describing the orchestration, I want
to create the ad'hoc XSD file (defining adequate ComptexTypes & Element)
and WSDL fille corresponding to this model.
Basically, my code iterate over the "generation" model and produce XSD
and WSDL entities (XSDSchema and Definition instances).
I was able to produce a XSD file using the classic 'Resource' EMF
framework:
> public void saveIntoXSDFile(String fileName){
> try {
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = new XSDResourceImpl(URI.createURI(fileName));
> resource.getContents().add(this.xsdSchema);
> resourceSet.getResources().add(resource);
> resource.save(Collections.EMPTY_MAP);
> }
> catch (Exception exception) {
> System.out.println(exception.getLocalizedMessage());
> exception.printStackTrace();
> }
> }
But I'm unable to perform the same for my WSDL Definition instance.
Using my best friend Google, I've found the "WSDLDocument" class, and
decide to use it:
> public void saveIntoWSDLFile(String fileName) {
> try {
> WSDLDocument doc = new WSDLDocument(this.wsdlDefinition);
> doc.write(fileName);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
But it throw a runtimeException:
> Exception in thread "main" java.lang.AbstractMethodError
> at com.ibm.wsdl.xml.WSDLWriterImpl.printExtensibilityAttributes (Unknown Source)
> at com.ibm.wsdl.xml.WSDLWriterImpl.printPortTypes(Unknown Source)
> at com.ibm.wsdl.xml.WSDLWriterImpl.printDefinition(Unknown Source)
> at com.ibm.wsdl.xml.WSDLWriterImpl.writeWSDL(Unknown Source)
> at org.apache.wsil.util.WSDLDocument.write(Unknown Source)
> at org.apache.wsil.util.WSDLDocument.write(Unknown Source)
> at fr.unice.i3s.modalis.soabridge.builders.WSDLBuilder.saveInto WSDLFile(WSDLBuilder.java:119)
> at fr.unice.i3s.modalis.soabridge.exec.Main.main(Main.java:31)
Any ideas ?
Cheers,
--
Sebastian Mosser
EPU Polytech'Nice - Sophia Antipolis, Office 314
CNRS / I3S / Modalis - http://rainbow.i3s.unice.fr/~mosser
|
|
|
Re: Generating a WSDL File from a WSDL Model instance ? [message #225740 is a reply to message #225731] |
Mon, 29 December 2008 12:01 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Sebastian,
I don't know much about how WSDL works, but I imagine it's very
analogous to XSD. More comments below...
Sebastian Mosser wrote:
> Hi guys.
>
> I'm new to webtools project, but this project seems to be exactly what
> I was looking for !
>
> For my research work, I develop a a code generation tools able to
> automatically produce interface (XSD & WSDL) of BPEL Orchestration.
>
> So, following a "generation" model describing the orchestration, I
> want to create the ad'hoc XSD file (defining adequate ComptexTypes &
> Element) and WSDL fille corresponding to this model.
>
> Basically, my code iterate over the "generation" model and produce XSD
> and WSDL entities (XSDSchema and Definition instances).
>
> I was able to produce a XSD file using the classic 'Resource' EMF
> framework:
>> public void saveIntoXSDFile(String fileName){
>> try {
>> ResourceSet resourceSet = new ResourceSetImpl();
>> Resource resource = new
>> XSDResourceImpl(URI.createURI(fileName));
Assuming you have extension "xsd" registered, which is normally the case
when running an Eclipse application, you'd use
resourceSet.createResource. If fileName is really a file name, you'd
use URI.createFileURI and you'd first make sure the fileName is absolute
iwth new File(fileName).getAbsolutePath().
>> resource.getContents().add(this.xsdSchema);
>> resourceSet.getResources().add(resource);
>> resource.save(Collections.EMPTY_MAP);
>> }
>> catch (Exception exception) {
>> System.out.println(exception.getLocalizedMessage());
>> exception.printStackTrace();
>> }
>> }
>
> But I'm unable to perform the same for my WSDL Definition instance.
> Using my best friend Google, I've found the "WSDLDocument" class, and
> decide to use it:
I'm quite sure that WSDL must have a resource factory as well the same
as XSD has XSDResourceFactoryImpl. If it's not already registered, you'd
register it and then you'd use exactly the same pattern as above.
>
>> public void saveIntoWSDLFile(String fileName) {
>> try {
>> WSDLDocument doc = new WSDLDocument(this.wsdlDefinition);
>> doc.write(fileName);
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>
> But it throw a runtimeException:
>
>> Exception in thread "main" java.lang.AbstractMethodError
>> at
>> com.ibm.wsdl.xml.WSDLWriterImpl.printExtensibilityAttributes (Unknown
>> Source)
>> at com.ibm.wsdl.xml.WSDLWriterImpl.printPortTypes(Unknown Source)
>> at com.ibm.wsdl.xml.WSDLWriterImpl.printDefinition(Unknown Source)
>> at com.ibm.wsdl.xml.WSDLWriterImpl.writeWSDL(Unknown Source)
>> at org.apache.wsil.util.WSDLDocument.write(Unknown Source)
>> at org.apache.wsil.util.WSDLDocument.write(Unknown Source)
>> at
>> fr.unice.i3s.modalis.soabridge.builders.WSDLBuilder.saveInto WSDLFile(WSDLBuilder.java:119)
>>
>> at fr.unice.i3s.modalis.soabridge.exec.Main.main(Main.java:31)
>
> Any ideas ?
>
> Cheers,
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Generating a WSDL File from a WSDL Model instance ? [message #225756 is a reply to message #225740] |
Mon, 29 December 2008 12:51 |
Eclipse User |
|
|
|
Originally posted by: mosser.polytech.unice.fr
Thanks for your answer.
Still encountering troubles ...
>>> public void saveIntoXSDFile(String fileName){
>>> try {
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> Resource resource = new
>>> XSDResourceImpl(URI.createURI(fileName));
> Assuming you have extension "xsd" registered, which is normally the case
> when running an Eclipse application, you'd use
> resourceSet.createResource. If fileName is really a file name, you'd
> use URI.createFileURI and you'd first make sure the fileName is absolute
> iwth new File(fileName).getAbsolutePath().
>>> resource.getContents().add(this.xsdSchema);
>>> resourceSet.getResources().add(resource);
>>> resource.save(Collections.EMPTY_MAP);
>>> }
>>> catch (Exception exception) {
>>> System.out.println(exception.getLocalizedMessage());
>>> exception.printStackTrace();
>>> }
>>> }
fileName is effectively an absolute file name => I'm now using
createFileURI.
About the resource creation, the following code
> Resource resource = new resourceSet.createResource(URI.createFileURI(fileName));
throw a null pointer exception at runtime. so I assume the "xsd" is not
registred as it should be, but I have no idea about how to fix this problem.
> I'm quite sure that WSDL must have a resource factory as well the same
> as XSD has XSDResourceFactoryImpl. If it's not already registered, you'd
> register it and then you'd use exactly the same pattern as above.
As my "quick'n dirty" XSDREsourceImpl usage worked for XSD file, I tried
to use the same ugly pattern for WSDL :
> public void saveIntoFile(String fileName) {
> try {
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource = new WSDLResourceImpl(URI.createURI(fileName));
> resource.getContents().add((EObject) this.result);
> resourceSet.getResources().add(resource);
> resource.save(Collections.EMPTY_MAP);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
It basically throw an exception at runtime:
> java.lang.NullPointerException
> at org.eclipse.wst.wsdl.util.WSDLResourceImpl.attached(WSDLReso urceImpl.java:655)
> at org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:415)
> at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
> at fr.unice.i3s.modalis.soabridge.builders.WSDLBuilder.saveInto File(WSDLBuilder.java:129)
> at fr.unice.i3s.modalis.soabridge.exec.Main.main(Main.java:30)
Using the 'resourceSet.createResource(URI.createFileURI(fileName))'
code, it also throw a nullPointerException.
So, I guess I've got two problems :
1) some troubles with the resourceSet configuration
=> I don't knwo how to "register" the resources ... any documentation ?
2) A bad understanding of the WSDL metamodel usage.
=> is ther some code examples availabe dealing with WSDL Definition xml
serialization ?
Cheers,
--
Sebastian
|
|
|
Re: Generating a WSDL File from a WSDL Model instance ? [message #225763 is a reply to message #225756] |
Mon, 29 December 2008 15:22 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------010603010905080502090007
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Sebastian,
Comments below.
Sebastian Mosser wrote:
> Thanks for your answer.
>
> Still encountering troubles ...
>
>
>>>> public void saveIntoXSDFile(String fileName){
>>>> try {
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> Resource resource = new
>>>> XSDResourceImpl(URI.createURI(fileName));
>> Assuming you have extension "xsd" registered, which is normally the
>> case when running an Eclipse application, you'd use
>> resourceSet.createResource. If fileName is really a file name, you'd
>> use URI.createFileURI and you'd first make sure the fileName is
>> absolute iwth new File(fileName).getAbsolutePath().
>>>> resource.getContents().add(this.xsdSchema);
>>>> resourceSet.getResources().add(resource);
>>>> resource.save(Collections.EMPTY_MAP);
>>>> }
>>>> catch (Exception exception) {
>>>> System.out.println(exception.getLocalizedMessage());
>>>> exception.printStackTrace();
>>>> }
>>>> }
>
> fileName is effectively an absolute file name => I'm now using
> createFileURI.
>
> About the resource creation, the following code
>> Resource resource = new
>> resourceSet.createResource(URI.createFileURI(fileName));
>
> throw a null pointer exception at runtime. so I assume the "xsd" is
> not registred as it should be, but I have no idea about how to fix
> this problem.
You're running some type of stand alone application, not an Eclipse OSGi
one? XSDMainExample is good to look at.
This should do the trick in general:
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xsd",
new XSDResourceFactoryImpl());
You'll want to find the WSDLResourceFactoryImpl as well...
>
>> I'm quite sure that WSDL must have a resource factory as well the
>> same as XSD has XSDResourceFactoryImpl. If it's not already
>> registered, you'd register it and then you'd use exactly the same
>> pattern as above.
>
> As my "quick'n dirty" XSDREsourceImpl usage worked for XSD file, I
> tried to use the same ugly pattern for WSDL :
>
>> public void saveIntoFile(String fileName) {
>> try { ResourceSet resourceSet = new
>> ResourceSetImpl();
>> Resource resource = new
>> WSDLResourceImpl(URI.createURI(fileName));
>> resource.getContents().add((EObject) this.result);
>> resourceSet.getResources().add(resource);
>> resource.save(Collections.EMPTY_MAP);
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>
> It basically throw an exception at runtime:
>> java.lang.NullPointerException
>> at
>> org.eclipse.wst.wsdl.util.WSDLResourceImpl.attached(WSDLReso urceImpl.java:655)
>>
Likely the problem is that resourceSet.getResources() doesn't contain
the resource so resource.getResourceSet is null...
Be sure to register the factories as I showed about and use
creatResource instead...
>> at
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:415)
>>
>> at
>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
>>
>> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>> at
>> fr.unice.i3s.modalis.soabridge.builders.WSDLBuilder.saveInto File(WSDLBuilder.java:129)
>>
>> at fr.unice.i3s.modalis.soabridge.exec.Main.main(Main.java:30)
>
> Using the 'resourceSet.createResource(URI.createFileURI(fileName))'
> code, it also throw a nullPointerException.
You're sure it's not your code doing that because createResource returns
null since no resources are registered?
>
> So, I guess I've got two problems :
>
> 1) some troubles with the resourceSet configuration
> => I don't knwo how to "register" the resources ... any documentation ?
XSDMainExample is good to look at. Also XSDPrototypicalSchema is full
of useful snippets and examples...
>
> 2) A bad understanding of the WSDL metamodel usage.
> => is ther some code examples availabe dealing with WSDL Definition
> xml serialization ?
It sounds like you're very close to getting it right.
>
> Cheers,
>
--------------010603010905080502090007
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Sebastian,<br>
<br>
Comments below.<br>
<br>
Sebastian Mosser wrote:
<blockquote cite="mid:gjah3s$7tq$1@build.eclipse.org" type="cite">Thanks
for your answer.
<br>
<br>
Still encountering troubles ...
<br>
<br>
<br>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">public void saveIntoXSDFile(String
fileName){
<br>
try {
<br>
ResourceSet resourceSet = new ResourceSetImpl();
<br>
Resource resource = new
XSDResourceImpl(URI.createURI(fileName));
<br>
</blockquote>
</blockquote>
Assuming you have extension "xsd" registered, which is normally the
case when running an Eclipse application, you'd use
resourceSet.createResource. If fileName is really a file name, you'd
use URI.createFileURI and you'd first make sure the fileName is
absolute iwth new File(fileName).getAbsolutePath().
<br>
<blockquote type="cite">
<blockquote type="cite">
resource.getContents().add(this.xsdSchema);
<br>
resourceSet.getResources().add(resource);
<br>
resource.save(Collections.EMPTY_MAP);
<br>
}
<br>
catch (Exception exception) {
<br>
System.out.println(exception.getLocalizedMessage());
<br>
exception.printStackTrace();
<br>
}
<br>
}
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
fileName is effectively an absolute file name => I'm now using
createFileURI.
<br>
<br>
About the resource creation, the following code
<br>
<blockquote type="cite">Resource resource = new
resourceSet.createResource(URI.createFileURI(fileName));
<br>
</blockquote>
<br>
throw a null pointer exception at runtime. so I assume the "xsd" is not
registred as it should be, but I have no idea about how to fix this
problem.
<br>
</blockquote>
You're running some type of stand alone application, not an Eclipse
OSGi one? XSDMainExample is good to look at.<br>
<br>
This should do the trick in general:<br>
<blockquote> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xsd",
new XSDResourceFactoryImpl());<br>
</blockquote>
You'll want to find the WSDLResourceFactoryImpl as well...<br>
<blockquote cite="mid:gjah3s$7tq$1@build.eclipse.org" type="cite"><br>
<blockquote type="cite">I'm quite sure that WSDL must have a resource
factory as well the same as XSD has XSDResourceFactoryImpl. If it's not
already registered, you'd register it and then you'd use exactly the
same pattern as above.
<br>
</blockquote>
<br>
As my "quick'n dirty" XSDREsourceImpl usage worked for XSD file, I
tried to use the same ugly pattern for WSDL :
<br>
<br>
<blockquote type="cite">public void saveIntoFile(String fileName) {
<br>
try { ResourceSet resourceSet = new
ResourceSetImpl();
<br>
Resource resource = new
WSDLResourceImpl(URI.createURI(fileName));
<br>
resource.getContents().add((EObject) this.result);
<br>
resourceSet.getResources().add(resource);
<br>
resource.save(Collections.EMPTY_MAP);
<br>
} catch (Exception e) {
<br>
e.printStackTrace();
<br>
}
<br>
}
<br>
</blockquote>
<br>
It basically throw an exception at runtime:
<br>
<blockquote type="cite">java.lang.NullPointerException
<br>
at
org.eclipse.wst.wsdl.util.WSDLResourceImpl.attached(WSDLReso urceImpl.java:655)
<br>
</blockquote>
</blockquote>
Likely the problem is that resourceSet.getResources() doesn't contain
the resource so resource.getResourceSet is null...<br>
<br>
Be sure to register the factories as I showed about and use
creatResource instead...<br>
<blockquote cite="mid:gjah3s$7tq$1@build.eclipse.org" type="cite">
<blockquote type="cite"> at
org.eclipse.emf.ecore.resource.impl.ResourceImpl$ContentsELi st.inverseAdd(ResourceImpl.java:415)
<br>
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
<br>
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
<br>
at
fr.unice.i3s.modalis.soabridge.builders.WSDLBuilder.saveInto File(WSDLBuilder.java:129)
<br>
at fr.unice.i3s.modalis.soabridge.exec.Main.main(Main.java:30)
<br>
</blockquote>
<br>
Using the 'resourceSet.createResource(URI.createFileURI(fileName))'
code, it also throw a nullPointerException.
<br>
</blockquote>
You're sure it's not your code doing that because createResource
returns null since no resources are registered?<br>
<blockquote cite="mid:gjah3s$7tq$1@build.eclipse.org" type="cite"><br>
So, I guess I've got two problems :
<br>
<br>
1) some troubles with the resourceSet configuration
<br>
=> I don't knwo how to "register" the resources ... any
documentation ?
<br>
</blockquote>
XSDMainExample is good to look at. Also XSDPrototypicalSchema is full
of useful snippets and examples...<br>
<blockquote cite="mid:gjah3s$7tq$1@build.eclipse.org" type="cite"><br>
2) A bad understanding of the WSDL metamodel usage.
<br>
=> is ther some code examples availabe dealing with WSDL Definition
xml serialization ?
<br>
</blockquote>
It sounds like you're very close to getting it right.<br>
<blockquote cite="mid:gjah3s$7tq$1@build.eclipse.org" type="cite"><br>
Cheers,
<br>
<br>
</blockquote>
</body>
</html>
--------------010603010905080502090007--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Generating a WSDL File from a WSDL Model instance ? [message #225788 is a reply to message #225763] |
Mon, 29 December 2008 17:26 |
Eclipse User |
|
|
|
Originally posted by: mosser.polytech.unice.fr
> You're running some type of stand alone application, not an Eclipse OSGi
> one? XSDMainExample is good to look at.
No !! I'm inside an EMF Project ...
>
> This should do the trick in general:
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xsd",
> new XSDResourceFactoryImpl());
>
> You'll want to find the WSDLResourceFactoryImpl as well...
Perfect, it works for me. Why this is not registrered by default is
still a mystery ...
> You're sure it's not your code doing that because createResource returns
> null since no resources are registered?
No, it was a missing plug-in dependency .
thanks for your answer, everything is fine now ;).
--
Sebastian
|
|
|
Goto Forum:
Current Time: Thu Jan 23 22:01:32 GMT 2025
Powered by FUDForum. Page generated in 0.02926 seconds
|