From 77e4bce99b9dd8d779b72ab70016be59d2478ffc Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sat, 27 Feb 2021 00:01:02 +0100 Subject: [PATCH] Moved WSDL under WS and some fixes for REST service --- src/zutil/net/ws/WSClientFactory.java | 15 +- src/zutil/net/ws/WSInterface.java | 12 +- src/zutil/net/ws/WSMethodDef.java | 215 +++-- src/zutil/net/ws/rest/RESTClientFactory.java | 2 +- .../ws/rest/RESTClientInvocationHandler.java | 68 +- .../{parser => net/ws}/wsdl/WSDLHttpPage.java | 2 +- .../{parser => net/ws}/wsdl/WSDLService.java | 104 +-- .../ws}/wsdl/WSDLServiceSOAP.java | 156 ++-- .../{parser => net/ws}/wsdl/WSDLWriter.java | 784 +++++++++--------- test/zutil/net/ws/soap/SOAPTest.java | 2 +- 10 files changed, 730 insertions(+), 630 deletions(-) rename src/zutil/{parser => net/ws}/wsdl/WSDLHttpPage.java (98%) mode change 100755 => 100644 rename src/zutil/{parser => net/ws}/wsdl/WSDLService.java (95%) rename src/zutil/{parser => net/ws}/wsdl/WSDLServiceSOAP.java (96%) rename src/zutil/{parser => net/ws}/wsdl/WSDLWriter.java (97%) diff --git a/src/zutil/net/ws/WSClientFactory.java b/src/zutil/net/ws/WSClientFactory.java index 84532e0..122c407 100755 --- a/src/zutil/net/ws/WSClientFactory.java +++ b/src/zutil/net/ws/WSClientFactory.java @@ -45,18 +45,15 @@ public class WSClientFactory { * * @param is the class of the web service definition * @param intf is the class of the web service definition + * @param handler is the handler that will execute the calls to the web service * @return a client Object */ - public static T createClient(Class intf, InvocationHandler handler){ - if( !WSInterface.class.isAssignableFrom( intf )){ - throw new ClassCastException("The Web Service class is not a subclass of WSInterface!"); - } - + public static T createClient(Class intf, InvocationHandler handler){ try { - Class proxyClass = Proxy.getProxyClass( - WSClientFactory.class.getClassLoader(), intf); - Constructor constructor = proxyClass.getConstructor(InvocationHandler.class); - T obj = constructor.newInstance(handler); + T obj = (T) Proxy.newProxyInstance( + WSClientFactory.class.getClassLoader(), + new Class[] { intf }, + handler); return obj; } catch (Exception e){ diff --git a/src/zutil/net/ws/WSInterface.java b/src/zutil/net/ws/WSInterface.java index 1e32480..5ba4177 100755 --- a/src/zutil/net/ws/WSInterface.java +++ b/src/zutil/net/ws/WSInterface.java @@ -41,7 +41,7 @@ import java.lang.annotation.Target; * public Test(){} * * @WSDocumentation("This is a description of the method") - * @WSDLParamDocumentation("arg1 = variable description?") + * @WSParamDocumentation("arg1 = variable description?") * public void pubZ( * @WSParamName("arg1") int randomName) * throws Exception{ @@ -100,14 +100,14 @@ public interface WSInterface { */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - @interface WSIgnore { } + @interface WSIgnore {} /** * Method or Parameter comments for the WSDL. * These comments are put in the message part of the WSDL */ @Retention(RetentionPolicy.RUNTIME) - @interface WSDocumentation{ + @interface WSDocumentation { String value(); } @@ -116,7 +116,7 @@ public interface WSInterface { * These comments are put in the message part of the WSDL */ @Retention(RetentionPolicy.RUNTIME) - @interface WSParamDocumentation{ + @interface WSParamDocumentation { String value(); } @@ -125,7 +125,7 @@ public interface WSInterface { */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - @interface WSHeader { } + @interface WSHeader {} /** * Specifies the name space for the method. @@ -145,7 +145,7 @@ public interface WSInterface { } /** - * Specifies the specific path for the method overriding the auto generated path. + * Sets a specific path for the method overriding the auto generated path. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff --git a/src/zutil/net/ws/WSMethodDef.java b/src/zutil/net/ws/WSMethodDef.java index 4945c5a..9b292ed 100755 --- a/src/zutil/net/ws/WSMethodDef.java +++ b/src/zutil/net/ws/WSMethodDef.java @@ -26,6 +26,8 @@ package zutil.net.ws; import zutil.net.ws.WSInterface.WSDocumentation; import zutil.net.ws.WSInterface.WSNamespace; +import zutil.net.ws.WSInterface.WSPath; +import zutil.net.ws.WSInterface.WSRequestType; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -41,141 +43,215 @@ import java.util.List; */ // TODO: Header parameters public class WSMethodDef { - /** The parent web service definition **/ + /** + * The parent web service definition + **/ private WebServiceDef wsDef; - /** A list of input parameters **/ + /** + * A list of input parameters + **/ private ArrayList inputs; - /** A List of return parameters of the method **/ + /** + * A List of return parameters of the method + **/ private ArrayList outputs; - /** A List of exceptions that this method throws **/ + /** + * A List of exceptions that this method throws + **/ private ArrayList> exceptions; - /** The real method that this class represent, can be null if its a remote method **/ + /** + * The real method that this class represent, can be null if its a remote method + **/ private Method method; - /** Documentation of the method **/ + /** + * Documentation of the method + **/ private String doc; - /** This is the namespace of the method **/ + /** + * The namespace of the method + **/ private String namespace; - /** The published name of the method **/ + /** + * The type of request required to execute the method + **/ + private WSInterface.RequestType requestType; + /** + * The published name of the method + **/ private String name; + /** + * The endpoint location + **/ + private String path; /** - * - * @param me is a method in a class that implements WSInterface + * @param wsDef is the parent web service defining interface + * @param me is a method in a class that implements WSInterface */ - protected WSMethodDef( WebServiceDef wsDef, Method me) { + protected WSMethodDef(WebServiceDef wsDef, Method me) { if (!WSInterface.class.isAssignableFrom(me.getDeclaringClass())) throw new ClassCastException("Declaring class does not implement WSInterface!"); + this.wsDef = wsDef; - method = me; - inputs = new ArrayList<>(); - outputs = new ArrayList<>(); - exceptions = new ArrayList<>(); - name = method.getName(); + this.method = me; + this.inputs = new ArrayList<>(); + this.outputs = new ArrayList<>(); + this.exceptions = new ArrayList<>(); + this.name = method.getName(); - //***** Documentation & Namespace - WSDocumentation tmpDoc = method.getAnnotation(WSDocumentation.class); - if (tmpDoc != null){ - doc = tmpDoc.value(); - } - WSNamespace tmpSpace = method.getAnnotation(WSNamespace.class); - if ( tmpSpace != null ) - namespace = tmpSpace.value(); + // Handle documentation and namespace + + WSDocumentation docAnnotation = method.getAnnotation(WSDocumentation.class); + if (docAnnotation != null) + doc = docAnnotation.value(); + + WSNamespace namespaceAnnotation = method.getAnnotation(WSNamespace.class); + if (namespaceAnnotation != null) + namespace = namespaceAnnotation.value(); else - namespace = wsDef.getNamespace()+"?#"+name; + namespace = wsDef.getNamespace() + "?#" + name; + + // Hnadle Exceptions - //***** Exceptions Collections.addAll(exceptions, method.getExceptionTypes()); - //********* Get the input parameter names ********** + // Handle input parameter names + Annotation[][] paramAnnotation = method.getParameterAnnotations(); Class[] inputTypes = method.getParameterTypes(); - for (int i=0; i retClass = method.getReturnType(); Field[] fields = retClass.getFields(); - for (int i=0; i> getExceptions(){ + public List> getExceptions() { return exceptions; } /** * @return a list of input parameters */ - public List getInputs(){ + public List getInputs() { return inputs; } /** * @return a list of input parameters */ - public List getOutputs(){ + public List getOutputs() { return outputs; } /** - * @return Documentation of the method if one exists or else null + * @return documentation of the method if one exists or else null */ - public String getDocumentation(){ + public String getDocumentation() { return doc; } + /** + * @return the type of request needed to execute this method + */ + public WSInterface.RequestType getRequestType() { + return requestType; + } + /** * @return the namespace or endpoint url of the method */ - public String getNamespace(){ + public String getNamespace() { return namespace; } @@ -183,19 +259,21 @@ public class WSMethodDef { /** * Invokes a specified method * - * @param obj the object the method will called on - * @param params a vector with arguments + * @param params a vector with arguments + * @param obj the object the method will called on */ public Object invoke(Object obj, Object[] params) throws Exception { - return this.method.invoke(obj, params ); + return this.method.invoke(obj, params); } - public String toString(){ + public String toString() { StringBuilder tmp = new StringBuilder(); boolean first = true; + tmp.append(name).append("("); - for (WSParameterDef param : inputs){ + + for (WSParameterDef param : inputs) { if (first) first = false; else @@ -205,8 +283,9 @@ public class WSMethodDef { tmp.append(param.getName()); } tmp.append(") => "); + first = true; - for (WSParameterDef param : outputs){ + for (WSParameterDef param : outputs) { if (first) first = false; else diff --git a/src/zutil/net/ws/rest/RESTClientFactory.java b/src/zutil/net/ws/rest/RESTClientFactory.java index 987014e..fbcb5e9 100644 --- a/src/zutil/net/ws/rest/RESTClientFactory.java +++ b/src/zutil/net/ws/rest/RESTClientFactory.java @@ -51,7 +51,7 @@ public class RESTClientFactory { * @return a client Object */ public static T createClient(URL url, Class intf){ - T obj = WSClientFactory.createClient( intf, + T obj = WSClientFactory.createClient(intf, new RESTClientInvocationHandler(url, new WebServiceDef(intf))); return obj; } diff --git a/src/zutil/net/ws/rest/RESTClientInvocationHandler.java b/src/zutil/net/ws/rest/RESTClientInvocationHandler.java index a020b72..42b112f 100644 --- a/src/zutil/net/ws/rest/RESTClientInvocationHandler.java +++ b/src/zutil/net/ws/rest/RESTClientInvocationHandler.java @@ -35,7 +35,10 @@ import zutil.net.ws.WSMethodDef; import zutil.net.ws.WSParameterDef; import zutil.net.ws.WebServiceDef; import zutil.net.ws.soap.SOAPHttpPage; +import zutil.parser.DataNode; +import zutil.parser.json.JSONParser; +import javax.naming.OperationNotSupportedException; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.net.MalformedURLException; @@ -70,38 +73,52 @@ public class RESTClientInvocationHandler implements InvocationHandler { */ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - // Generate XML - HttpURL url = generateRESTRequest(method.getName(), args); + // Generate request - // Send request - HttpClient request = new HttpClient(HttpClient.HttpRequestType.POST); - request.setURL(url); - HttpHeader response = request.send(); - String rspJson = IOUtil.readContentAsString(request.getResponseInputStream()); - request.close(); + WSMethodDef methodDef = wsDef.getMethod(method.getName()); + HttpURL url = generateRESTRequest(methodDef, args); - // DEBUG - if (logger.isLoggable(Level.FINEST)) { - System.out.println("********** Request"); - System.out.println(url); - System.out.println("********** Response"); - System.out.println(rspJson); + String requestType = "GET"; + switch (methodDef.getRequestType()) { + case HTTP_GET: requestType = "GET"; break; + case HTTP_PUT: requestType = "PUT"; break; + case HTTP_POST: requestType = "POST"; break; + case HTTP_DELETE: requestType = "DELETE"; break; } - return parseRESTResponse(rspJson); + // Send request + + HttpClient request = new HttpClient(HttpClient.HttpRequestType.POST); + request.setURL(url); + request.setType(requestType); + + logger.fine("Sending request for: " + url); + HttpHeader response = request.send(); + logger.fine("Received response(" + response.getResponseStatusCode() + ")"); + + // Parse response + + String rspStr = IOUtil.readContentAsString(request.getResponseInputStream()); + request.close(); + + //if (logger.isLoggable(Level.FINEST)) { + System.out.println("********** Response: " + url); + System.out.println(rspStr); + //} + + Object rspObj = parseRESTResponse(methodDef, rspStr); + return rspObj; } - private HttpURL generateRESTRequest(String targetMethod, Object[] args) { - logger.fine("Sending request for " + targetMethod); + private HttpURL generateRESTRequest(WSMethodDef methodDef, Object[] args) { HttpURL url = new HttpURL(serviceUrl); - WSMethodDef methodDef = wsDef.getMethod(targetMethod); url.setPath(serviceUrl.getPath() + (serviceUrl.getPath().endsWith("/") ? "" : "/") - + methodDef.getName()); + + methodDef.getPath()); - List params = methodDef.getOutputs(); + List params = methodDef.getInputs(); for (int i = 0; i < params.size(); i++) { WSParameterDef param = params.get(i); url.setParameter(param.getName(), args[i].toString()); @@ -110,8 +127,15 @@ public class RESTClientInvocationHandler implements InvocationHandler { return url; } - private Object parseRESTResponse(String json) { + private Object parseRESTResponse(WSMethodDef methodDef, String str) { + DataNode json = JSONParser.read(str); + List outputs = methodDef.getOutputs(); - return null; + if (outputs.size() == 1) { + if (outputs.get(0).getParamClass().isAssignableFrom(DataNode.class)) + return json; + } + + throw new RuntimeException("WS JSON return type currently not supported: " + methodDef); } } diff --git a/src/zutil/parser/wsdl/WSDLHttpPage.java b/src/zutil/net/ws/wsdl/WSDLHttpPage.java old mode 100755 new mode 100644 similarity index 98% rename from src/zutil/parser/wsdl/WSDLHttpPage.java rename to src/zutil/net/ws/wsdl/WSDLHttpPage.java index f288cc2..58a9529 --- a/src/zutil/parser/wsdl/WSDLHttpPage.java +++ b/src/zutil/net/ws/wsdl/WSDLHttpPage.java @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -package zutil.parser.wsdl; +package zutil.net.ws.wsdl; import zutil.net.http.HttpHeader; import zutil.net.http.HttpPage; diff --git a/src/zutil/parser/wsdl/WSDLService.java b/src/zutil/net/ws/wsdl/WSDLService.java similarity index 95% rename from src/zutil/parser/wsdl/WSDLService.java rename to src/zutil/net/ws/wsdl/WSDLService.java index 9630372..2892323 100644 --- a/src/zutil/parser/wsdl/WSDLService.java +++ b/src/zutil/net/ws/wsdl/WSDLService.java @@ -1,52 +1,52 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020 Ziver Koc - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package zutil.parser.wsdl; - -import org.dom4j.Element; -import zutil.net.ws.WSMethodDef; - -/** - * This interface defines a WSDL Service type. - * - * User: Ziver - */ -public abstract class WSDLService { - /** The URL of this service **/ - private String url; - - public WSDLService(String url){ - this.url = url; - } - - public String getServiceAddress(){ - return url; - } - - public abstract String getServiceType(); - - public abstract void generateBinding(Element definitions); - - public abstract void generateOperation(Element definitions, WSMethodDef method); -} +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.net.ws.wsdl; + +import org.dom4j.Element; +import zutil.net.ws.WSMethodDef; + +/** + * This interface defines a WSDL Service type. + * + * User: Ziver + */ +public abstract class WSDLService { + /** The URL of this service **/ + private String url; + + public WSDLService(String url){ + this.url = url; + } + + public String getServiceAddress(){ + return url; + } + + public abstract String getServiceType(); + + public abstract void generateBinding(Element definitions); + + public abstract void generateOperation(Element definitions, WSMethodDef method); +} diff --git a/src/zutil/parser/wsdl/WSDLServiceSOAP.java b/src/zutil/net/ws/wsdl/WSDLServiceSOAP.java similarity index 96% rename from src/zutil/parser/wsdl/WSDLServiceSOAP.java rename to src/zutil/net/ws/wsdl/WSDLServiceSOAP.java index 18536b0..920d2b7 100644 --- a/src/zutil/parser/wsdl/WSDLServiceSOAP.java +++ b/src/zutil/net/ws/wsdl/WSDLServiceSOAP.java @@ -1,78 +1,78 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020 Ziver Koc - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package zutil.parser.wsdl; - -import org.dom4j.Element; -import zutil.net.ws.WSMethodDef; - -/** - * User: Ziver - */ -public class WSDLServiceSOAP extends WSDLService{ - - public WSDLServiceSOAP(String url){ - super(url); - } - - @Override - public String getServiceType() { return "soap"; } - - @Override - public void generateBinding(Element definitions) { - // definitions -> binding -> soap:binding - Element soap_binding = definitions.addElement("soap:binding"); - soap_binding.addAttribute("style", "rpc"); - soap_binding.addAttribute("transport", "http://schemas.xmlsoap.org/soap/http"); - } - - @Override - public void generateOperation(Element definitions, WSMethodDef method) { - // definitions -> binding -> operation - Element operation = definitions.addElement("wsdl:operation"); - operation.addAttribute("name", method.getName()); - - // definitions -> binding -> operation -> soap:operation - Element soap_operation = operation.addElement("soap:operation"); - soap_operation.addAttribute("soapAction", method.getNamespace()); - - //*************************** Input - // definitions -> binding -> operation -> input - Element input = operation.addElement("wsdl:input"); - // definitions -> binding -> operation -> input -> body - Element input_body = input.addElement("soap:body"); - input_body.addAttribute("use", "literal"); - input_body.addAttribute("namespace", method.getNamespace()); - - //*************************** output - if(!method.getOutputs().isEmpty()){ - // definitions -> binding -> operation -> output - Element output = operation.addElement("wsdl:output"); - // definitions -> binding -> operation -> input -> body - Element output_body = output.addElement("soap:body"); - output_body.addAttribute("use", "literal"); - output_body.addAttribute("namespace", method.getNamespace()); - } - } -} +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.net.ws.wsdl; + +import org.dom4j.Element; +import zutil.net.ws.WSMethodDef; + +/** + * User: Ziver + */ +public class WSDLServiceSOAP extends WSDLService{ + + public WSDLServiceSOAP(String url){ + super(url); + } + + @Override + public String getServiceType() { return "soap"; } + + @Override + public void generateBinding(Element definitions) { + // definitions -> binding -> soap:binding + Element soap_binding = definitions.addElement("soap:binding"); + soap_binding.addAttribute("style", "rpc"); + soap_binding.addAttribute("transport", "http://schemas.xmlsoap.org/soap/http"); + } + + @Override + public void generateOperation(Element definitions, WSMethodDef method) { + // definitions -> binding -> operation + Element operation = definitions.addElement("wsdl:operation"); + operation.addAttribute("name", method.getName()); + + // definitions -> binding -> operation -> soap:operation + Element soap_operation = operation.addElement("soap:operation"); + soap_operation.addAttribute("soapAction", method.getNamespace()); + + //*************************** Input + // definitions -> binding -> operation -> input + Element input = operation.addElement("wsdl:input"); + // definitions -> binding -> operation -> input -> body + Element input_body = input.addElement("soap:body"); + input_body.addAttribute("use", "literal"); + input_body.addAttribute("namespace", method.getNamespace()); + + //*************************** output + if(!method.getOutputs().isEmpty()){ + // definitions -> binding -> operation -> output + Element output = operation.addElement("wsdl:output"); + // definitions -> binding -> operation -> input -> body + Element output_body = output.addElement("soap:body"); + output_body.addAttribute("use", "literal"); + output_body.addAttribute("namespace", method.getNamespace()); + } + } +} diff --git a/src/zutil/parser/wsdl/WSDLWriter.java b/src/zutil/net/ws/wsdl/WSDLWriter.java similarity index 97% rename from src/zutil/parser/wsdl/WSDLWriter.java rename to src/zutil/net/ws/wsdl/WSDLWriter.java index 75d0322..2811b2c 100644 --- a/src/zutil/parser/wsdl/WSDLWriter.java +++ b/src/zutil/net/ws/wsdl/WSDLWriter.java @@ -1,392 +1,392 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020 Ziver Koc - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package zutil.parser.wsdl; - -import org.dom4j.Document; -import org.dom4j.DocumentHelper; -import org.dom4j.Element; -import org.dom4j.io.OutputFormat; -import org.dom4j.io.XMLWriter; -import zutil.io.StringOutputStream; -import zutil.net.ws.WSMethodDef; -import zutil.net.ws.WSParameterDef; -import zutil.net.ws.WSReturnObject; -import zutil.net.ws.WSReturnObject.WSValueName; -import zutil.net.ws.WebServiceDef; - -import java.io.*; -import java.lang.reflect.Field; -import java.util.ArrayList; - -public class WSDLWriter{ - /** Current Web service definition ***/ - private WebServiceDef ws; - /** Cache of generated WSDL **/ - private String cache; - /** A list of services **/ - private ArrayList services; - - public WSDLWriter( WebServiceDef ws ){ - this.services = new ArrayList<>(); - this.ws = ws; - } - - /** - * Add a service to be published with the WSDL - */ - public void addService(WSDLService serv){ - cache = null; - services.add(serv); - } - - - public void write( Writer out ) throws IOException { - out.write(generate()); - } - public void write( PrintStream out ) { - out.print(generate()); - } - public void write( OutputStream out ) throws IOException { - out.write(generate().getBytes() ); - } - - - private String generate(){ - if(cache == null){ - try { - OutputFormat outformat = OutputFormat.createPrettyPrint(); - StringOutputStream out = new StringOutputStream(); - XMLWriter writer = new XMLWriter(out, outformat); - - Document docroot = generateDefinition(); - writer.write(docroot); - - writer.flush(); - this.cache = out.toString(); - out.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return cache; - } - - private Document generateDefinition(){ - Document wsdl = DocumentHelper.createDocument(); - Element definitions = wsdl.addElement("wsdl:definitions"); - definitions.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); - definitions.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/"); - definitions.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/"); - definitions.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema"); - definitions.addNamespace("soap-enc", "http://schemas.xmlsoap.org/soap/encoding/"); - definitions.addNamespace("tns", ws.getNamespace()+"?type"); - definitions.addAttribute("targetNamespace", ws.getNamespace()); - - generateType(definitions); - generateMessages(definitions); - generatePortType(definitions); - generateBinding(definitions); - generateService(definitions); - - return wsdl; - } - - private void generateMessages(Element definitions){ - for( WSMethodDef method : ws.getMethods() ){ - generateMessage(definitions, method); - } - - // Default message used for functions without input parameters - // definitions -> message: empty - Element empty = definitions.addElement("wsdl:message"); - empty.addAttribute("name", "empty"); - // definitions -> message: empty -> part - Element empty_part = empty.addElement("wsdl:part"); - empty_part.addAttribute("name", "empty"); - empty_part.addAttribute("type", "td:empty"); - - // Exception message - // definitions -> message: exception - Element exception = definitions.addElement("wsdl:message"); - exception.addAttribute("name", "exception"); - // definitions -> message: exception -> part - Element exc_part = exception.addElement("wsdl:part"); - exc_part.addAttribute("name", "exception"); - exc_part.addAttribute("type", "td:string"); - } - - private void generateMessage(Element parent, WSMethodDef method){ - //*************************** Input - if(!method.getInputs().isEmpty()){ - // definitions -> message - Element input = parent.addElement("wsdl:message"); - input.addAttribute("name", method.getName()+"Request"); - - // Parameters - for( WSParameterDef param : method.getInputs() ){ - // definitions -> message -> part - Element part = input.addElement("wsdl:part"); - part.addAttribute("name", param.getName()); - part.addAttribute("type", "xsd:"+getClassName( param.getParamClass())); - - if( param.isOptional() ) - part.addAttribute("minOccurs", "0"); - } - } - //*************************** Output - if(!method.getOutputs().isEmpty()){ - // definitions -> message - Element output = parent.addElement("wsdl:message"); - output.addAttribute("name", method.getName()+"Response"); - - // Parameters - for( WSParameterDef param : method.getOutputs() ){ - // definitions -> message -> part - Element part = output.addElement("wsdl:part"); - part.addAttribute("name", param.getName()); - - Class paramClass = param.getParamClass(); - Class valueClass = getClass( paramClass ); - // is an binary array - if(byte[].class.isAssignableFrom( paramClass )){ - part.addAttribute("type", "xsd:base64Binary"); - } - // is an array? - else if( paramClass.isArray()){ - part.addAttribute("type", "td:" +getArrayClassName(paramClass)); - } - else if( WSReturnObject.class.isAssignableFrom(valueClass) ){ - // its an SOAPObject - part.addAttribute("type", "td:"+getClassName( paramClass )); - } - else{// its an Object - part.addAttribute("type", "xsd:"+getClassName( paramClass )); - } - } - } - } - - private void generatePortType(Element definitions){ - // definitions -> portType - Element portType = definitions.addElement("wsdl:portType"); - portType.addAttribute("name", ws.getName()+"PortType"); - - for( WSMethodDef method : ws.getMethods() ){ - // definitions -> portType -> operation - Element operation = portType.addElement("wsdl:operation"); - operation.addAttribute("name", method.getName()); - - // Documentation - if(method.getDocumentation() != null){ - Element doc = operation.addElement("wsdl:documentation"); - doc.setText(method.getDocumentation()); - } - - //*************************** Input - if( method.getInputs().size() > 0 ){ - // definitions -> message - Element input = operation.addElement("wsdl:input"); - input.addAttribute("message", "tns:"+method.getName()+"Request"); - } - //*************************** Output - if( method.getOutputs().size() > 0 ){ - // definitions -> message - Element output = operation.addElement("wsdl:output"); - output.addAttribute("message", "tns:"+method.getName()+"Response"); - } - //*************************** Fault - if( method.getOutputs().size() > 0 ){ - // definitions -> message - Element fault = operation.addElement("wsdl:fault"); - fault.addAttribute("message", "tns:exception"); - } - } - } - - - private void generateBinding(Element definitions){ - // definitions -> binding - Element binding = definitions.addElement("wsdl:binding"); - binding.addAttribute("name", ws.getName()+"Binding"); - binding.addAttribute("type", "tns:"+ws.getName()+"PortType"); - - for(WSDLService serv : services){ - serv.generateBinding(binding); - - for(WSMethodDef method : ws.getMethods()){ - serv.generateOperation(binding, method); - } - } - } - - - private void generateService(Element parent){ - // definitions -> service - Element root = parent.addElement("wsdl:service"); - root.addAttribute("name", ws.getName()+"Service"); - - // definitions -> service -> port - Element port = root.addElement("wsdl:port"); - port.addAttribute("name", ws.getName()+"Port"); - port.addAttribute("binding", "tns:"+ws.getName()+"Binding"); - - for(WSDLService serv : services){ - // definitions -> service-> port -> address - Element address = port.addElement(serv.getServiceType()+":address"); - address.addAttribute("location", serv.getServiceAddress()); - } - } - - /** - * This function generates the Type section of the WSDL. - *
-     * -wsdl:definitions
-     *     -wsdl:type
-     *  
- */ - private void generateType(Element definitions){ - ArrayList> types = new ArrayList<>(); - // Find types - for( WSMethodDef method : ws.getMethods() ){ - if(!method.getOutputs().isEmpty()){ - for( WSParameterDef param : method.getOutputs() ){ - Class paramClass = param.getParamClass(); - Class valueClass = getClass(paramClass); - // is an array? or special class - if( paramClass.isArray() || WSReturnObject.class.isAssignableFrom(valueClass)){ - // add to type generation list - if(!types.contains( paramClass )) - types.add( paramClass ); - } - } - } - } - - // definitions -> types - Element typeE = definitions.addElement("wsdl:types"); - Element schema = typeE.addElement("xsd:schema"); - schema.addAttribute("targetNamespace", ws.getNamespace()+"?type"); - - // empty type - Element empty = schema.addElement("xsd:complexType"); - empty.addAttribute("name", "empty"); - empty.addElement("xsd:sequence"); - - for(int n=0; n c = types.get(n); - // Generate Array type - if(c.isArray()){ - Class ctmp = getClass(c); - - Element type = schema.addElement("xsd:complexType"); - type.addAttribute("name", getArrayClassName(c)); - - Element sequence = type.addElement("xsd:sequence"); - - Element element = sequence.addElement("xsd:element"); - element.addAttribute("minOccurs", "0"); - element.addAttribute("maxOccurs", "unbounded"); - element.addAttribute("name", "element"); - element.addAttribute("nillable", "true"); - if( WSReturnObject.class.isAssignableFrom(ctmp) ) - element.addAttribute("type", "tns:"+getClassName(c).replace("[]", "")); - else - element.addAttribute("type", "xsd:"+getClassName(c).replace("[]", "")); - - if(!types.contains(ctmp)) - types.add(ctmp); - } - // Generate SOAPObject type - else if(WSReturnObject.class.isAssignableFrom(c)){ - Element type = schema.addElement("xsd:complexType"); - type.addAttribute("name", getClassName(c)); - - Element sequence = type.addElement("xsd:sequence"); - - Field[] fields = c.getFields(); - for(int i=0; i cTmp = getClass(fields[i].getType()); - if( WSReturnObject.class.isAssignableFrom(cTmp) ){ - element.addAttribute("type", "tns:"+getClassName(cTmp)); - if(!types.contains(cTmp)) - types.add(cTmp); - } - else{ - element.addAttribute("type", "xsd:"+getClassName(fields[i].getType())); - } - // Is the Field optional - if(tmp != null && tmp.optional()) - element.addAttribute("minOccurs", "0"); - } - } - } - } - - - /////////////////////////////////////////////////////////////////////////////////////////////// - // TODO: FIX THESE ARE DUPLICATES FROM SOAPHttpPage - /////////////////////////////////////////////////////////////////////////////////////////////// - - private Class getClass(Class c){ - if(c!=null && c.isArray()){ - return getClass(c.getComponentType()); - } - return c; - } - - private String getArrayClassName(Class c){ - return "ArrayOf"+getClassName(c).replaceAll("[\\[\\]]", ""); - } - - private String getClassName(Class c){ - Class cTmp = getClass(c); - if( byte[].class.isAssignableFrom(c) ){ - return "base64Binary"; - } - else if( WSReturnObject.class.isAssignableFrom(cTmp) ){ - return c.getSimpleName(); - } - else{ - String ret = c.getSimpleName().toLowerCase(); - - if( cTmp == Integer.class ) ret = ret.replaceAll("integer", "int"); - else if( cTmp == Character.class ) ret = ret.replaceAll("character", "char"); - - return ret; - } - } - - public void close() {} - -} +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package zutil.net.ws.wsdl; + +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.XMLWriter; +import zutil.io.StringOutputStream; +import zutil.net.ws.WSMethodDef; +import zutil.net.ws.WSParameterDef; +import zutil.net.ws.WSReturnObject; +import zutil.net.ws.WSReturnObject.WSValueName; +import zutil.net.ws.WebServiceDef; + +import java.io.*; +import java.lang.reflect.Field; +import java.util.ArrayList; + +public class WSDLWriter{ + /** Current Web service definition ***/ + private WebServiceDef ws; + /** Cache of generated WSDL **/ + private String cache; + /** A list of services **/ + private ArrayList services; + + public WSDLWriter( WebServiceDef ws ){ + this.services = new ArrayList<>(); + this.ws = ws; + } + + /** + * Add a service to be published with the WSDL + */ + public void addService(WSDLService serv){ + cache = null; + services.add(serv); + } + + + public void write( Writer out ) throws IOException { + out.write(generate()); + } + public void write( PrintStream out ) { + out.print(generate()); + } + public void write( OutputStream out ) throws IOException { + out.write(generate().getBytes() ); + } + + + private String generate(){ + if(cache == null){ + try { + OutputFormat outformat = OutputFormat.createPrettyPrint(); + StringOutputStream out = new StringOutputStream(); + XMLWriter writer = new XMLWriter(out, outformat); + + Document docroot = generateDefinition(); + writer.write(docroot); + + writer.flush(); + this.cache = out.toString(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return cache; + } + + private Document generateDefinition(){ + Document wsdl = DocumentHelper.createDocument(); + Element definitions = wsdl.addElement("wsdl:definitions"); + definitions.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/"); + definitions.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/"); + definitions.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/"); + definitions.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema"); + definitions.addNamespace("soap-enc", "http://schemas.xmlsoap.org/soap/encoding/"); + definitions.addNamespace("tns", ws.getNamespace()+"?type"); + definitions.addAttribute("targetNamespace", ws.getNamespace()); + + generateType(definitions); + generateMessages(definitions); + generatePortType(definitions); + generateBinding(definitions); + generateService(definitions); + + return wsdl; + } + + private void generateMessages(Element definitions){ + for( WSMethodDef method : ws.getMethods() ){ + generateMessage(definitions, method); + } + + // Default message used for functions without input parameters + // definitions -> message: empty + Element empty = definitions.addElement("wsdl:message"); + empty.addAttribute("name", "empty"); + // definitions -> message: empty -> part + Element empty_part = empty.addElement("wsdl:part"); + empty_part.addAttribute("name", "empty"); + empty_part.addAttribute("type", "td:empty"); + + // Exception message + // definitions -> message: exception + Element exception = definitions.addElement("wsdl:message"); + exception.addAttribute("name", "exception"); + // definitions -> message: exception -> part + Element exc_part = exception.addElement("wsdl:part"); + exc_part.addAttribute("name", "exception"); + exc_part.addAttribute("type", "td:string"); + } + + private void generateMessage(Element parent, WSMethodDef method){ + //*************************** Input + if(!method.getInputs().isEmpty()){ + // definitions -> message + Element input = parent.addElement("wsdl:message"); + input.addAttribute("name", method.getName()+"Request"); + + // Parameters + for( WSParameterDef param : method.getInputs() ){ + // definitions -> message -> part + Element part = input.addElement("wsdl:part"); + part.addAttribute("name", param.getName()); + part.addAttribute("type", "xsd:"+getClassName( param.getParamClass())); + + if( param.isOptional() ) + part.addAttribute("minOccurs", "0"); + } + } + //*************************** Output + if(!method.getOutputs().isEmpty()){ + // definitions -> message + Element output = parent.addElement("wsdl:message"); + output.addAttribute("name", method.getName()+"Response"); + + // Parameters + for( WSParameterDef param : method.getOutputs() ){ + // definitions -> message -> part + Element part = output.addElement("wsdl:part"); + part.addAttribute("name", param.getName()); + + Class paramClass = param.getParamClass(); + Class valueClass = getClass( paramClass ); + // is an binary array + if(byte[].class.isAssignableFrom( paramClass )){ + part.addAttribute("type", "xsd:base64Binary"); + } + // is an array? + else if( paramClass.isArray()){ + part.addAttribute("type", "td:" +getArrayClassName(paramClass)); + } + else if( WSReturnObject.class.isAssignableFrom(valueClass) ){ + // its an SOAPObject + part.addAttribute("type", "td:"+getClassName( paramClass )); + } + else{// its an Object + part.addAttribute("type", "xsd:"+getClassName( paramClass )); + } + } + } + } + + private void generatePortType(Element definitions){ + // definitions -> portType + Element portType = definitions.addElement("wsdl:portType"); + portType.addAttribute("name", ws.getName()+"PortType"); + + for( WSMethodDef method : ws.getMethods() ){ + // definitions -> portType -> operation + Element operation = portType.addElement("wsdl:operation"); + operation.addAttribute("name", method.getName()); + + // Documentation + if(method.getDocumentation() != null){ + Element doc = operation.addElement("wsdl:documentation"); + doc.setText(method.getDocumentation()); + } + + //*************************** Input + if( method.getInputs().size() > 0 ){ + // definitions -> message + Element input = operation.addElement("wsdl:input"); + input.addAttribute("message", "tns:"+method.getName()+"Request"); + } + //*************************** Output + if( method.getOutputs().size() > 0 ){ + // definitions -> message + Element output = operation.addElement("wsdl:output"); + output.addAttribute("message", "tns:"+method.getName()+"Response"); + } + //*************************** Fault + if( method.getOutputs().size() > 0 ){ + // definitions -> message + Element fault = operation.addElement("wsdl:fault"); + fault.addAttribute("message", "tns:exception"); + } + } + } + + + private void generateBinding(Element definitions){ + // definitions -> binding + Element binding = definitions.addElement("wsdl:binding"); + binding.addAttribute("name", ws.getName()+"Binding"); + binding.addAttribute("type", "tns:"+ws.getName()+"PortType"); + + for(WSDLService serv : services){ + serv.generateBinding(binding); + + for(WSMethodDef method : ws.getMethods()){ + serv.generateOperation(binding, method); + } + } + } + + + private void generateService(Element parent){ + // definitions -> service + Element root = parent.addElement("wsdl:service"); + root.addAttribute("name", ws.getName()+"Service"); + + // definitions -> service -> port + Element port = root.addElement("wsdl:port"); + port.addAttribute("name", ws.getName()+"Port"); + port.addAttribute("binding", "tns:"+ws.getName()+"Binding"); + + for(WSDLService serv : services){ + // definitions -> service-> port -> address + Element address = port.addElement(serv.getServiceType()+":address"); + address.addAttribute("location", serv.getServiceAddress()); + } + } + + /** + * This function generates the Type section of the WSDL. + *
+     * -wsdl:definitions
+     *     -wsdl:type
+     *  
+ */ + private void generateType(Element definitions){ + ArrayList> types = new ArrayList<>(); + // Find types + for( WSMethodDef method : ws.getMethods() ){ + if(!method.getOutputs().isEmpty()){ + for( WSParameterDef param : method.getOutputs() ){ + Class paramClass = param.getParamClass(); + Class valueClass = getClass(paramClass); + // is an array? or special class + if( paramClass.isArray() || WSReturnObject.class.isAssignableFrom(valueClass)){ + // add to type generation list + if(!types.contains( paramClass )) + types.add( paramClass ); + } + } + } + } + + // definitions -> types + Element typeE = definitions.addElement("wsdl:types"); + Element schema = typeE.addElement("xsd:schema"); + schema.addAttribute("targetNamespace", ws.getNamespace()+"?type"); + + // empty type + Element empty = schema.addElement("xsd:complexType"); + empty.addAttribute("name", "empty"); + empty.addElement("xsd:sequence"); + + for(int n=0; n c = types.get(n); + // Generate Array type + if(c.isArray()){ + Class ctmp = getClass(c); + + Element type = schema.addElement("xsd:complexType"); + type.addAttribute("name", getArrayClassName(c)); + + Element sequence = type.addElement("xsd:sequence"); + + Element element = sequence.addElement("xsd:element"); + element.addAttribute("minOccurs", "0"); + element.addAttribute("maxOccurs", "unbounded"); + element.addAttribute("name", "element"); + element.addAttribute("nillable", "true"); + if( WSReturnObject.class.isAssignableFrom(ctmp) ) + element.addAttribute("type", "tns:"+getClassName(c).replace("[]", "")); + else + element.addAttribute("type", "xsd:"+getClassName(c).replace("[]", "")); + + if(!types.contains(ctmp)) + types.add(ctmp); + } + // Generate SOAPObject type + else if(WSReturnObject.class.isAssignableFrom(c)){ + Element type = schema.addElement("xsd:complexType"); + type.addAttribute("name", getClassName(c)); + + Element sequence = type.addElement("xsd:sequence"); + + Field[] fields = c.getFields(); + for(int i=0; i cTmp = getClass(fields[i].getType()); + if( WSReturnObject.class.isAssignableFrom(cTmp) ){ + element.addAttribute("type", "tns:"+getClassName(cTmp)); + if(!types.contains(cTmp)) + types.add(cTmp); + } + else{ + element.addAttribute("type", "xsd:"+getClassName(fields[i].getType())); + } + // Is the Field optional + if(tmp != null && tmp.optional()) + element.addAttribute("minOccurs", "0"); + } + } + } + } + + + /////////////////////////////////////////////////////////////////////////////////////////////// + // TODO: FIX THESE ARE DUPLICATES FROM SOAPHttpPage + /////////////////////////////////////////////////////////////////////////////////////////////// + + private Class getClass(Class c){ + if(c!=null && c.isArray()){ + return getClass(c.getComponentType()); + } + return c; + } + + private String getArrayClassName(Class c){ + return "ArrayOf"+getClassName(c).replaceAll("[\\[\\]]", ""); + } + + private String getClassName(Class c){ + Class cTmp = getClass(c); + if( byte[].class.isAssignableFrom(c) ){ + return "base64Binary"; + } + else if( WSReturnObject.class.isAssignableFrom(cTmp) ){ + return c.getSimpleName(); + } + else{ + String ret = c.getSimpleName().toLowerCase(); + + if( cTmp == Integer.class ) ret = ret.replaceAll("integer", "int"); + else if( cTmp == Character.class ) ret = ret.replaceAll("character", "char"); + + return ret; + } + } + + public void close() {} + +} diff --git a/test/zutil/net/ws/soap/SOAPTest.java b/test/zutil/net/ws/soap/SOAPTest.java index 119c57e..089eb45 100755 --- a/test/zutil/net/ws/soap/SOAPTest.java +++ b/test/zutil/net/ws/soap/SOAPTest.java @@ -31,7 +31,7 @@ import zutil.net.ws.WSInterface; import zutil.net.ws.WSInterface.WSNamespace; import zutil.net.ws.WSReturnObject; import zutil.net.ws.WebServiceDef; -import zutil.parser.wsdl.WSDLWriter; +import zutil.net.ws.wsdl.WSDLWriter; // TODO: Convert to JUnit