| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
package argos.bangbang.axis; |
| 32 | |
|
| 33 | |
import java.lang.reflect.Method; |
| 34 | |
import java.util.ArrayList; |
| 35 | |
import java.util.List; |
| 36 | |
import java.util.logging.Level; |
| 37 | |
import java.util.logging.Logger; |
| 38 | |
|
| 39 | |
import javax.management.Notification; |
| 40 | |
|
| 41 | |
import org.apache.axis.AxisFault; |
| 42 | |
import org.apache.axis.handlers.soap.SOAPService; |
| 43 | |
import org.apache.axis.server.AxisServer; |
| 44 | |
import org.apache.axis.transport.http.AdminServlet; |
| 45 | |
import org.mortbay.jetty.servlet.Context; |
| 46 | |
import org.mortbay.jetty.servlet.ServletHolder; |
| 47 | |
|
| 48 | |
import argos.annotation.Description; |
| 49 | |
import argos.annotation.Impact; |
| 50 | |
import argos.annotation.Init; |
| 51 | |
import argos.annotation.NotificationHandler; |
| 52 | |
import argos.annotation.RemoveInstrumentation; |
| 53 | |
import argos.annotation.ServiceMeta; |
| 54 | |
import argos.bangbang.jetty6.Jetty; |
| 55 | |
import argos.bangbang.webservice.annotation.WebMethod; |
| 56 | |
import argos.deploy.ComponentManager; |
| 57 | |
import argos.metadata.ComponentMetaInfo; |
| 58 | |
import argos.metadata.ServiceMetaInfo; |
| 59 | |
import argos.naming.NamingService; |
| 60 | |
import axis.dynamic.AxisServlet2; |
| 61 | |
import axis.dynamic.SoapReceiver; |
| 62 | |
import axis.dynamic.SoapServerConfiguration; |
| 63 | |
|
| 64 | |
@Description("Bang bang SOAP service.") |
| 65 | 0 | public class Axis { |
| 66 | 0 | private static final Logger logger = Logger.getLogger(Axis.class.getName()); |
| 67 | |
|
| 68 | |
public static AxisServer axisServer; |
| 69 | |
private SoapServerConfiguration soapServerConfiguration; |
| 70 | |
private List<String> added; |
| 71 | |
|
| 72 | |
@ServiceMeta public ServiceMetaInfo meta; |
| 73 | |
|
| 74 | |
@Init |
| 75 | |
@Impact(Impact.ACTION) |
| 76 | |
@Description("Starts Axis") |
| 77 | |
public void init() throws Exception { |
| 78 | 0 | added = new ArrayList<String>(); |
| 79 | 0 | soapServerConfiguration = new SoapServerConfiguration(); |
| 80 | 0 | soapServerConfiguration.setDisableServicesList(false); |
| 81 | 0 | soapServerConfiguration.setServicesPath("/axis"); |
| 82 | |
|
| 83 | 0 | axisServer = new AxisServer(soapServerConfiguration); |
| 84 | 0 | axisServer.setName("AxisServlet"); |
| 85 | |
|
| 86 | 0 | Jetty jetty = (Jetty) NamingService.getInstance().getComponentByName("!!Jetty6"); |
| 87 | 0 | Context con = new Context(jetty.getJettyServer(), "/axis"); |
| 88 | 0 | con.addServlet(new ServletHolder(AxisServlet2.class), "/AxisServlet"); |
| 89 | 0 | con.addServlet(new ServletHolder(AxisServlet2.class), "/services/*"); |
| 90 | 0 | con.addServlet(new ServletHolder(AdminServlet.class), "/AdminServlet"); |
| 91 | 0 | con.setAttribute("AxisEngine", axisServer); |
| 92 | 0 | jetty.addContext(con); |
| 93 | 0 | } |
| 94 | |
|
| 95 | |
|
| 96 | |
@NotificationHandler |
| 97 | |
@RemoveInstrumentation |
| 98 | |
public void handler(Notification not) { |
| 99 | 0 | if(handle(not)) { |
| 100 | 0 | ServiceMetaInfo temp = (ServiceMetaInfo) not.getUserData(); |
| 101 | |
|
| 102 | 0 | if(temp.dependsOn(meta)) { |
| 103 | 0 | if(not.getType().equals(ComponentManager.SERVICE_STARTED)) { |
| 104 | 0 | for(ComponentMetaInfo tempMeta : ((ServiceMetaInfo) not.getUserData()).getComponentMetaInfo()) { |
| 105 | 0 | addComponent(tempMeta); |
| 106 | |
} |
| 107 | |
} |
| 108 | 0 | else if(not.getType().equals(ComponentManager.SERVICE_STOPPED)) { |
| 109 | 0 | for(ComponentMetaInfo tempMeta : ((ServiceMetaInfo) not.getUserData()).getComponentMetaInfo()) { |
| 110 | 0 | removeComponent(tempMeta); |
| 111 | |
} |
| 112 | |
} |
| 113 | |
} |
| 114 | |
} |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
@Impact(Impact.ACTION) |
| 118 | |
@Description("Removes a soap (component) service.") |
| 119 | |
public void addComponent(ComponentMetaInfo componentMeta) { |
| 120 | 0 | Object component = NamingService.getInstance().getComponentByMeta(componentMeta); |
| 121 | 0 | String name = componentMeta.getName(); |
| 122 | |
|
| 123 | 0 | Class<?> clazz = component.getClass(); |
| 124 | 0 | List<String> methods = new ArrayList<String>(); |
| 125 | 0 | for(Method method : clazz.getMethods()) { |
| 126 | 0 | if(method.isAnnotationPresent(WebMethod.class)) { |
| 127 | 0 | methods.add(method.getName()); |
| 128 | |
} |
| 129 | |
} |
| 130 | 0 | if(methods.isEmpty()) { |
| 131 | 0 | return; |
| 132 | |
} |
| 133 | |
|
| 134 | 0 | String[] m = new String[methods.size()]; |
| 135 | 0 | for(int i = 0; i < methods.size(); i++) { |
| 136 | 0 | m[i] = methods.get(i); |
| 137 | |
} |
| 138 | |
|
| 139 | 0 | SoapReceiver publisher = new SoapReceiver(); |
| 140 | 0 | publisher.setServiceName(name); |
| 141 | 0 | publisher.setTarget(component); |
| 142 | 0 | publisher.setAllowedMethods(m); |
| 143 | 0 | publisher.setServerConfiguration(soapServerConfiguration); |
| 144 | |
try { |
| 145 | 0 | SOAPService service = publisher.createService(); |
| 146 | 0 | soapServerConfiguration.deployService(name, service); |
| 147 | 0 | added.add(name); |
| 148 | 0 | logger.info("Deployed SOAP service " + name + " with operations " + |
| 149 | |
service.getServiceDescription().getAllowedMethods()); |
| 150 | |
} |
| 151 | 0 | catch (AxisFault e) { |
| 152 | 0 | logger.log(Level.SEVERE, "Unable to create SOAP service " + name + ": " + |
| 153 | |
e.getMessage(), e); |
| 154 | 0 | } |
| 155 | 0 | } |
| 156 | |
|
| 157 | |
@Description("Removes a soap (component) service.") |
| 158 | |
@Impact(Impact.ACTION) |
| 159 | |
public void removeComponent(ComponentMetaInfo componentMeta) { |
| 160 | 0 | if(added.remove(componentMeta.getName())) { |
| 161 | 0 | soapServerConfiguration.undeployService(componentMeta.getName()); |
| 162 | 0 | logger.info("Undeployed SOAP service " + componentMeta.getName()); |
| 163 | |
} |
| 164 | 0 | } |
| 165 | |
|
| 166 | |
|
| 167 | |
private boolean handle(Notification not) { |
| 168 | 0 | return (not.getType().equals(ComponentManager.SERVICE_STARTED) || |
| 169 | |
not.getType().equals(ComponentManager.SERVICE_STOPPED)); |
| 170 | |
} |
| 171 | |
} |