001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.deployment;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.Constants;
023: import org.apache.axis2.context.ConfigurationContext;
024: import org.apache.axis2.deployment.repository.util.ArchiveReader;
025: import org.apache.axis2.deployment.repository.util.DeploymentFileData;
026: import org.apache.axis2.description.AxisOperation;
027: import org.apache.axis2.description.AxisService;
028: import org.apache.axis2.description.AxisServiceGroup;
029: import org.apache.axis2.engine.AxisConfiguration;
030: import org.apache.axis2.i18n.Messages;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: import java.io.PrintWriter;
035: import java.io.StringWriter;
036: import java.io.File;
037: import java.util.ArrayList;
038: import java.util.HashMap;
039: import java.util.Iterator;
040:
041: public class ServiceDeployer implements Deployer {
042: private static final Log log = LogFactory
043: .getLog(ServiceDeployer.class);
044: private AxisConfiguration axisConfig;
045: private ConfigurationContext configCtx;
046:
047: //To initialize the deployer
048: public void init(ConfigurationContext configCtx) {
049: this .configCtx = configCtx;
050: this .axisConfig = this .configCtx.getAxisConfiguration();
051: }
052:
053: //Will process the file and add that to axisConfig
054:
055: public void deploy(DeploymentFileData deploymentFileData)
056: throws DeploymentException {
057: boolean isDirectory = deploymentFileData.getFile()
058: .isDirectory();
059: ArchiveReader archiveReader;
060: StringWriter errorWriter = new StringWriter();
061: archiveReader = new ArchiveReader();
062: String serviceStatus = "";
063: try {
064: deploymentFileData
065: .setClassLoader(
066: isDirectory,
067: axisConfig.getServiceClassLoader(),
068: (File) axisConfig
069: .getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR));
070: HashMap wsdlservice = archiveReader
071: .processWSDLs(deploymentFileData);
072: if (wsdlservice != null && wsdlservice.size() > 0) {
073: Iterator services = wsdlservice.values().iterator();
074: while (services.hasNext()) {
075: AxisService service = (AxisService) services.next();
076: Iterator operations = service.getOperations();
077: while (operations.hasNext()) {
078: AxisOperation axisOperation = (AxisOperation) operations
079: .next();
080: axisConfig.getPhasesInfo().setOperationPhases(
081: axisOperation);
082: }
083: }
084: }
085: AxisServiceGroup serviceGroup = new AxisServiceGroup(
086: axisConfig);
087: serviceGroup.setServiceGroupClassLoader(deploymentFileData
088: .getClassLoader());
089: ArrayList serviceList = archiveReader.processServiceGroup(
090: deploymentFileData.getAbsolutePath(),
091: deploymentFileData, serviceGroup, isDirectory,
092: wsdlservice, configCtx);
093: DeploymentEngine.addServiceGroup(serviceGroup, serviceList,
094: deploymentFileData.getFile().toURL(),
095: deploymentFileData, axisConfig);
096: log.info(Messages.getMessage(
097: DeploymentErrorMsgs.DEPLOYING_WS,
098: deploymentFileData.getName()));
099: } catch (DeploymentException de) {
100: de.printStackTrace();
101: log.error(Messages.getMessage(
102: DeploymentErrorMsgs.INVALID_SERVICE,
103: deploymentFileData.getName(), de.getMessage()), de);
104: PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
105: de.printStackTrace(error_ptintWriter);
106: serviceStatus = "Error:\n" + errorWriter.toString();
107:
108: throw de;
109:
110: } catch (AxisFault axisFault) {
111: log.error(Messages.getMessage(
112: DeploymentErrorMsgs.INVALID_SERVICE,
113: deploymentFileData.getName(), axisFault
114: .getMessage()), axisFault);
115: PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
116: axisFault.printStackTrace(error_ptintWriter);
117: serviceStatus = "Error:\n" + errorWriter.toString();
118:
119: throw new DeploymentException(axisFault);
120:
121: } catch (Exception e) {
122: if (log.isInfoEnabled()) {
123: StringWriter sw = new StringWriter();
124: PrintWriter pw = new PrintWriter(sw);
125: e.printStackTrace(pw);
126: log.info(Messages.getMessage(
127: DeploymentErrorMsgs.INVALID_SERVICE,
128: deploymentFileData.getName(), sw.getBuffer()
129: .toString()));
130: }
131: PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
132: e.printStackTrace(error_ptintWriter);
133: serviceStatus = "Error:\n" + errorWriter.toString();
134:
135: throw new DeploymentException(e);
136:
137: } catch (Throwable t) {
138: if (log.isInfoEnabled()) {
139: StringWriter sw = new StringWriter();
140: PrintWriter pw = new PrintWriter(sw);
141: t.printStackTrace(pw);
142: log.info(Messages.getMessage(
143: DeploymentErrorMsgs.INVALID_SERVICE,
144: deploymentFileData.getName(), sw.getBuffer()
145: .toString()));
146: }
147: PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
148: t.printStackTrace(error_ptintWriter);
149: serviceStatus = "Error:\n" + errorWriter.toString();
150:
151: throw new DeploymentException(new Exception(t));
152:
153: } finally {
154: if (serviceStatus.startsWith("Error:")) {
155: axisConfig.getFaultyServices().put(
156: deploymentFileData.getFile().getAbsolutePath(),
157: serviceStatus);
158: }
159: }
160: }
161:
162: public void setDirectory(String directory) {
163: }
164:
165: public void setExtension(String extension) {
166: }
167:
168: public void unDeploy(String fileName) throws DeploymentException {
169: try {
170: fileName = DeploymentEngine.getAxisServiceName(fileName);
171: AxisServiceGroup serviceGroup = axisConfig
172: .removeServiceGroup(fileName);
173: if (serviceGroup != null) {
174: configCtx.removeServiceGroupContext(serviceGroup);
175: log.info(Messages.getMessage(
176: DeploymentErrorMsgs.SERVICE_REMOVED, fileName));
177: } else {
178: axisConfig.removeFaultyService(fileName);
179: }
180: } catch (AxisFault axisFault) {
181: //May be a faulty service
182: axisConfig.removeFaultyService(fileName);
183:
184: throw new DeploymentException(axisFault);
185: }
186: }
187: }
|