diff --git a/src/zutil/net/ws/WSInterface.java b/src/zutil/net/ws/WSInterface.java index 4c265b9..582f124 100755 --- a/src/zutil/net/ws/WSInterface.java +++ b/src/zutil/net/ws/WSInterface.java @@ -32,29 +32,31 @@ import java.lang.annotation.Target; * * Specifies web service definitions. Which methods that will * be published and other related metadata. + * Only public and non static methods will be published or + * the WSIgnore annotation can be used to ignore the specific method. * * Example: *
  *	private static class Test implements WSInterface{
  *		public Test(){}
  *
- *		@WSDocumentation("blabla")
- *		@WSDLParamDocumentation("olle = a variable?")
+ *		@WSDocumentation("This is a description of the method")
+ *		@WSDLParamDocumentation("arg1 = variable description?")
  *		public void pubZ(
- *				@WSParamName("olle") int lol)
+ *				@WSParamName("arg1") int randomName)
  *				throws Exception{
  *			....
  *		}
  *
  *		@WSReturnName("param")
  *		public String pubA(
- *				@WSParamName(value="lol", optional=true) String lol)
+ *				@WSParamName(value="optArg", optional=true) String optionalParam)
  *				throws Exception{
  *			....
  *		}
  *
  *		@WSIgnore()
- *		public void privaZ(....){
+ *		public void privatZ(....){
  *			...
  *		}
  *	}
@@ -129,7 +131,7 @@ public interface WSInterface {
     @interface WSHeader { }
 
     /**
-     * Specifies the name space for method.
+     * Specifies the name space for the method.
      *
      * @author Ziver
      */
diff --git a/src/zutil/net/ws/WSMethodDef.java b/src/zutil/net/ws/WSMethodDef.java
index 66aff63..9afbff0 100755
--- a/src/zutil/net/ws/WSMethodDef.java
+++ b/src/zutil/net/ws/WSMethodDef.java
@@ -64,7 +64,7 @@ public class WSMethodDef {
      * @param me is a method in a class that implements WSInterface
      */
     protected WSMethodDef( WebServiceDef wsDef, Method me) {
-        if( !WSInterface.class.isAssignableFrom(me.getDeclaringClass()) )
+        if (!WSInterface.class.isAssignableFrom(me.getDeclaringClass()))
             throw new ClassCastException("Declaring class does not implement WSInterface!");
         this.wsDef = wsDef;
         method = me;
@@ -74,12 +74,12 @@ public class WSMethodDef {
         name = method.getName();
 
         //***** Documentation & Namespace
-        WSDocumentation tmpDoc = method.getAnnotation( WSDocumentation.class );
-        if(tmpDoc != null){
+        WSDocumentation tmpDoc = method.getAnnotation(WSDocumentation.class);
+        if (tmpDoc != null){
             doc = tmpDoc.value();
         }
-        WSNamespace tmpSpace = method.getAnnotation( WSNamespace.class );
-        if( tmpSpace != null )
+        WSNamespace tmpSpace = method.getAnnotation(WSNamespace.class);
+        if ( tmpSpace != null )
             namespace = tmpSpace.value();
         else
             namespace = wsDef.getNamespace()+"?#"+name;
@@ -91,10 +91,10 @@ public class WSMethodDef {
         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 ");
         first = true;
-        for(WSParameterDef param : outputs){
-            if(first)
+        for (WSParameterDef param : outputs){
+            if (first)
                 first = false;
             else
                 tmp.append(" ,");
diff --git a/src/zutil/net/ws/WebServiceDef.java b/src/zutil/net/ws/WebServiceDef.java
index 656b659..062c8f9 100755
--- a/src/zutil/net/ws/WebServiceDef.java
+++ b/src/zutil/net/ws/WebServiceDef.java
@@ -51,12 +51,12 @@ public class WebServiceDef {
         methods = new HashMap<>();
         name = intf.getSimpleName();
 
-        if( intf.getAnnotation( WSInterface.WSNamespace.class ) != null )
-            this.namespace = intf.getAnnotation( WSInterface.WSNamespace.class ).value();
+        if (intf.getAnnotation( WSInterface.WSNamespace.class) != null)
+            this.namespace = intf.getAnnotation(WSInterface.WSNamespace.class).value();
 
         for(Method m : intf.getDeclaredMethods()){
             // check for public methods
-            if((m.getModifiers() & Modifier.PUBLIC) > 0 &&
+            if ((m.getModifiers() & Modifier.PUBLIC) > 0 &&
                     !m.isAnnotationPresent(WSInterface.WSIgnore.class)){
                 WSMethodDef method = new WSMethodDef(this, m);
                 methods.put(method.getName(), method);
diff --git a/src/zutil/net/ws/rest/RESTClientInvocationHandler.java b/src/zutil/net/ws/rest/RESTClientInvocationHandler.java
index 6cdb557..35fe9a8 100644
--- a/src/zutil/net/ws/rest/RESTClientInvocationHandler.java
+++ b/src/zutil/net/ws/rest/RESTClientInvocationHandler.java
@@ -39,6 +39,7 @@ import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -97,8 +98,9 @@ public class RESTClientInvocationHandler implements InvocationHandler {
                 + (serviceUrl.getPath().endsWith("/") ? "" : "/")
                 + methodDef.getName());
 
-        for (int i = 0; i < methodDef.getOutputCount(); i++) {
-            WSParameterDef param = methodDef.getOutput(i);
+        List params =  methodDef.getOutputs();
+        for (int i = 0; i < params.size(); i++) {
+            WSParameterDef param = params.get(i);
             url.setParameter(param.getName(), args[i].toString());
         }
 
diff --git a/src/zutil/net/ws/rest/RESTHttpPage.java b/src/zutil/net/ws/rest/RESTHttpPage.java
index 763f48f..767ed27 100755
--- a/src/zutil/net/ws/rest/RESTHttpPage.java
+++ b/src/zutil/net/ws/rest/RESTHttpPage.java
@@ -36,6 +36,7 @@ import zutil.net.ws.WebServiceDef;
 import zutil.parser.json.JSONObjectOutputStream;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -71,32 +72,33 @@ public class RESTHttpPage implements HttpPage {
 
 
     protected String execute(String targetMethod, Map input) throws Exception {
-        if( wsDef.hasMethod(targetMethod) ){
+        if (wsDef.hasMethod(targetMethod)) {
             // Parse request
             WSMethodDef m = wsDef.getMethod(targetMethod);
-            Object[] params = prepareInputParams(m, input);
+            Object[] inputParams = prepareInputParams(m, input);
 
             // Invoke
-            Object ret = m.invoke(ws, params);
+            Object ret = m.invoke(ws, inputParams);
 
             // Generate Response
-            StringOutputStream dummyOut = new StringOutputStream();
-            JSONObjectOutputStream out = new JSONObjectOutputStream(dummyOut);
+            StringOutputStream strBuffer = new StringOutputStream();
+            JSONObjectOutputStream out = new JSONObjectOutputStream(strBuffer);
             out.enableMetaData(false);
             out.writeObject(ret);
             out.close();
-            return dummyOut.toString();
+            return strBuffer.toString();
         }
         return "{error: \"Unknown target: "+targetMethod+"\"}";
     }
 
-    private Object[] prepareInputParams(WSMethodDef method, Map input){
-        Object[] inputParams = new Object[method.getInputCount()];
+    private Object[] prepareInputParams(WSMethodDef methodDef, Map input){
+        List inputParamDefs = methodDef.getInputs();
+        Object[] inputParams = new Object[inputParamDefs.size()];
 
         // Get the parameter values
-        for(int i=0; i outputParamDefs = methodDef.getOutputs();
+            for (int i = 0; i < outputParamDefs.size(); i++) {
+                WSParameterDef param = outputParamDefs.get(i);
                 SOAPHttpPage.generateSOAPXMLForObj(method, args[i], param.getName());
             }
 
diff --git a/src/zutil/net/ws/soap/SOAPHttpPage.java b/src/zutil/net/ws/soap/SOAPHttpPage.java
index 0ab967d..f84ead0 100755
--- a/src/zutil/net/ws/soap/SOAPHttpPage.java
+++ b/src/zutil/net/ws/soap/SOAPHttpPage.java
@@ -45,6 +45,7 @@ import java.io.InputStreamReader;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -90,7 +91,7 @@ public class SOAPHttpPage implements HttpPage{
     /** Session enabled **/
     private boolean session_enabled;
 
-    public SOAPHttpPage( WebServiceDef wsDef ){
+    public SOAPHttpPage( WebServiceDef wsDef ) {
         this.wsDef = wsDef;
         this.session_enabled = false;
     }
@@ -103,7 +104,7 @@ public class SOAPHttpPage implements HttpPage{
      *
      * @param enabled is if session should be enabled
      */
-    public void enableSession(boolean enabled){
+    public void enableSession(boolean enabled) {
         this.session_enabled = enabled;
     }
 
@@ -143,16 +144,16 @@ public class SOAPHttpPage implements HttpPage{
             out.flush();
 
             WSInterface obj;
-            if(session_enabled){
-                if( session.containsKey("SOAPInterface"))
+            if (session_enabled) {
+                if ( session.containsKey("SOAPInterface"))
                     obj = (WSInterface)session.get("SOAPInterface");
-                else{
+                else {
                     obj = wsDef.newInstance();
                     session.put("SOAPInterface", obj);
                 }
             }
-            else{
-                if( ws == null )
+            else {
+                if (ws == null)
                     ws = wsDef.newInstance();
                 obj = ws;
             }
@@ -165,7 +166,7 @@ public class SOAPHttpPage implements HttpPage{
 
 
             // DEBUG
-            if( logger.isLoggable(Level.FINEST) ){
+            if (logger.isLoggable(Level.FINEST)) {
                 System.out.println("********** Request");
                 System.out.println(request);
                 System.out.println("********** Response");
@@ -183,10 +184,10 @@ public class SOAPHttpPage implements HttpPage{
      * @param		xml 	is the XML request
      * @return 				a Document with the response
      */
-    public Document genSOAPResponse(String xml){
+    public Document genSOAPResponse(String xml) {
         try {
             WSInterface obj;
-            if( ws == null )
+            if ( ws == null )
                 ws = wsDef.newInstance();
             obj = ws;
 
@@ -197,7 +198,7 @@ public class SOAPHttpPage implements HttpPage{
         return null;
     }
 
-    protected Document genSOAPResponse(String xml, WSInterface obj){
+    protected Document genSOAPResponse(String xml, WSInterface obj) {
         Document document = DocumentHelper.createDocument();
         Element envelope = document.addElement("soap:Envelope");
         try {
@@ -206,29 +207,29 @@ public class SOAPHttpPage implements HttpPage{
             envelope.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
 
             Element body = envelope.addElement( "soap:Body" );
-            try{
+            try {
                 Element request = getXMLRoot(xml);
-                if(request == null) return document;
+                if (request == null) return document;
                 // Header
-                if( request.element("Header") != null){
+                if ( request.element("Header") != null) {
                     Element header = envelope.addElement( "soap:Header" );
                     prepareInvoke( obj, request.element("Header"), header );
                 }
 
                 // Body
-                if( request.element("Body") != null){
+                if ( request.element("Body") != null) {
                     prepareInvoke( obj, request.element("Body"), body );
                 }
-            }catch(Throwable e){
+            } catch(Throwable e) {
                 body.clearContent();
                 Element fault = body.addElement("soap:Fault");
                 // The fault source
-                if(e instanceof SOAPException || e instanceof SAXException || e instanceof DocumentException)
+                if (e instanceof SOAPException || e instanceof SAXException || e instanceof DocumentException)
                     fault.addElement("faultcode").setText( "soap:Client" );
                 else
                     fault.addElement("faultcode").setText( "soap:Server" );
                 // The fault message
-                if( e.getMessage() == null || e.getMessage().isEmpty())
+                if ( e.getMessage() == null || e.getMessage().isEmpty())
                     fault.addElement("faultstring").setText( ""+e.getClass().getSimpleName() );
                 else
                     fault.addElement("faultstring").setText( ""+e.getMessage() );
@@ -248,7 +249,7 @@ public class SOAPHttpPage implements HttpPage{
      * @return 					the XML root Element
      */
     protected static Element getXMLRoot(String xml) throws DocumentException {
-        if(xml != null && !xml.isEmpty()){
+        if (xml != null && !xml.isEmpty()) {
             Document document = DocumentHelper.parseText(xml);
             return document.getRootElement();
         }
@@ -265,44 +266,46 @@ public class SOAPHttpPage implements HttpPage{
     @SuppressWarnings("unchecked")
     private void prepareInvoke(WSInterface obj, Element requestRoot, Element responseRoot) throws Throwable{
         Iterator it = requestRoot.elementIterator();
-        while( it.hasNext() ){
+        while(it.hasNext()) {
             Element e = it.next();
-            if( wsDef.hasMethod( e.getQName().getName()) ){
-                WSMethodDef m = wsDef.getMethod( e.getQName().getName() );
-                Object[] params = new Object[ m.getInputCount() ];
+            if (wsDef.hasMethod( e.getQName().getName())) {
+                WSMethodDef methodDef = wsDef.getMethod(e.getQName().getName());
+                List inputParamDefs = methodDef.getInputs();
+                Object[] inputParams = new Object[inputParamDefs.size()];
 
                 // Get the parameter values
-                for(int i=0; i outputParamDefs = methodDef.getOutputs();
 
                 // generate response XML
-                if( m.getOutputCount()>0 ){
+                if (outputParamDefs.size() > 0) {
                     Element response = responseRoot.addElement("");
-                    response.addNamespace("m",  m.getNamespace() );
-                    response.setName("m:"+m.getName()+"Response");
+                    response.addNamespace("m",  methodDef.getNamespace() );
+                    response.setName("m:"+methodDef.getName()+"Response");
 
-                    if( ret instanceof WSReturnObject ){
-                        Field[] f = ret.getClass().getFields();
-                        for(int i=0;  i c){
+    protected static String getSOAPClassName(Class c) {
         Class cTmp = getClass(c);
-        if(byte[].class.isAssignableFrom(c)){
+        if (byte[].class.isAssignableFrom(c)) {
             return "base64Binary";
         }
-        else if( WSReturnObject.class.isAssignableFrom(cTmp) ){
+        else if (WSReturnObject.class.isAssignableFrom(cTmp)) {
             return c.getSimpleName();
         }
-        else{
+        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");
+            if (cTmp == Integer.class)        ret = ret.replaceAll("integer", "int");
+            else if(cTmp == Character.class) ret = ret.replaceAll("character", "char");
 
             return ret;
         }
     }
 
-    protected static Class getClass(Class c){
-        if(c!=null && c.isArray()){
+    protected static Class getClass(Class c) {
+        if (c!=null && c.isArray()) {
             return getClass(c.getComponentType());
         }
         return c;
diff --git a/src/zutil/parser/wsdl/WSDLServiceSOAP.java b/src/zutil/parser/wsdl/WSDLServiceSOAP.java
index 7563159..78b2d5e 100644
--- a/src/zutil/parser/wsdl/WSDLServiceSOAP.java
+++ b/src/zutil/parser/wsdl/WSDLServiceSOAP.java
@@ -66,7 +66,7 @@ public class WSDLServiceSOAP extends WSDLService{
         input_body.addAttribute("namespace", method.getNamespace());
 
         //*************************** output
-        if( method.getOutputCount() > 0 ){
+        if(!method.getOutputs().isEmpty()){
             // definitions -> binding -> operation -> output
             Element output = operation.addElement("wsdl:output");
             // definitions -> binding -> operation -> input -> body
diff --git a/src/zutil/parser/wsdl/WSDLWriter.java b/src/zutil/parser/wsdl/WSDLWriter.java
index 4720844..a9585aa 100644
--- a/src/zutil/parser/wsdl/WSDLWriter.java
+++ b/src/zutil/parser/wsdl/WSDLWriter.java
@@ -139,7 +139,7 @@ public class WSDLWriter{
 
     private void generateMessage(Element parent, WSMethodDef method){
         //*************************** Input
-        if( method.getInputCount() > 0 ){
+        if(!method.getInputs().isEmpty()){
             // definitions -> message
             Element input = parent.addElement("wsdl:message");
             input.addAttribute("name", method.getName()+"Request");
@@ -156,7 +156,7 @@ public class WSDLWriter{
             }
         }
         //*************************** Output
-        if( method.getOutputCount() > 0 ){
+        if(!method.getOutputs().isEmpty()){
             // definitions -> message
             Element output = parent.addElement("wsdl:message");
             output.addAttribute("name", method.getName()+"Response");
@@ -205,19 +205,19 @@ public class WSDLWriter{
             }
 
             //*************************** Input
-            if( method.getInputCount() > 0 ){
+            if( method.getInputs().size() > 0 ){
                 // definitions -> message
                 Element input = operation.addElement("wsdl:input");
                 input.addAttribute("message", "tns:"+method.getName()+"Request");
             }
             //*************************** Output
-            if( method.getOutputCount() > 0 ){
+            if( method.getOutputs().size() > 0 ){
                 // definitions -> message
                 Element output = operation.addElement("wsdl:output");
                 output.addAttribute("message", "tns:"+method.getName()+"Response");
             }
             //*************************** Fault
-            if( method.getOutputCount() > 0 ){
+            if( method.getOutputs().size() > 0 ){
                 // definitions -> message
                 Element fault = operation.addElement("wsdl:fault");
                 fault.addAttribute("message", "tns:exception");
@@ -270,7 +270,7 @@ public class WSDLWriter{
         ArrayList> types = new ArrayList<>();
         // Find types
         for( WSMethodDef method : ws.getMethods() ){
-            if( method.getOutputCount() > 0 ){
+            if(!method.getOutputs().isEmpty()){
                 for( WSParameterDef param : method.getOutputs() ){
                     Class paramClass = param.getParamClass();
                     Class valueClass = getClass(paramClass);
diff --git a/test/zutil/net/ws/rest/RESTClientTest.java b/test/zutil/net/ws/rest/RESTClientTest.java
index 9b94fed..fda63ff 100755
--- a/test/zutil/net/ws/rest/RESTClientTest.java
+++ b/test/zutil/net/ws/rest/RESTClientTest.java
@@ -18,6 +18,7 @@ public class RESTClientTest {
 
     public interface OpenWeartherMap extends WSInterface {
 
+        @WSNamespace("")
         int weather(@WSParamName("q") String city);
     }