KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > remote > resolver > soap > Resolver


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.tools.remote.resolver.soap;
10
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import javax.management.remote.JMXServiceURL JavaDoc;
16
17 import mx4j.log.Logger;
18 import mx4j.tools.remote.http.HTTPResolver;
19 import mx4j.tools.remote.soap.SOAPClientInvoker;
20 import org.apache.axis.client.AdminClient;
21 import org.apache.axis.client.Service;
22 import org.apache.axis.configuration.FileProvider;
23 import org.apache.axis.transport.http.AxisServlet;
24 import org.apache.axis.utils.Options;
25
26 /**
27  * @version $Revision: 1.1 $
28  */

29 public class Resolver extends HTTPResolver
30 {
31    private static final String JavaDoc SERVER_DEPLOY_WSDD = "server-deploy.wsdd";
32    private static final String JavaDoc SERVER_UNDEPLOY_WSDD = "server-undeploy.wsdd";
33    private static final String JavaDoc CLIENT_WSDD = "client.wsdd";
34    private static final String JavaDoc AXIS_DEPLOY_SERVICE = "AdminService";
35
36    public Object JavaDoc lookupClient(JMXServiceURL JavaDoc address, Map JavaDoc environment) throws IOException JavaDoc
37    {
38       String JavaDoc endpoint = getEndpoint(address, environment);
39
40       InputStream JavaDoc wsdd = getClass().getResourceAsStream(CLIENT_WSDD);
41       if (wsdd == null) throw new IOException JavaDoc("Could not find AXIS deployment descriptor");
42       Service service = new Service(new FileProvider(wsdd));
43       service.setMaintainSession(true);
44
45       return new SOAPClientInvoker(endpoint, service);
46    }
47
48    protected String JavaDoc getServletClassName()
49    {
50       return AxisServlet.class.getName();
51    }
52
53    protected void deploy(JMXServiceURL JavaDoc address, Map JavaDoc environment) throws IOException JavaDoc
54    {
55       String JavaDoc path = address.getURLPath();
56       if (!path.endsWith("/")) path += "/";
57       String JavaDoc deployPath = path + AXIS_DEPLOY_SERVICE;
58
59       JMXServiceURL JavaDoc temp = new JMXServiceURL JavaDoc(address.getProtocol(), address.getHost(), address.getPort(), deployPath);
60       String JavaDoc deployEndpoint = getEndpoint(temp, environment);
61
62       try
63       {
64          AdminClient deployer = new AdminClient();
65          Options options = new Options(null);
66          options.setDefaultURL(deployEndpoint);
67          InputStream JavaDoc wsdd = getClass().getResourceAsStream(SERVER_DEPLOY_WSDD);
68          if (wsdd == null) throw new IOException JavaDoc("Could not find AXIS deployment descriptor");
69          deployer.process(options, wsdd);
70       }
71       catch (RuntimeException JavaDoc x)
72       {
73          throw x;
74       }
75       catch (Exception JavaDoc x)
76       {
77          Logger logger = getLogger();
78          if (logger.isEnabledFor(Logger.INFO)) logger.info("Exception while deploying AXIS service", x);
79          throw new IOException JavaDoc("Could not deploy connector server to AXIS " + x.toString());
80       }
81    }
82
83    protected void undeploy(JMXServiceURL JavaDoc address, Map JavaDoc environment) throws IOException JavaDoc
84    {
85       String JavaDoc path = address.getURLPath();
86       if (!path.endsWith("/")) path += "/";
87       String JavaDoc undeployPath = path + AXIS_DEPLOY_SERVICE;
88
89       JMXServiceURL JavaDoc temp = new JMXServiceURL JavaDoc(address.getProtocol(), address.getHost(), address.getPort(), undeployPath);
90       String JavaDoc undeployEndpoint = getEndpoint(temp, environment);
91
92       try
93       {
94          AdminClient deployer = new AdminClient();
95          Options options = new Options(null);
96          options.setDefaultURL(undeployEndpoint);
97          InputStream JavaDoc wsdd = getClass().getResourceAsStream(SERVER_UNDEPLOY_WSDD);
98          if (wsdd == null) throw new IOException JavaDoc("Could not find AXIS deployment descriptor " + SERVER_UNDEPLOY_WSDD);
99          deployer.process(options, wsdd);
100       }
101       catch (Exception JavaDoc x)
102       {
103          Logger logger = getLogger();
104          if (logger.isEnabledFor(Logger.INFO)) logger.info("Exception while undeploying AXIS service", x);
105          throw new IOException JavaDoc("Could not undeploy connector server " + x.toString());
106       }
107    }
108 }
109
Popular Tags