...
A successful run of Apache Maven will generate a report similar to the following:
4. Copy the GREG_HOME/
samples/handler/src/target/
org.wso2.carbon.registry.samples.handler-4.5.0.jar
into GREG_HOME/repository/components/dropins
.
...
7. Start the server and observe the command prompt. See Starting Governance Registry Management Console on Windows or Starting Governance Registry Management Console on Linux.
8. Navigate to the / collection of the Resource Browser and add an E-mail subscription for Update events.
Click the "Subscribe" button to create the subscription. Read about Managing the Resources and Managing Breadcrumb to learn how to navigate to the / collection. And read more about Managing Subscriptions.
9. Click on the E-mail Address verification link that you will receive via E-mail.
Info | ||
---|---|---|
| ||
In this example, John Smith uses a Gmail account. |
...
Code Block |
---|
This message was intercepted by EmailTransformHandler |
See also Notifications and Managing Subscriptions.
...
This sample can be improved to restrict which users will receive an E-mail notification. For example, it might be required to get an approval from a particular group of users before moving from one state to another. However, this E-mail might not make sense to be delivered to John Smith or Joe BloggBloggs. The following modification can be made to the code segment to restrict the recipients such that John Doe will receive this E-mail though John Smith or Joe Blogg Bloggs would not.
Code Block | ||
---|---|---|
| ||
package org.wso2.carbon.registry.samples.notifications; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.xpath.AXIOMXPath; import org.apache.axiom.soap.SOAPEnvelope; import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import org.apache.axis2.engine.Handler; import org.apache.axis2.handlers.AbstractHandler; import org.apache.axis2.transport.mail.MailConstants; import org.jaxen.JaxenException; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; public class EmailTransformHandler extends AbstractHandler implements Handler { private String[] blacklist = {"john@smith.com", "joe@bloggs.co.uk"}; private String name; public String getName() { return name; } public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { String address = msgContext.getTo().getAddress(); if (msgContext.getTo() != null && address.startsWith("mailto:")) { try { SOAPEnvelope envelope = msgContext.getEnvelope(); AXIOMXPath xPath = new AXIOMXPath("//ns:text"); xPath.addNamespace("ns", "http://ws.apache.org/commons/ns/payload"); OMElement element = (OMElement) ((ArrayList) xPath.evaluate(envelope)).get(0); if (restrict(msgContext, address, element)) { return InvocationResponse.ABORT; } element.setText(element.getText().replace("--", "This message was intercepted by " + "EmailTransformHandler\n--")); } catch (JaxenException e) { e.printStackTrace(); } } return InvocationResponse.CONTINUE; } private boolean restrict(MessageContext msgContext, String address, OMElement element) { final String checkItem = "Smoke Test Passed"; final String state = "Testing"; String subject = ((Map<String, String>) msgContext.getOptions().getProperty( MessageContext.TRANSPORT_HEADERS)).get(MailConstants.MAIL_HEADER_SUBJECT); return (subject.contains("CheckListItemChecked") && element.getText().contains( "CheckList item '" + checkItem + "' of LifeCycle State '" + state + "' was") && Arrays.binarySearch(blacklist, address.substring("mailto:".length())) >= 0); } public void revoke(MessageContext msgContext) { } public void setName(String name) { this.name = name; } } |
Info | ||
---|---|---|
| ||
In this example we have used the default We have also assumed that the For this to work, each user on Governance Registry should fill out their User Profile. |
...