Hi Rajith,

Service field was a useful parameter when BAM mediator is used inside an
API as I remember. And that field has to be there for the backward
compatibility as well IMO.
The problem is handling the NPE with a null check when executing*
msgCtx.getAxisService().getName()*.
There is no other way to prevent that exception other than handling it and
setting an empty string as the service. (I have attached a possible patch
which is not tested at all)
The correct way to handle this issue IMO is by handling the null value from
the Axis2 level.
WDYT?

Thanks.


*Maninda Edirisooriya*
Senior Software Engineer

*WSO2, Inc.*lean.enterprise.middleware.

*Blog* : http://maninda.blogspot.com/
*E-mail* : [email protected]
*Skype* : @manindae
*Twitter* : @maninda


On Sat, May 31, 2014 at 2:56 AM, Rajith Siriwardena <[email protected]> wrote:

> Hi,
> $Subject. From the following code chunks,
>
> ---------------------------- BamMediator.java
> AxisService service = msgCtx.getAxisService();
> if(service == null)
>
> { return true; }
> // When this is not inside an API theses parameters should be there
> if ((!service.getName().equals("__SynapseService")) &&
> (service.getParameter(ADMIN_SERVICE_PARAMETER) != null ||
> service.getParameter(HIDDEN_SERVICE_PARAMETER) != null)) { return true; }
>
> ---------------------------- PayloadDataBuilder.java
> try
>
> { service = msgCtx.getAxisService().getName(); }
>
> catch (Exception e)
>
> { String errorMsg = "Error occurred while Service Name is extracted. " +
> e.getMessage(); log.error(errorMsg, e); service = ""; }
>
> --------------------------- StreamDefinitionBuilder.java
> attributes.add(new Attribute(BamMediatorConstants.SERVICE_NAME,
> AttributeType.STRING));
> ---------------------------
>
>
> if the it is invoked from a proxy the value of service = <proxy which it
> is invoked> and it works. when it is invoked from a sequence service is
> null and it ends there
>
> as a solution to that I have removed the parts which checks the service
> and dropped it from sending with events. if it isn't violating any use
> case, attached patch to the jira issue can be used as a fix.
>
> jira issue: https://wso2.org/jira/browse/BAM-1642
>
> Thanks,
> --Rajith
>
> --
> *Rajith Siriwardana*
> Software Engineer
> WSO2 Inc. ; http://wso2.com
> *lean. enterprise. middleware*
>
> *www: **http://people.apache.org/~siriwardana
> <http://people.apache.org/~siriwardana>*
>
Index: src/main/java/org/wso2/carbon/mediator/bam/BamMediator.java
===================================================================
--- src/main/java/org/wso2/carbon/mediator/bam/BamMediator.java	(revision 204322)
+++ src/main/java/org/wso2/carbon/mediator/bam/BamMediator.java	(working copy)
@@ -16,10 +16,8 @@
 
 package org.wso2.carbon.mediator.bam;
 
-import org.apache.axis2.description.AxisService;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.SynapseLog;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.mediators.AbstractMediator;
 import org.wso2.carbon.mediator.bam.config.BamMediatorException;
 
@@ -56,19 +54,6 @@
             }
         }
 
-        org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
-
-        AxisService service = msgCtx.getAxisService();
-        if(service == null) {
-            return true;
-        }
-        // When this is not inside an API theses parameters should be there
-        if ((!service.getName().equals("__SynapseService")) &&
-            (service.getParameter(ADMIN_SERVICE_PARAMETER) != null ||
-             service.getParameter(HIDDEN_SERVICE_PARAMETER) != null)) {
-            return true;
-        }
-
         try {
             stream.sendEvents(messageContext);
         } catch (BamMediatorException e) {
Index: src/main/java/org/wso2/carbon/mediator/bam/builders/PayloadDataBuilder.java
===================================================================
--- src/main/java/org/wso2/carbon/mediator/bam/builders/PayloadDataBuilder.java	(revision 204322)
+++ src/main/java/org/wso2/carbon/mediator/bam/builders/PayloadDataBuilder.java	(working copy)
@@ -48,7 +48,7 @@
                                              Object[] payloadData) throws BamMediatorException {
         int i = 0;
         boolean direction;
         try{
             try{
                 direction = (!messageContext.isResponse() && !messageContext.isFaultResponse());
@@ -57,14 +57,8 @@
                 log.error(errorMsg, e);
                 direction = true;
             }
             try{
                 service = msgCtx.getAxisService().getName();
             } catch (Exception e) {
-                String errorMsg = "Error occurred while Service Name is extracted. " + e.getMessage();
-                log.error(errorMsg, e);
                 service = "";
             }
             try{
                 operation = msgCtx.getAxisOperation().getName().getLocalPart();
             } catch (Exception e) {
                 String errorMsg = "Error occurred while Operation Name is extracted. " + e.getMessage();

_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to