Srinath,

If it's not too much of a problem....Can you please add this as an enchancement 
request in
Bugzilla? So that we don't lose the code or the test case.

Thanks,
dims

--- Srinath Perera <[EMAIL PROTECTED]> wrote:
>  Hi all
> 
>     This is regarding the susantha's qustion. It seems that dims like a
> patch. I give it a try, So here it is, Please some commiter have a look
> at the patch. this has the patch, test case(If patch is accepted does my
> test case is good enough to add as the  test case for the senario).
> 
>     Actually this is my first patch (It take more time than write the
> code than come pass the     fiewall and create the patch. Thanks for all
> who helps me for that regards.)I hope the patch is correct, I follow
> instruction in apache site pls let me if anthing worng.
> 
>     please let me know if there are much more better ways to do thing
> (regarding code,comments anything).
> 
>   Any comment regarding this welcome. (I am on my toes to know what
> happen to my first Patch)
>   Thanks for your time
>   regards
> 
>   Srinath
> 
>  rest of the mail is as follows.
>  1) description of logic behind the patch
>  2) annoted results about the patch
>  3) comment about result 
> 
>  Description of logic behind the patch
>  -------------------------------------
>  User can specify the allowed methods add - that means any overloaded
> method of add or add(II),add(III).....
>  then they would come to the "List, allowedmethod" in the ServiceDesc 
> without breaking anything. (That was a big relef).
> 
>  Then I make sure that only the allowed methods can enter the
> method2OperationMap. I have private method
>  "isAllowedMethod" to help decide whether it is the a
> allowedMethod(using the allowedmethod list/ it
>  will return true all methods if user specify as e.g. "add" to make sure
> that this is backward compatible).
> 
>  Then I cover the all the places that you put() on to the hashmap
> method2OperationMap with the condition to to make
>  sure only methods we need are inside the hash map. (it is at
> setTypeMappingRegistry(TypeMappingRegistry tmr) and
>  and createOperationForMethod(Method method)).
> 
> 
>  The effect of that code seem to be the methods that is not specified is
> practially act as they do
>  not exists in the original code of service. That what we need I belive
> !!!!!!!!!!!!!!
>  * to run the test please refer to the comment on the test class
> 
>  Annoted result when the Calculator service in server-config.wsdd as
> given below.
> 
> ===============================================================================
> 
>  <service name="Calculator" provider="java:RPC">
>   <parameter name="allowedMethods"
> value="add,multiply(II),multiply([Ljava.lang.String),multiply(Ltest.data.CalcData)"/>
>   <parameter name="className" value="test.data.Calculator"/>
>   <beanMapping qname="ns:CalcData" xmlns:ns="urn:test.data"
>              languageSpecificType="java:test.data.CalcData"/>
>  </service>
> 
>  add is given in the .wsdd as "add" this test or backword compatibility
> *********************** test add(II) ***************************
> SUCSESS Got result : 11
> 
> ************************* test add(III) ************************
> SUCSESS Got result : 16
> Test specified simple method compatibility
> 
>  multiply(II) allowed should be sucessful
> ****************** test multiply(II) ******************
> SUCSESS Got result : 18
> 
>  multiply(III) not allowed should fail
> ************************* test multiply(III) **************************
> FAILEURE No such operation 'multiply'
> - FAILEURE
> AxisFault
>  faultCode: Server.userException
>  faultSubcode:
>  faultString: No such operation 'multiply'
>  faultActor:
>  faultNode:
>  faultDetail:
>       {http://xml.apache.org/axis/}stackTrace:AxisFault
 faultCode:
> Server.userException
 faultSubcode: 
 faultString: No
> such operation 'multiply'
 faultActor: 
 faultNode:
> 
 faultDetail: 

No such operation
> 'multiply'
        at
> org.apache.axis.message.RPCElement.deserialize(RPCElement.java:301)
        at
> org.apache.axis.message.RPCElement.getParams(RPCElement.java:347)
        at
> org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:184)
        at
> org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:334)
        at
> org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:71)
        at
> org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:150)
        at
> org.apache.axis.SimpleChain.invoke(SimpleChain.java:120)
        at
> org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:485)
        at
> org.apache.axis.server.AxisServer.invoke(AxisServer.java:324)
        at
> org.apache.axis.transport.http.SimpleAxisWorker.execute(SimpleAxisWorker.java:435)
        at
> org.apache.axis.transport.http.SimpleAxisWorker.run(SimpleAxisWorker.java:190)
        at
> java.lang.Thread.run(Thread.java:536)

> 
> No such operation 'multiply'
>       at
> org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:260)
>       at
> org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:169)
>       at
>
org.apache.axis.encoding.DeserializationContextImpl.endElement(DeserializationContextImpl.java:1083)
>       at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
> Source)
>       at
> org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown
> Source)
>       at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
>       at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
>       at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>       at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
>       at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>       at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>       at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
>       at
> org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:252)
>       at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:553)
>       at org.apache.axis.Message.getSOAPEnvelope(Message.java:378)
>       at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
>       at org.apache.axis.client.Call.invoke(Call.java:2553)
>       at org.apache.axis.client.Call.invoke(Call.java:2248)
>       at org.apache.axis.client.Call.invoke(Call.java:2171)
>       at org.apache.axis.client.Call.invoke(Call.java:1691)
>       at
>
test.deployment.OverloadedMethodRestrictionTest.testSpecifiedSimpleMethod(OverloadedMethodRestrictionTest.java:175)
>       at
> test.deployment.OverloadedMethodRestrictionTest.main(OverloadedMethodRestrictionTest.java:329)
> 
>  Complex type multiply(Ldata.Calculator) allowed should be succsessful
> ***************** test multiply(Ldata.Calculator)******************
> Got result : 3
> 
>  multiply([I)allowed should be succsessful
> ***************** test multiply([I)******************
> Got result : 362880
> 
>  multiply([I[I)allowed should fail
> ****************** test multiply[I[I *******************
> FAILEURE org.xml.sax.SAXException: Bad types (class [Ljava.lang.Object;
> -> int)
> - FAILEURE
> AxisFault
>  faultCode:
> {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
>  faultSubcode:
>  faultString: org.xml.sax.SAXException: Bad types (class
> [Ljava.lang.Object; -&gt; int)
>  faultActor:
>  faultNode:
>  faultDetail:
>       {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Bad
> types (class [Ljava.lang.Object; -&gt; int)
        at
> org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:317)
        at
>
org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.java:1031)
        at
> org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:198)
        at
> org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:845)
        at
> org.apache.axis.message.RPCElement.deserialize(RPCElement.java:233)
        at
> org.apache.axis.message.RPCElement.getParams(RPCElement.java:347)
        at
> org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:184)
        at
> org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:334)
        at
> org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:71)
        at
> org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:150)
        at
> org.apache.axis.SimpleChain.invoke(SimpleChain.java:120)
        at
> org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:485)
        at
> org.apache.axis.server.AxisServer.invoke(AxisServer.java:324)
        at
> org.apache.axis.transport.http.SimpleAxisWorker.execute(SimpleAxisWorker.java:435)
        at
> org.apache.axis.transport.http.SimpleAxisWorker.run(SimpleAxisWorker.java:190)
        at
> java.lang.Thread.run(Thread.java:536)

> 
> org.xml.sax.SAXException: Bad types (class [Ljava.lang.Object; -> int)
>       at
> org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:260)
>       at
> org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:169)
>       at
>
org.apache.axis.encoding.DeserializationContextImpl.endElement(DeserializationContextImpl.java:1083)
>       at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
> Source)
>       at
> org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown
> Source)
>       at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
>       at
> 
=== message truncated ===> --- ./patch/ServiceDesc.java 2003-07-29 08:35:19.000000000 
+0600
> +++ ServiceDesc.java  2003-07-29 08:18:45.000000000 +0600
> @@ -590,6 +590,20 @@
>          // javaTypes of the Method parameters.
>          //
>          // ------------------------------------------------
> +             
> +             //TODO this is new
> +                        /*
> +                                if the method not allowed we will do nothing
> +                        */
> +                        if (oper != null && implClass != null) {
> +                                List inParam = oper.getAllInParams();
> +                                Class[] params = new Class[inParam.size()];
> +                                for (int i = 0; i < params.length; i++) {
> +                                        params[i] = ((ParameterDesc) 
> inParam.get(i)).getJavaType();
> +                                }
> +                                if (!this.isAllowedMethod(params, oper.getName()))
> +                                        return;
> +                        }
>  
>          // If we're already mapped to a Java method, no need to do anything.
>          if (oper.getMethod() != null)
> @@ -957,12 +971,15 @@
>          // If we're done introspecting, or have completed this method, return
>          if (completedNames == null || completedNames.contains(methodName))
>              return;
> -
> +//TODO remove this this will check by my code
> +/*
>          // Skip it if it's not a sanctioned method name
>          if ((allowedMethods != null) &&
>              !allowedMethods.contains(methodName))
>              return;
>  
> +*/
> +
>          if ((disallowedMethods != null) &&
>              disallowedMethods.contains(methodName))
>              return;
> @@ -1081,6 +1098,13 @@
>       * if not.
>       */
>      private void createOperationForMethod(Method method) {
> +             
> +             //TODO this is new
> +               //if the method is not allowed we will simply return
> +             if ((method != null) &&
> +                        !isAllowedMethod(method.getParameterTypes(), 
> method.getName()))
> +                        return;
> +
>          // If we've already got it, never mind
>          if (method2OperationMap.get(method) != null) {
>              return;
> @@ -1354,4 +1378,82 @@
>      public void setTypeMappingRegistry(TypeMappingRegistry tmr) {
>          this.tmr = tmr;
>      }
> +     /**
> +      * Check a given method descriptions wheather it is an allowed method.
> +      * the allowed methods are specified in the wsdd file using the JNI standreads.
> +      *
> +      * Signature Java Programming Language Type
> +             Z - boolean
> +             B - byte
> +             C - char
> +             S - short
> +             I - int
> +             J - long
> +             F - float
> +             D - double
> +             L fully-qualified-class;  fully-qualified-class
> +             [ type - type[]
> +
> +      eg:- add(int a,int b) is add(II)
> +               getValue(SOAPHeaderElement[] headers) is
> getValue([Lorg.apache.axis.message.SOAPHeaderElement)
> +
> +      the convention used is
> +      method-name(attlist-in-jni)
> +
> +      * @param param
> +      * @param methodName
> +      * @return
> +      */
> +
> +     private boolean isAllowedMethod(Class[] param, String methodName) {
> +        if(this.allowedMethods == null) return true; //if allowed methods are null 
> that means
> all are allowed
> +             if (methodName != null) {
> +                     //if () is not added the it is considered to be using the old 
> convension (No parameters) and
> will return true. Do we need that ???
> +                     if ((param == null || param.length == 0) || 
> (this.allowedMethods.contains(methodName) ||
> this.allowedMethods.contains(methodName + "()")))
> +                             return true;
> +                     else {
> +                             StringBuffer name = new StringBuffer();
> +                             name.append(methodName + "(");
> +                             for (int i = 0; i < param.length; i++) {
> +                                     className2JNIName(param[i], name);
> +                             }
> +                             name.append(")");
> +                             if (this.allowedMethods.contains(name.toString()))
> +                                     return true;
> +                     }
> +             }
> +             return false;
> +     }
> +
> +     /**
> +      * This is a convinence method. It checks each parameter and append correct 
> string to the
> buffer
> +      * @param param
> +      * @param name
> +      */
> +     private void className2JNIName(Class param, StringBuffer name) {
> +             if (param.isArray()) {
> +                     name.append("[");
> +                     className2JNIName(param.getComponentType(), name);
> +             } else if (param.getName().equals("boolean")) {
> +                     name.append("Z");
> +             } else if (param.getName().equals("byte")) {
> +                     name.append("B");
> +             } else if (param.getName().equals("char")) {
> +                     name.append("C");
> +             } else if (param.getName().equals("short")) {
> +                     name.append("S");
> +             } else if (param.getName().equals("int")) {
> +                     name.append("I");
> +             } else if (param.getName().equals("long")) {
> +                     name.append("J");
> +             } else if (param.getName().equals("float")) {
> +                     name.append("F");
> +             } else if (param.getName().equals("double")) {
> +                     name.append("D");
> +             } else {
> +                     name.append("L" + param.getName());
> +             }
> +     }
>  }
> +
> +
> 

> ATTACHMENT part 3 application/x-tar name=test-case.tar



=====
Davanum Srinivas - http://webservices.apache.org/~dims/

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

Reply via email to