001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.common.sa.component;
025:
026: import java.io.File;
027: import java.util.List;
028:
029: import javax.wsdl.WSDLException;
030:
031: import org.eclipse.core.runtime.Path;
032:
033: import com.bostechcorp.cbesb.common.i18n.Message;
034: import com.bostechcorp.cbesb.common.i18n.Messages;
035: import com.bostechcorp.cbesb.common.sa.service.EndPoint;
036: import com.bostechcorp.cbesb.common.sa.service.PropertiesKey;
037: import com.bostechcorp.cbesb.common.sa.service.PropertyUtil;
038: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
039: import com.bostechcorp.cbesb.common.util.FileUtil;
040: import com.bostechcorp.cbesb.common.util.generators.wsdl.generators.AbstractWsdlGenaretor;
041: import com.bostechcorp.cbesb.common.util.generators.wsdl.generators.HttpWsdlGenerator;
042:
043: public class HTTPComponent extends AbstractComponent {
044:
045: public HTTPComponent() {
046: super ();
047: }
048:
049: public String getComponentName() {
050: return "ChainBuilderESB-BC-HTTP";
051: }
052:
053: @Override
054: public void generateWSDL(String path, String saName)
055: throws Exception {
056: for (int i = 0; i < getEndPointList().size(); i++) {
057: EndPoint endPoint = this .endPointList.get(i);
058: // String endPointName = endPoint.getName();
059: String role = endPoint.getRole();
060:
061: // if it is client and SOAP is enable then
062: // use HTTP-MERGER instead of HTTp generator
063: if ("true".equals(endPoint.getSettings().getProperty(
064: PropertiesKey.HTTP_SOAP_ENABLE))
065: && !PropertyUtil.isConsumer(role)) {
066:
067: // HttpWsdlMerger mmerger = new HttpWsdlMerger(path, saName,
068: // getName(), this.getComponentType(), endPoint, endPoint
069: // .getSettings().getProperty(
070: // PropertiesKey.HTTP_SOAP_WSDLRESOURCE));
071: // mmerger.writeToFile();
072:
073: //Copy wsdlResourceFile to required location
074: //Copy the files from src/wsdl/{SU_NAME} folder
075: //into the src/SUs/{SU_NAME}/wsdlPublic
076: File file = new File(
077: EsbPathHelper
078: .getFullPathForDef(endPoint
079: .getSettings()
080: .getProperty(
081: PropertiesKey.HTTP_SOAP_WSDLRESOURCE)));
082: Path auxPp = new Path(EsbPathHelper
083: .getCbesbUiWorkSpace());
084: auxPp = (Path) auxPp.append(saName).append("src")
085: .append("SUs").append(saName + "_" + getName())
086: .append("wsdlPublic");
087: String newPath = auxPp.toString();
088: File dirs = new File(newPath);
089: dirs.mkdirs();
090: FileUtil.copyFile(file, newPath);
091: //change the wsdlResource path
092: String impWSdl = endPoint.getSettings().getProperty(
093: PropertiesKey.HTTP_SOAP_WSDLRESOURCE);
094: String fileName = new Path(EsbPathHelper
095: .getFullPathForDef(impWSdl)).lastSegment();
096: endPoint.getSettings().setProperty(
097: PropertiesKey.HTTP_SOAP_WSDLRESOURCE,
098: "wsdlPublic/" + fileName);
099: //generate WSDL FIle
100: AbstractWsdlGenaretor generator = getWsdlGenerator(
101: path, saName, endPoint);
102: generator.writeToFile();
103: } else {
104: AbstractWsdlGenaretor generator = getWsdlGenerator(
105: path, saName, endPoint);
106: generator.writeToFile();
107: }
108:
109: //This generatio is tranfered to the Wizard
110: // if ("consumer".equals(role) ) {
111: // //writePublicWsdlFile(path, saName, endPoint);
112: //
113: // Path auxPath = new Path(path);
114: // auxPath=(Path)auxPath.removeLastSegments(2);
115: // auxPath=(Path)auxPath.append("wsdl").append(getName());
116: //
117: // HttpDefaultPublicWsdlGenerator.newPublicWsdl(auxPath.toString(),
118: // saName, getName(), this.getComponentType(), endPoint);
119: // }
120: }
121: }
122:
123: @Override
124: public void validateBase(List<String> list) {
125: super .validateBase(list);
126: for (int i = 0; i < getEndPointList().size(); i++) {
127: EndPoint endPoint = getEndPointList().get(i);
128: if (endPoint.getName() == null
129: || "".equals(endPoint.getName())) {
130: list.add(new Message(
131: Messages.FLOWEDITOR_MISSING_ENDPOINTNAME,
132: getName()).getMessage());
133: }
134:
135: if (endPoint.getSettings().getProperty(
136: PropertiesKey.HTTP_LOCATIONURL) == null
137: || "".equals(endPoint.getSettings().getProperty(
138: PropertiesKey.HTTP_LOCATIONURL))) {
139: list.add(new Message(
140: Messages.HTTPCOMPONENT_MISSING_LOCATIONURL,
141: getName()).getMessage());
142: }
143: }
144: }
145:
146: // Bug88:
147: // In component flow editor wizards, we need to implement the following
148: // rules:
149: // - the UseCCSL default to be "true"
150: // - Is using HTTP as sever and Enable Soap is "true", the UseCCSL needs to
151: // be
152: // "true".
153: // - Take out the "AddRecord" and "StripRecord" from the wizard. (in the
154: // properties view, they should be "false" for all components except HTTP.
155: // They
156: // should be "false" for HTTP server with SOAP enabled and "true" for all
157: // other
158: // HTTP.
159: //
160: // In the properties view, the useSendMessage should always be "false"
161: // except it
162: // is HTTP server with SOAP enabled.
163: /*
164: * public void validateCCSL(List<String> list) { for (int i = 0; i <
165: * getEndPointList().size(); i++) { EndPoint endPoint =
166: * getEndPointList().get(i); String prefix=PropertiesKey.CCSL;
167: *
168: * if (endPoint.isConumer() &&
169: * endPoint.getSettings().getProperty(PropertiesKey.HTTP_SOAP_ENABLE).equals("true")) {
170: * if(!endPoint.getSettings().getProperty(PropertiesKey.USECCSL).equals("true")){
171: * list.add(new Message(
172: * Messages.HTTP_PROVIDER_USECCSL,getName()).getMessage()); }
173: * if(!(endPoint.getSettings().getProperty(prefix+PropertiesKey.CCSL_ADDRECORD).equals("false") &&
174: * endPoint.getSettings().getProperty(prefix+PropertiesKey.CCSL_STRIPRECORD).equals("false")) ){
175: * list.add(new Message(
176: * Messages.HTTP_PROVIDER_ADDRECORD_STRIPRECORD,getName()).getMessage()); }
177: * if(!endPoint.getSettings().getProperty(prefix+PropertiesKey.CCSL_USESENDMESSAGE).equals("true") ){
178: * list.add(new Message(
179: * Messages.HTTP_PROVIDER_USESENDMESSAGE,getName()).getMessage()); } } else
180: * if(endPoint.getSettings().getProperty(PropertiesKey.USECCSL).equals("true")){
181: * if(!(endPoint.getSettings().getProperty(prefix+PropertiesKey.CCSL_ADDRECORD).equals("true") &&
182: * endPoint.getSettings().getProperty(prefix+PropertiesKey.CCSL_STRIPRECORD).equals("true")) ){
183: * list.add(new Message(
184: * Messages.HTTP_OTHERS_ADDRECORD_STRIPRECORD,getName()).getMessage()); }
185: * if(!endPoint.getSettings().getProperty(prefix+PropertiesKey.CCSL_USESENDMESSAGE).equals("false") ){
186: * list.add(new Message(
187: * Messages.HTTP_OTHERS_USESENDMESSAGE,getName()).getMessage()); } } } }
188: */
189: @Override
190: public void validateCCSL(java.util.List<String> list) {
191: for (int i = 0; i < getEndPointList().size(); i++) {
192: EndPoint endPoint = getEndPointList().get(i);
193: String prefix = PropertiesKey.CCSL;
194: if (endPoint.getSettings().getProperty(
195: PropertiesKey.USECCSL) != null
196: && endPoint.getSettings().getProperty(
197: PropertiesKey.USECCSL).equals("true")) {
198: if (endPoint.getSettings().getProperty(
199: prefix + PropertiesKey.CCSL_ADDRECORD).equals(
200: "true")
201: || endPoint
202: .getSettings()
203: .getProperty(
204: prefix
205: + PropertiesKey.CCSL_STRIPRECORD)
206: .equals("true")
207: || endPoint
208: .getSettings()
209: .getProperty(
210: prefix
211: + PropertiesKey.CCSL_USESENDMESSAGE)
212: .equals("true")) {
213: list.add(new Message(Messages.COMPONENT_WRONG_CCSL,
214: getName()).getMessage());
215: }
216:
217: }
218: }
219: }
220:
221: @Override
222: protected AbstractWsdlGenaretor getWsdlGenerator(String path,
223: String saName, EndPoint ep) throws WSDLException {
224: return new HttpWsdlGenerator(path, saName, getName(), this
225: .getComponentType(), ep);
226: }
227: }
|