[ 
https://issues.apache.org/jira/browse/CXF-2069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12699780#action_12699780
 ] 

Ted Leung commented on CXF-2069:
--------------------------------

An attempt was made at modifying WSDLToJavaContainer to use the URL provided as 
the services list then loop through the generation code with each line but that 
failed. The reason is the ToolContext is not reusable or reentrant or what ever 
you want to call it. The ToolContext is generated way back right at the 
beginning of the process and is passed though to here so it's not possible for 
me to re-make a new ToolContext. The ToolContext holds state information about 
the wsdl being generated so it's not immediately clear how to re-initialise the 
ToolContext either.

As such, I've given up on modifying the WSDLToJava to generate all services 
from a given list.

I've resorted to a much simpler hack and I've pasted it here in case anyone 
else needs a solution. Just write your own wrapper class as follows 

--------------------------------------------------------------

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import org.apache.cxf.tools.wsdlto.WSDLToJava;

/**
 * This class functions and has parameters identical to 
org.apache.cxf.tools.wsdlto.WSDLToJava
 * with the exception of the wsdlurl parameter, it should be the unformatted 
services list instead.
 * i.e. http://127.0.0.1:8095/hnr/ws?formatted=false   
 */
public class WsdlToJava
{
        public static void main(String... argv) throws Exception
        {
                URL url=new URL(argv[argv.length-1]);
                InputStream is=(InputStream)url.getContent();
                BufferedReader reader=new BufferedReader(new 
InputStreamReader(is));
                String tempLine=null;
                while ((tempLine=reader.readLine())!=null)
                {
                        if (!tempLine.endsWith("?wsdl")) 
tempLine=tempLine+"?wsdl";
                        argv[argv.length-1]=tempLine;
                        WSDLToJava.main(argv);
                }               
        }
}


> provide services list that's easily parseable
> ---------------------------------------------
>
>                 Key: CXF-2069
>                 URL: https://issues.apache.org/jira/browse/CXF-2069
>             Project: CXF
>          Issue Type: New Feature
>          Components: Transports
>    Affects Versions: 2.1
>         Environment: all
>            Reporter: Ted Leung
>            Assignee: Daniel Kulp
>            Priority: Trivial
>             Fix For: 2.0.11, 2.1.5
>
>         Attachments: patch.txt
>
>
> The motivation for this feature is to help support tools to generate all 
> client stubs for a given instance, i.e. a given instance may have 10 or more 
> service end points and therefore 10 different wsdl's. When generating client 
> stubs right now there's no easy way to generate all client stubs or to even 
> know what all available stubs are. You can see the "Available services" list 
> provided at the CXFServlet mapping point but that's currently provided in 
> HTML which is not as nice to parse and I would presume is meant to be human 
> readable and therefore I'm assuming the display may change when ever some one 
> desires a different display format.
> The idea here is to provide a terse programmatic listing, i.e. a raw 
> unformatted list.
> Attached is a patch file which outlines a simple change to the 
> ServletController.java which has a query string options of "?formatted=false" 
> which then displays the same list of services on new lines. 
> With the change, I was then able to use a simple command like wget to 
> retrieve the listing, then generate all client stubs for the given system 
> (without having to hard code the service end points into the script). i.e. 
> #!/bin/sh
> SERVICES_LIST_FILE=target/services_list.txt
> wget -O ${SERVICES_LIST_FILE} http://127.0.0.1:8095/hnr/ws?formatted=false
>                       
> for foo in `cat ${SERVICES_LIST_FILE}`
> do
>       java -classpath ${CLASSPATH} org.apache.cxf.tools.wsdlto.WSDLToJava 
> -verbose -client -p org.oscarehr.hnr.ws.client -d target/client_stubs 
> ${foo}?wsdl
> done

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to