synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Saminda Abeyruwan <samin...@gmail.com>
Subject Re: svn commit: r355415 - in /incubator/synapse/trunk/java/src/sampleMediators/deprecation: ./ META-INF/
Date Sat, 10 Dec 2005 01:55:48 GMT
<service name="DeprecationMediator">
+    <operation name="mediate">
+        <messageReceiver class="sampleMediators.deprecation
.DeprecationMediator"/>
+    </operation>
+</service>

"class" in <messageReceiver/> points to a Mediator, which is theoritically
incorrect. It should point to a Implementer of MessageReceiver interface,
which has a way of calling mediator(MC) .
There should be a Inbuilt or custom message receiver at this level.

 Saminda

On 12/9/05, vikas@apache.org <vikas@apache.org> wrote:
>
> Author: vikas
> Date: Fri Dec  9 00:31:35 2005
> New Revision: 355415
>
> URL: http://svn.apache.org/viewcvs?rev=355415&view=rev
> Log:
> Refer to the README.txt
>
> Added:
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfiguration.java
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfigurator.java
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConstants.java
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationMediator.java
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationRule.java
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/META-INF/
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/META-INF/services.xml
>
>     incubator/synapse/trunk/java/src/sampleMediators/deprecation/README.txt
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfiguration.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfiguration.java?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfiguration.java
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfiguration.java
> Fri Dec  9 00:31:35 2005
> @@ -0,0 +1,67 @@
> +/*
> + * Copyright 2004,2005 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package sampleMediators.deprecation;
> +
> +public class DeprecationConfiguration {
> +
> +    private DeprecationRule rules[] = new DeprecationRule[0];
> +    private String enabled;
> +
> +    public DeprecationConfiguration() {
> +    }
> +
> +    public void addRule(DeprecationRule rule) {
> +        DeprecationRule tmp[] = new DeprecationRule[rules.length + 1];
> +        for (int i = 0; i < rules.length; i++) {
> +            tmp[i] = rules[i];
> +        }
> +        tmp[rules.length] = rule;
> +        this.rules = tmp;
> +    }
> +
> +    public void removeRule() {
> +        if (rules.length == 0)
> +            return;
> +        DeprecationRule tmp[] = new DeprecationRule[rules.length - 1];
> +        for (int i = 0; i < rules.length - 1; i++) {
> +            tmp[i] = rules[i];
> +        }
> +        this.rules = tmp;
> +    }
> +
> +    public boolean hasRule(String service) {
> +        for (int i = 0; i < rules.length; i++) {
> +            if (rules[i].getService().equals(service)) {
> +                return true;
> +            }
> +        }
> +        return false;
> +    }
> +
> +    public DeprecationRule[] getRules() {
> +        return rules;
> +    }
> +
> +    public void setEnabled(String enabled) {
> +        this.enabled = enabled;
> +    }
> +
> +    public String getEnabled() {
> +        return this.enabled;
> +    }
> +
> +}
> \ No newline at end of file
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfigurator.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfigurator.java?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfigurator.java
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConfigurator.java
> Fri Dec  9 00:31:35 2005
> @@ -0,0 +1,144 @@
> +/*
> + * Copyright 2004,2005 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package sampleMediators.deprecation;
> +
> +import org.apache.axis2.addressing.EndpointReference;
> +import org.apache.axis2.om.OMElement;
> +import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
> +
> +import javax.xml.namespace.QName;
> +import java.io.File;
> +import java.util.HashMap;
> +import java.util.Iterator;
> +import java.util.Map;
> +
> +public class DeprecationConfigurator {
> +
> +    /*
> +    *** MAP STRUCTURE ***
> +    The config map contains the parameter-sets for all the services and
> also a default
> +    parameter set. The key to this map is the endPoint reference of the
> service and the
> +    value associated with it is the parameter map corresponding to it.
> +
> +    <deprecationConfig>
> +        <service Id = "the serviceEPR">
> +                <parameterSet>
> +                    <fromDate>value</fromDate>
> +                    <toDate>value</toDate>
> +                </parameterSet>
> +                <parameterSet>
> +                    <fromDate>value</fromDate>
> +                    <toDate>value</toDate>
> +                </parameterSet>*
> +        </service>*
> +    </deprecationConfig>
> +
> +    This should map to
> +    key is ("serviceEPR")
> +    value is (map of parameterSet) i.e.
> +        map with key (parameter name), value (parameter value).
> +    */
> +
> +    public Map deprecationConfig;
> +    private Map configMap;
> +
> +    public DeprecationConfigurator() {
> +
> +        //Read from some source, probably a file and set the config map
> here.
> +        //If the source is service specific, we can use getConfig() and
> only access
> +        //service based parameters else make a general config and filter
> out the needed parameters
> +        //and create a Map in the getConfig(EndpointReference to)
> +        try {
> +            configMap = generateMap();
> +            setConfig(configMap);
> +        } catch (Exception e) {
> +            e.printStackTrace();
> +        }
> +    }
> +
> +    private Map generateMap() throws Exception {
> +
> +        //Read the source and generate a map of the
> +        Map generatedMap = new HashMap();
> +
> +        //ToDo - The file location should come as a parameter,
> +        //  read the parameter from Synapse.xml or some other source
> +        File file = new File(this.getClass
> ().getProtectionDomain().getCodeSource().getLocation().getPath());
> +        file = file.getParentFile();
> +        String filePath = file.getAbsolutePath() + File.separator +
> DeprecationConstants.CFG_XML_FOLDER;
> +        filePath = filePath + File.separator +
> DeprecationConstants.CFG_DEPRECATION_XML;
> +
> +        StAXOMBuilder staxOMBuilder;
> +
> +        staxOMBuilder = new StAXOMBuilder(filePath);
> +
> +        OMElement config = staxOMBuilder.getDocumentElement();
> +        config.build();
> +        Iterator serviceItr = config.getChildrenWithName(new QName(
> DeprecationConstants.CFG_DEPRECATION_SERVICE));
> +
> +        while (serviceItr.hasNext()) {
> +            OMElement serviceEle = (OMElement) serviceItr.next();
> +            String serviceKey = serviceEle.getAttributeValue(new
> QName("Id"));
> +            Iterator paramItr = serviceEle.getChildElements();
> +            int counter = 0;
> +            Map dataMap = new HashMap();
> +
> +            while (paramItr.hasNext()) {
> +                OMElement paramEle = (OMElement) paramItr.next();
> +                Iterator dataItr = paramEle.getChildElements();
> +
> +                while (dataItr.hasNext()) {
> +                    OMElement dataEle = (OMElement) dataItr.next();
> +                    String dataName = dataEle.getLocalName() + "[" +
> counter + "]";
> +                    String dataValue = dataEle.getText();
> +                    dataMap.put(dataName, dataValue);
> +                }
> +
> +                //Will be of use if multiple services are facaded by a
> single serviceEPR
> +                dataMap.put(DeprecationConstants.CFG_DEPRECATION_SERVICE+ "[" + counter
+ "]", serviceKey);
> +                counter++;
> +
> +            }
> +            generatedMap.put(serviceKey, dataMap);
> +        }
> +        return generatedMap;
> +    }
> +
> +    public Map getConfig(EndpointReference to) {
> +
> +        //Filter out the required parameters and generate the ConfigMap
> for this service
> +        //This is done by using the EndPointReference as a key into the
> configMap.
> +        //The value object corresponding to it is the required
> deprecationMap.
> +        //System.out.println("EPR = "+ to);
> +
> +        deprecationConfig = (Map) configMap.get(to.getAddress());
> +
> +        return deprecationConfig;
> +    }
> +
> +    public void setConfig(Map configMap) {
> +
> +        //In case we go for service-specific impl then the configMap will
> contain details
> +        // for the single service alone, hence this line.
> +        //If an aggregate approach is taken [i.e. all service data in a
> single source file]
> +        // then this method should not assign configMap to
> deprecationConfig.
> +
> +        this.deprecationConfig = configMap;
> +
> +    }
> +
> +}
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConstants.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConstants.java?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConstants.java
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationConstants.java
> Fri Dec  9 00:31:35 2005
> @@ -0,0 +1,28 @@
> +/*
> + * Copyright 2004,2005 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package sampleMediators.deprecation;
> +
> +public interface DeprecationConstants {
> +
> +    public static final String CFG_DEPRECATION_SERVICE =
> "deprecationService";
> +    public static final String CFG_DEPRECATION_FROM_DATE =
> "deprecationFromdate";
> +    public static final String CFG_DEPRECATION_TO_DATE =
> "deprecationTodate";
> +    public static final String CFG_DEPRECATION_ENABLED =
> "deprecationEnabled";
> +    public static final String CFG_DEPRECATION_RESULT = "
> synapse.deprecation.result";
> +    public static final String CFG_DEPRECATION_XML = "deprecation.xml";
> +    public static final String CFG_XML_FOLDER = "config";
> +}
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationMediator.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationMediator.java?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationMediator.java
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationMediator.java
> Fri Dec  9 00:31:35 2005
> @@ -0,0 +1,85 @@
> +/*
> + * Copyright 2004,2005 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package sampleMediators.deprecation;
> +
> +import org.apache.synapse.SynapseMessage;
> +import org.apache.synapse.api.Mediator;
> +
> +import java.util.Map;
> +
> +public class DeprecationMediator implements Mediator {
> +
> +    private static final DeprecationConfigurator deprecationConfigurator
> = new DeprecationConfigurator();
> +
> +    DeprecationConfiguration configuration;
> +
> +    public DeprecationMediator() {
> +    }
> +
> +    public boolean mediate(SynapseMessage synapseMessageContext) {
> +
> +        try {
> +
> +            Map mediatorConfig = deprecationConfigurator.getConfig(
> synapseMessageContext.getTo());
> +            loadConfiguration(mediatorConfig);
> +            DeprecationRule rules[] = configuration.getRules();
> +            boolean deprecated = false;
> +
> +            for (int i = 0, len = rules.length; i < len; i++) {
> +
> +                if (rules[i].isDeprecated()) {
> +                    deprecated = true;
> +                }
> +
> +            }
> +
> +            synapseMessageContext.setProperty(
> DeprecationConstants.CFG_DEPRECATION_RESULT, Boolean.valueOf(deprecated));
> +
> +            return !(deprecated);
> +
> +        } catch (Exception e) {
> +
> +            return false;
> +        }
> +    }
> +
> +    private void loadConfiguration(Map mediatorConfig) {
> +        configuration = new DeprecationConfiguration();
> +
> +        for (int i = 0; true; i++) {
> +
> +            String serviceKey =
> DeprecationConstants.CFG_DEPRECATION_SERVICE + "[" + i + "]";
> +            String fromDateKey =
> DeprecationConstants.CFG_DEPRECATION_FROM_DATE + "[" + i + "]";
> +            String toDateKey =
> DeprecationConstants.CFG_DEPRECATION_TO_DATE + "[" + i + "]";
> +            String enabledKey =
> DeprecationConstants.CFG_DEPRECATION_ENABLED + "[" + i + "]";
> +
> +            if (mediatorConfig.get(serviceKey) == null) {
> +                break;
> +            }
> +
> +
> +            DeprecationRule rule = new DeprecationRule();
> +            rule.setService((String) mediatorConfig.get(serviceKey));
> +            rule.setFromDate((String) mediatorConfig.get(fromDateKey));
> +            rule.setToDate((String) mediatorConfig.get(toDateKey));
> +            rule.setEnabled((String) mediatorConfig.get(enabledKey));
> +            configuration.addRule(rule);
> +        }
> +
> +    }
> +
> +}
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationRule.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationRule.java?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationRule.java
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/DeprecationRule.java
> Fri Dec  9 00:31:35 2005
> @@ -0,0 +1,118 @@
> +/*
> + * Copyright 2004,2005 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package sampleMediators.deprecation;
> +
> +import java.text.DateFormat;
> +import java.text.ParseException;
> +import java.text.SimpleDateFormat;
> +import java.util.Calendar;
> +import java.util.Date;
> +import java.util.GregorianCalendar;
> +import java.util.TimeZone;
> +
> +public class DeprecationRule {
> +
> +    private String service;
> +    private String fromDate;
> +    private String toDate;
> +    private String enabled;
> +
> +    public DeprecationRule() {
> +
> +    }
> +
> +    public DeprecationRule(String service) {
> +        this.service = service;
> +    }
> +
> +    public String getService() {
> +        return this.service;
> +    }
> +
> +    public void setService(String service) {
> +        this.service = service;
> +    }
> +
> +    public String getFromDate() {
> +        return this.fromDate;
> +    }
> +
> +    public void setFromDate(String fromDate) {
> +        this.fromDate = fromDate;
> +    }
> +
> +    public String getToDate() {
> +        return this.toDate;
> +    }
> +
> +    public void setToDate(String toDate) {
> +        this.toDate = toDate;
> +    }
> +
> +    public String getEnabled() {
> +        return this.enabled;
> +    }
> +
> +    public void setEnabled(String enabled) {
> +        this.enabled = enabled;
> +    }
> +
> +    public boolean isDeprecated() {
> +        try {
> +            if (Boolean.TRUE == Boolean.valueOf(enabled)) {
> +                Calendar current = Calendar.getInstance();
> +                TimeZone tz = current.getTimeZone();
> +                int offset = tz.getRawOffset();
> +                Calendar calendar = new GregorianCalendar(tz);
> +
> +                DateFormat df = new SimpleDateFormat("d/M/y:H:m");
> +                df.setTimeZone(tz);
> +
> +                Date d1 = df.parse(fromDate);
> +                Calendar fromCalendar = new GregorianCalendar(tz);
> +                d1.setTime(d1.getTime() + offset);
> +                fromCalendar.setTime(d1);
> +
> +                if (toDate == null || (toDate.length() == 0)) {
> +                    return calendar.before(fromCalendar);
> +                }
> +
> +                Date d2 = df.parse(toDate);
> +                Calendar toCalendar = new GregorianCalendar(tz);
> +                d2.setTime(d2.getTime() + offset);
> +                toCalendar.setTime(d2);
> +
> +                return (calendar.after(fromCalendar) && calendar.before
> (toCalendar));
> +            }
> +        } catch (ParseException e) {
> +            return false;
> +        }
> +
> +        return false;
> +    }
> +
> +    public String toString() {
> +        StringBuffer buf = new StringBuffer(1024);
> +        buf.append("Service : ").append(getService()).append("\n");
> +        buf.append("FromDate: ").append(getFromDate()).append("\n");
> +        buf.append("ToDate: ").append(getToDate()).append("\n");
> +        buf.append("Enabled: ").append(getEnabled()).append("\n");
> +
> +        return buf.toString();
> +    }
> +
> +}
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/META-INF/services.xml
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/META-INF/services.xml?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/META-INF/services.xml
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/META-INF/services.xml
> Fri Dec  9 00:31:35 2005
> @@ -0,0 +1,7 @@
> +<!-- Can be used if the mediator is to be provided as an axis2 service-->
> +<service name="DeprecationMediator">
> +    <operation name="mediate">
> +        <messageReceiver class="
> sampleMediators.deprecation.DeprecationMediator"/>
> +    </operation>
> +</service>
> +
> \ No newline at end of file
>
> Added:
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/README.txt
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/sampleMediators/deprecation/README.txt?rev=355415&view=auto
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/README.txt
> (added)
> +++
> incubator/synapse/trunk/java/src/sampleMediators/deprecation/README.txt Fri
> Dec  9 00:31:35 2005
> @@ -0,0 +1,35 @@
> +Hi everybody,
> +
> +Note
> +-----
> +
> +This is the first shot towards a Deprecation mediator.
> +A trivial explanation would be - A service configured as deprecated
> between certain dates/time will not
> +be accessible for requests coming in between those dates.
> +You are free to declare more than one set of dates/time and enable or
> disable the set when required.
> +
> +The mediator depends on the UTC - Date/time settings and these are
> converted and offset to local time,
> +during processing, internally.
> +
> +It implements the Mediator interface and hence has the "boolean
> mediate(SynapseMessage)" method.
> +The configuration data about the deprecation for a particular service is
> provided in a
> +"deprecation.xml" file.
> +
> +When a SynapseContext is sent to the DeprecationMediator it checks wether
> the service to which the request is
> +addressed is deprecatd or not. It sets the value in the "
> synapse.deprecation.result" property in the synapseContext.
> +
> +A config folder has been created in Synapse to hold the xml files that
> would be used to pass data to the mediators.
> +The deprecation.xml file is the one to begin with.
> +
> +Return Values
> +--------------
> +True - Service is not deprecated, the request can go on.
> +False - The service is deprecated, need not send the request to the
> service.
> +
> +To try out the mediator
> +------------------------
> +
> + - Modify the deprecation.xml present in the 'config' folder to suit the
> configuration you want.
> + - Send in a request to Synapse and see it work/get rejected depending on
> the settings.
> +
> +~Lots of scope for enhancement and improvement. Will keep adding up!
> \ No newline at end of file
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: synapse-dev-help@ws.apache.org
>
>

Mime
View raw message