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.ui.componentflow.componentFlowEditor.diagram.wizards;
025:
026: import java.io.File;
027: import java.io.FileInputStream;
028: import java.io.FileOutputStream;
029: import java.io.InputStream;
030: import java.io.OutputStream;
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.Iterator;
034: import java.util.Map;
035:
036: import org.eclipse.core.resources.ResourcesPlugin;
037: import org.eclipse.core.runtime.Path;
038: import org.eclipse.jface.wizard.IWizardPage;
039: import org.eclipse.swt.SWT;
040: import org.eclipse.swt.events.ModifyEvent;
041: import org.eclipse.swt.events.ModifyListener;
042: import org.eclipse.swt.events.SelectionAdapter;
043: import org.eclipse.swt.events.SelectionEvent;
044: import org.eclipse.swt.layout.GridData;
045: import org.eclipse.swt.layout.GridLayout;
046: import org.eclipse.swt.widgets.Button;
047: import org.eclipse.swt.widgets.Combo;
048: import org.eclipse.swt.widgets.Composite;
049: import org.eclipse.swt.widgets.Group;
050: import org.eclipse.swt.widgets.Label;
051: import org.eclipse.swt.widgets.Text;
052: import org.eclipse.ui.PlatformUI;
053:
054: import com.bostechcorp.cbesb.common.i18n.I18N;
055: import com.bostechcorp.cbesb.common.i18n.Messages;
056: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
057: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
058: import com.bostechcorp.cbesb.common.util.project.ProjectUtil;
059: import com.bostechcorp.cbesb.common.wsdl.PortInfo;
060: import com.bostechcorp.cbesb.common.wsdl.ServiceInfo;
061: import com.bostechcorp.cbesb.common.wsdl.WsdlInfo;
062: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.AttachmentModeType;
063: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HttpProvider;
064: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.SSL;
065: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.SSLMode;
066: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
067: import com.bostechcorp.cbesb.ui.util.browser.BaseFileBrowser;
068:
069: public class HttpPropertyWizardPageClientProperty extends
070: PropertyWizardPage {
071:
072: private Button authAdvancedSettingButton;
073: private Text timeOutText;
074: private Combo attachmentModeCombo;
075: private Combo defaultOperationCombo;
076: private Combo comboPort;
077:
078: private Combo comboService;
079:
080: private Text textImportedWsdlFiles;
081:
082: private Combo comboSoapEnable;
083:
084: private Text textLocationURI;
085:
086: private Button browseButton;
087:
088: private WsdlInfo wsdl;
089:
090: private String filePath;
091:
092: private String defaultService = "";
093:
094: private String defaultPort = "";
095:
096: private String defaultOperation = "";
097:
098: private Button sslButton;
099:
100: private Button proxyButton;
101: private Button proxyAdvancedSettingsButton;
102:
103: private Button advancedSettingButton;
104:
105: public Map<String, String> proxyMap = new HashMap<String, String>();
106:
107: public Map<String, String> sslMap = new HashMap<String, String>();
108:
109: public Map<String, String> authenticationMap = new HashMap<String, String>();
110:
111: private boolean updateOperation = false;
112: private Button authenticationButton;
113:
114: protected HttpPropertyWizardPageClientProperty(String pageName) {
115: super (pageName);
116: setTitle(I18N.getString(Messages.HTTP_CLIENT_TITLE));// "Choose
117: setDescription(I18N.getString(Messages.WIZARD_ENTER_TIP));
118:
119: /*
120: * setTitle(I18N.getString(Messages.IDE_CHOOSE_TRN_FILE));// "Choose
121: * setDescription(I18N.getString(Messages.IDE_CHOOSE_TRNFILE_DESC));//
122: * "Choose
123: */
124:
125: }
126:
127: public void createControl(Composite parent) {
128:
129: final Composite topLevel = new Composite(parent, SWT.NONE);
130: final GridLayout gridLayout_1 = new GridLayout();
131: gridLayout_1.numColumns = 2;
132: topLevel.setLayout(gridLayout_1);
133: topLevel.setLayoutData(new GridData(
134: GridData.VERTICAL_ALIGN_FILL
135: | GridData.HORIZONTAL_ALIGN_FILL));
136: topLevel.setFont(parent.getFont());
137: this .setControl(topLevel);
138: Group soapGroup;
139:
140: final Label labelSource = new Label(topLevel, SWT.NONE);
141: labelSource.setText(I18N.getString(Messages.HTTP_URL));
142:
143: textLocationURI = new Text(topLevel, SWT.BORDER);
144: textLocationURI.setLayoutData(new GridData(SWT.FILL,
145: SWT.CENTER, true, false));
146: textLocationURI.addModifyListener(new ModifyListener() {
147: public void modifyText(ModifyEvent e) {
148: dialogChanged();
149:
150: }
151: });
152:
153: final Label timeOutLabel = new Label(topLevel, SWT.NONE);
154: timeOutLabel.setText(I18N.getString(Messages.TIME_OUT));
155:
156: timeOutText = new Text(topLevel, SWT.BORDER);
157: timeOutText.setText("30000");
158: timeOutText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
159: true, false));
160: timeOutText.addModifyListener(new ModifyListener() {
161: public void modifyText(final ModifyEvent e) {
162: dialogChanged();
163: }
164: });
165: soapGroup = new Group(topLevel, SWT.NONE);
166: final GridData gridData_2 = new GridData(SWT.FILL, SWT.CENTER,
167: false, false, 2, 1);
168: gridData_2.widthHint = 500;
169: soapGroup.setLayoutData(gridData_2);
170: final GridLayout gridLayout = new GridLayout();
171: gridLayout.numColumns = 3;
172: soapGroup.setLayout(gridLayout);
173: soapGroup.setText(I18N.getString(Messages.HTTP_SOAP));
174:
175: final Label unableLabel = new Label(soapGroup, SWT.NONE);
176: unableLabel.setText(I18N.getString(Messages.HTTP_SOAP_ENABLE));
177:
178: comboSoapEnable = new Combo(soapGroup, SWT.READ_ONLY);
179: comboSoapEnable.setItems(new String[] { "true", "false" });
180: comboSoapEnable.setLayoutData(new GridData(SWT.FILL,
181: SWT.CENTER, false, false, 2, 1));
182: if (!this .getWizard().isUpdateOperation())
183: comboSoapEnable.setText("false");
184: comboSoapEnable.addModifyListener(new ModifyListener() {
185:
186: public void modifyText(ModifyEvent e) {
187:
188: if (comboSoapEnable.getText().equals("true")) {
189: textImportedWsdlFiles.setEnabled(true);
190: textLocationURI.setEnabled(false);
191: browseButton.setEnabled(true);
192: attachmentModeCombo.setEnabled(true);
193: if (!comboPort.getText().equals("") && wsdl != null
194: && !comboService.getText().equals("")) {
195: String locationURL = wsdl.getServiceInfo(
196: comboService.getText()).getPort(
197: comboPort.getText()).getLocationURI();
198: textLocationURI.setText(locationURL);
199: }
200:
201: } else {
202: textImportedWsdlFiles.setEnabled(false);
203: browseButton.setEnabled(false);
204: attachmentModeCombo.setEnabled(false);
205: textLocationURI.setEnabled(true);
206: }
207: dialogChanged();
208: }
209:
210: });
211:
212: final Label importedWsdlFilesLabel = new Label(soapGroup,
213: SWT.NONE);
214: importedWsdlFilesLabel.setText(I18N
215: .getString(Messages.HTTP_IMPORTED_WSDL_FILES));
216:
217: textImportedWsdlFiles = new Text(soapGroup, SWT.READ_ONLY
218: | SWT.BORDER);
219: final GridData gridData_1 = new GridData(SWT.FILL, SWT.CENTER,
220: false, false);
221: gridData_1.widthHint = 291;
222: textImportedWsdlFiles.setLayoutData(gridData_1);
223: textImportedWsdlFiles.setEnabled(false);
224: textImportedWsdlFiles.addModifyListener(new ModifyListener() {
225: public void modifyText(ModifyEvent e) {
226:
227: importWsdlFilesChange();
228: dialogChanged();
229:
230: }
231: });
232:
233: browseButton = new Button(soapGroup, SWT.NONE);
234: browseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
235: true, false));
236: browseButton.setText(I18N.getString(Messages.WIZARD_BROWSE));
237: browseButton.setEnabled(false);
238: browseButton.addSelectionListener(new SelectionAdapter() {
239: public void widgetSelected(final SelectionEvent e) {
240:
241: String projectName = ProjectUtil.getCurProjectName();
242: BaseFileBrowser browser = new BaseFileBrowser(
243: ComponentFlowEditorDiagramEditorPlugin
244: .getInstance(), topLevel.getShell(),
245: textImportedWsdlFiles, projectName, ".wsdl",
246: "wsdl", I18N
247: .getString(Messages.SELECT_WSDL_FILE));
248: browser.open();
249: }
250: });
251:
252: final Label label = new Label(soapGroup, SWT.NONE);
253: label.setText(I18N.getString(Messages.HTTP_WSDL_SERVICES));
254:
255: comboService = new Combo(soapGroup, SWT.READ_ONLY);
256: comboService.addModifyListener(new ModifyListener() {
257: public void modifyText(final ModifyEvent e) {
258: if (comboSoapEnable.getText().equals("true")) {
259: serviceChange();
260: dialogChanged();
261: }
262: }
263: });
264: final GridData gridData = new GridData(SWT.FILL, SWT.CENTER,
265: true, false, 2, 1);
266: gridData.widthHint = 390;
267: comboService.setLayoutData(gridData);
268:
269: final Label label_1 = new Label(soapGroup, SWT.NONE);
270: label_1.setText(I18N.getString(Messages.HTTP_WSDL_PORT));
271:
272: comboPort = new Combo(soapGroup, SWT.READ_ONLY);
273: comboPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
274: true, false, 2, 1));
275: comboPort.addModifyListener(new ModifyListener() {
276: public void modifyText(final ModifyEvent e) {
277: if (comboSoapEnable.getText().equals("false"))
278: return;
279: if (!comboPort.getText().equals("")) {
280: String locationURL = wsdl.getServiceInfo(
281: comboService.getText()).getPort(
282: comboPort.getText()).getLocationURI();
283: if (locationURL != null)
284: textLocationURI.setText(locationURL);
285: portChange();
286: }
287: dialogChanged();
288: }
289: });
290:
291: final Label defaultOperationLabel = new Label(soapGroup,
292: SWT.NONE);
293: defaultOperationLabel.setText(I18N
294: .getString(Messages.DEFAULT_OPERATION));
295:
296: defaultOperationCombo = new Combo(soapGroup, SWT.READ_ONLY);
297: defaultOperationCombo.setLayoutData(new GridData(SWT.FILL,
298: SWT.CENTER, true, false, 2, 1));
299:
300: final Label attachmentModeLabel = new Label(soapGroup, SWT.NONE);
301: attachmentModeLabel.setLayoutData(new GridData());
302: attachmentModeLabel.setText(I18N
303: .getString(Messages.ATTACHMENT_MODE));
304:
305: attachmentModeCombo = new Combo(soapGroup, SWT.READ_ONLY);
306: attachmentModeCombo.setItems(new String[] {
307: AttachmentModeType.NONE_LITERAL.getLiteral(),
308: AttachmentModeType.SW_A_LITERAL.getLiteral(),
309: AttachmentModeType.MTOM_LITERAL.getLiteral() });
310: attachmentModeCombo.select(0);
311: attachmentModeCombo.setLayoutData(new GridData(SWT.FILL,
312: SWT.CENTER, true, false, 2, 1));
313:
314: authenticationButton = new Button(topLevel, SWT.CHECK);
315: authenticationButton.setText("Authentication");
316: authenticationButton
317: .addSelectionListener(new SelectionAdapter() {
318: public void widgetSelected(SelectionEvent e) {
319: if (authenticationButton.getSelection()) {
320: authAdvancedSettingButton.setEnabled(true);
321: } else
322: authAdvancedSettingButton.setEnabled(false);
323: }
324: });
325:
326: authAdvancedSettingButton = new Button(topLevel, SWT.NONE);
327: authAdvancedSettingButton.setEnabled(false);
328: authAdvancedSettingButton.setText("Advanced Settings");
329: authAdvancedSettingButton
330: .addSelectionListener(new SelectionAdapter() {
331: public void widgetSelected(SelectionEvent e) {
332: HttpAuthenticationDialog dialog = new HttpAuthenticationDialog(
333: PlatformUI.getWorkbench()
334: .getActiveWorkbenchWindow()
335: .getShell(), authenticationMap,
336: updateOperation);
337: dialog.open();
338: }
339: });
340:
341: proxyButton = new Button(topLevel, SWT.CHECK);
342: proxyButton.addSelectionListener(new SelectionAdapter() {
343: public void widgetSelected(final SelectionEvent e) {
344: if (proxyButton.getSelection()) {
345: proxyAdvancedSettingsButton.setEnabled(true);
346: } else {
347: proxyAdvancedSettingsButton.setEnabled(false);
348: }
349: dialogChanged();
350: }
351: });
352: proxyButton.setText(I18N.getString(Messages.PROXY));
353:
354: proxyAdvancedSettingsButton = new Button(topLevel, SWT.NONE);
355: proxyAdvancedSettingsButton.setEnabled(false);
356: proxyAdvancedSettingsButton.setLayoutData(new GridData(103,
357: SWT.DEFAULT));
358: proxyAdvancedSettingsButton.setText(I18N
359: .getString(Messages.TCPIP_ADVANCED_SETTINGS));
360:
361: proxyAdvancedSettingsButton
362: .addSelectionListener(new SelectionAdapter() {
363: public void widgetSelected(SelectionEvent e) {
364: HttpProxyWizard dialog = new HttpProxyWizard(
365: PlatformUI.getWorkbench()
366: .getActiveWorkbenchWindow()
367: .getShell(), proxyMap,
368: updateOperation);
369: dialog.open();
370: }
371: });
372:
373: sslButton = new Button(topLevel, SWT.CHECK);
374: sslButton.addSelectionListener(new SelectionAdapter() {
375: public void widgetSelected(SelectionEvent e) {
376: if (sslButton.getSelection()) {
377: advancedSettingButton.setEnabled(true);
378: } else
379: advancedSettingButton.setEnabled(false);
380: dialogChanged();
381: }
382: });
383: sslButton.setText(I18N.getString(Messages.TCPIP_SSL));
384:
385: advancedSettingButton = new Button(topLevel, SWT.NONE);
386: advancedSettingButton.setEnabled(false);
387: advancedSettingButton.setText(I18N
388: .getString(Messages.TCPIP_ADVANCED_SETTINGS));
389: advancedSettingButton
390: .addSelectionListener(new SelectionAdapter() {
391: public void widgetSelected(SelectionEvent e) {
392: TCPIPClientSSLSettingsWizardPage dialog = new TCPIPClientSSLSettingsWizardPage(
393: PlatformUI.getWorkbench()
394: .getActiveWorkbenchWindow()
395: .getShell(), sslMap,
396: updateOperation);
397: dialog.open();
398: }
399: });
400:
401: if (this .getWizard().isUpdateOperation()) {
402: updateOperation = true;
403: modelsToControl();
404: }
405: dialogChanged();
406: }
407:
408: private void dialogChanged() {
409: if (WizardUtil.whetherUseValidation == false) {
410: setPageComplete(true);
411: return;
412: }
413: if (comboSoapEnable.getText().equals("true")) {
414: if (textImportedWsdlFiles.getText().equals("")) {
415: updateStatus(I18N
416: .getString(Messages.HTTP_ERROR_WSDL_REQUIRE));
417: setPageComplete(false);
418: return;
419: }
420: if (comboService.getText().equals("")) {
421: updateStatus(I18N
422: .getString(Messages.HTTP_ERROR_WSDL_SERVICE_REQUIRE));
423: setPageComplete(false);
424: return;
425: }
426: if (comboPort.getText().equals("")) {
427: updateStatus(I18N
428: .getString(Messages.HTTP_ERROR_WSDL_PORT_REQUIRE));
429: setPageComplete(false);
430: return;
431: }
432: }
433: if (textLocationURI.getText().equals("")) {
434: updateStatus(I18N
435: .getString(Messages.HTTP_ERROR_LOCATIONURL_REQUIRE));
436: setPageComplete(false);
437: return;
438: }
439:
440: if (timeOutText.getText().equals("")) {
441: updateStatus(I18N.getString(Messages.TIME_OUT_REQUIRED));
442: setPageComplete(false);
443: return;
444: } else if (!timeOutText.getText().equals("")) {
445: if (!WizardUtil.isNumber(timeOutText.getText())) {
446: updateStatus(I18N.getString(Messages.TIME_OUT_NUMBER));
447: setPageComplete(false);
448: return;
449: }
450: }
451:
452: setPageComplete(true);
453: updateStatus(null);
454: }
455:
456: private void updateStatus(String message) {
457: setErrorMessage(message);
458: // this.getWizard().canFinish();
459: }
460:
461: @Override
462: public void controlToModels() {
463:
464: HttpPropertyWizard httpWizard = (HttpPropertyWizard) this
465: .getWizard();
466:
467: if (httpWizard.getModels() == null)
468: return;
469: try {
470: HttpProvider httpProvider = httpWizard.getModels()
471: .getHttpProvider();
472: httpProvider.setLocationUrl(textLocationURI.getText());
473: httpProvider.setTimeout(Integer.parseInt(timeOutText
474: .getText()));
475:
476: if (comboSoapEnable.getText().equals("true")) {
477: httpProvider.setSoapEnabled(true);
478: httpProvider.setImportedWSDL(textImportedWsdlFiles
479: .getText()/*importedWsdl()*/);
480: httpProvider.setService(comboService.getText());
481: httpProvider.setPort(comboPort.getText());
482: httpProvider
483: .setDefaultOperation( /*defaultOperationToModel()*/defaultOperationCombo
484: .getText());
485: httpProvider.setAttachmentMode(AttachmentModeType
486: .get(attachmentModeCombo.getSelectionIndex()));
487:
488: } else if (comboSoapEnable.getText().equals("false")) {
489: httpProvider.setSoapEnabled(false);
490: httpProvider
491: .setAttachmentMode(AttachmentModeType.NONE_LITERAL);
492: }
493:
494: if (authenticationButton.getSelection()) {
495: httpProvider.setBasicAuthUser(authenticationMap
496: .get("user"));
497: httpProvider.setBasicAuthPassword(authenticationMap
498: .get("password"));
499: }
500:
501: if (proxyButton.getSelection()) {
502: httpProvider.setProxyHost(proxyMap.get("host"));
503: httpProvider.setProxyUser(proxyMap.get("user"));
504: httpProvider.setProxyPassword(proxyMap.get("password"));
505: httpProvider.setProxyPort(proxyMap.get("port"));
506:
507: } else {
508: httpProvider.setProxyHost(null);
509: httpProvider.setProxyUser(null);
510: httpProvider.setProxyPassword(null);
511: httpProvider.setProxyPort(null);
512:
513: }
514:
515: if (sslButton.getSelection()) {
516: httpProvider.setUseSsl(true);
517: SSL sslModel = httpProvider.getSSL();
518: sslModel.setSslProtocol(SSLMode.get(sslMap
519: .get("sslProtocol")));
520: sslModel.setAllowAnonymous(Boolean.parseBoolean(sslMap
521: .get("allowAnonymous")));
522: sslModel.setUsePrivateKey(Boolean.parseBoolean(sslMap
523: .get("usePrivateKey")));
524: sslModel.setKeyStoreFile(sslMap.get("keyStoreFile"));
525: sslModel.setKeyStorePassword(sslMap
526: .get("keyStorePassword"));
527: sslModel.setAuthenticatePeer(new Boolean(sslMap.get(
528: "authenticateServer").toString()));
529: sslModel.setUseDefaultTrustStore(Boolean
530: .parseBoolean(sslMap
531: .get("useDefaultTrustStore")));
532: sslModel
533: .setTrustStoreFile(sslMap.get("trustStoreFile"));
534: sslModel.setTrustStorePassword(sslMap
535: .get("trustStorePassword"));
536: } else {
537: httpProvider.setUseSsl(false);
538: }
539:
540: } catch (Exception e) {
541: e.printStackTrace();
542: }
543: }
544:
545: private String importedWsdl() throws Exception {
546: String impWSdl = textImportedWsdlFiles.getText();
547: String fileName = new Path(EsbPathHelper
548: .getFullPathForDef(impWSdl)).lastSegment();
549: return "publicWsdl/" + fileName;
550: }
551:
552: /**
553: * @return namespace:operationName format to be set to the model
554: */
555: private String defaultOperationToModel() {
556:
557: String dop = defaultOperationCombo.getText();
558: String ns = wsdl.getWsdlDefinition().getTargetNamespace();
559: return ns + ":" + dop;
560: }
561:
562: public IWizardPage getNextPage() {
563: if (this .getWizard().getMainPage().isConsumer()) {
564:
565: return getWizard().getPage("ServerProperty");
566: }
567: if (this .getWizard().getMainPage().isUseCCSL()) {
568:
569: return getWizard().getCcslProviderPage();
570: }
571:
572: return null;
573: }
574:
575: @Override
576: public void modelsToControl() {
577:
578: HttpPropertyWizard httpWizard = (HttpPropertyWizard) this
579: .getWizard();
580: if (!httpWizard.isUpdateOperation())
581: return;
582: try {
583:
584: HttpProvider httpProvider = httpWizard.getModels()
585: .getHttpProvider();
586: if (httpProvider.isSoapEnabled() == true) {
587: comboSoapEnable.setText("true");
588: // ArrayList<String> list = getValues(httpProvider
589: // .getImportedWSDL(), httpProvider.getLocationUrl(),/* httpProvider.getDefaultOperation() */
590: // defaultOperationFromModel(httpProvider
591: // .getDefaultOperation()));
592: // if (list != null && list.size() == 2) {
593: defaultService = httpProvider.getService();
594: defaultPort = httpProvider.getPort();
595: defaultOperation = httpProvider.getDefaultOperation();
596: if (defaultOperation.indexOf(":") > 0) {
597: defaultOperation = defaultOperation
598: .substring(defaultOperation
599: .lastIndexOf(":") + 1);
600: }
601: // }
602:
603: if (httpProvider.getImportedWSDL() != null)
604: textImportedWsdlFiles.setText(httpProvider
605: .getImportedWSDL());
606:
607: textImportedWsdlFiles.setEnabled(true);
608: attachmentModeCombo.setText(httpProvider
609: .getAttachmentMode().getLiteral());
610: browseButton.setEnabled(true);
611: attachmentModeCombo.setEnabled(true);
612:
613: } else if (httpProvider.isSoapEnabled() == false) {
614: comboSoapEnable.setText("false");
615: textImportedWsdlFiles.setEnabled(false);
616: browseButton.setEnabled(false);
617: attachmentModeCombo.setEnabled(false);
618:
619: }
620:
621: if (httpProvider.getLocationUrl() != null)
622: textLocationURI.setText(httpProvider.getLocationUrl());
623: else
624: textLocationURI.setText("");
625:
626: timeOutText.setText(String.valueOf(httpProvider
627: .getTimeout()));
628:
629: authenticationMap.put("user", httpProvider
630: .getBasicAuthUser());
631: authenticationMap.put("password", httpProvider
632: .getBasicAuthPassword());
633:
634: if (httpProvider.getBasicAuthUser() != null
635: && !httpProvider.getBasicAuthUser().equals("")) {
636: authAdvancedSettingButton.setEnabled(true);
637: authenticationButton.setSelection(true);
638: }
639:
640: if (comboService.getItemCount() != 0) {
641: if (defaultService.equals(""))
642: comboService.select(0);
643: else
644: comboService.select(comboService
645: .indexOf(defaultService));
646: }
647:
648: if (comboPort.getItemCount() != 0) {
649: if (defaultPort.equals(""))
650: comboPort.select(0);
651: else
652: comboPort.select(comboPort.indexOf(defaultPort));
653: }
654:
655: if (defaultOperationCombo.getItemCount() != 0) {
656: if (defaultOperation.equals(""))
657: defaultOperationCombo.select(0);
658: else
659: defaultOperationCombo.select(defaultOperationCombo
660: .indexOf(defaultOperation));
661: }
662:
663: defaultService = "";
664: defaultPort = "";
665: defaultOperation = "";
666:
667: proxyMap.put("host", httpProvider.getProxyHost());
668: proxyMap.put("port", httpProvider.getProxyPort());
669: proxyMap.put("user", httpProvider.getProxyUser());
670: proxyMap.put("password", httpProvider.getProxyPassword());
671:
672: if (httpProvider.getProxyHost() != null
673: && !httpProvider.getProxyHost().equals("")) {
674: proxyButton.setSelection(true);
675: proxyAdvancedSettingsButton.setEnabled(true);
676: }
677:
678: sslButton.setSelection(httpProvider.isUseSsl());
679: advancedSettingButton.setEnabled(httpProvider.isUseSsl());
680:
681: SSL sslModel = httpProvider.getSSL();
682: sslMap.put("sslProtocol", sslModel.getSslProtocol()
683: .getLiteral());
684: sslMap.put("allowAnonymous", Boolean.toString(sslModel
685: .isAllowAnonymous()));
686: sslMap.put("usePrivateKey", Boolean.toString(sslModel
687: .isUsePrivateKey()));
688: sslMap.put("keyStoreFile", sslModel.getKeyStoreFile());
689: sslMap.put("keyStorePassword", sslModel
690: .getKeyStorePassword());
691: sslMap.put("authenticateServer", new Boolean(sslModel
692: .isAuthenticatePeer()).toString());
693: sslMap.put("useDefaultTrustStore", Boolean
694: .toString(sslModel.isUseDefaultTrustStore()));
695: sslMap.put("trustStoreFile", sslModel.getTrustStoreFile());
696: sslMap.put("trustStorePassword", sslModel
697: .getTrustStorePassword());
698: } catch (Exception e) {
699: e.printStackTrace();
700: }
701: }
702:
703: /**
704: * @param string the namespace:operationNAme format
705: * @return only operation Name
706: */
707: private String defaultOperationFromModel(String string) {
708: return string.substring(string.lastIndexOf(":") + 1, string
709: .length());
710: }
711:
712: public static void copyFile(File oldFile, String newPath) {
713: try {
714: int byteRead = 0;
715: int byteSum = 0;
716: if (oldFile.exists()) {
717: InputStream inputStream = new FileInputStream(oldFile);
718: File newFolder = new File(newPath);
719: newFolder.mkdir();
720: String newFilename = newPath + File.separator
721: + oldFile.getName();
722: OutputStream outputStream = new FileOutputStream(
723: newFilename);
724: byte[] buffer = new byte[1024];
725: while ((byteRead = inputStream.read(buffer)) != -1) {
726: byteSum += byteRead;
727: outputStream.write(buffer, 0, byteRead);
728: }
729: outputStream.close();
730: inputStream.close();
731: }
732: } catch (Exception e) {
733: // throw new Exception(new
734: // Message(Messages.FILE_COPY_ERROR).getMessage());
735: e.printStackTrace();
736: }
737: }
738:
739: protected void importWsdlFilesChange() {
740:
741: if (textImportedWsdlFiles.getText().equals(""))
742: return;
743: if (comboService.getItemCount() != 0)
744: comboService.removeAll();
745: String textString = textImportedWsdlFiles.getText();
746:
747: wsdl = null;
748:
749: try {
750: filePath = EsbPathHelper.getFullPathForDef(MacroUtil
751: .resolveBuiltinMacro(textString, ProjectUtil
752: .getCurProjectName()));
753: File file = new File(filePath);
754: wsdl = WsdlInfo.load(file);
755: } catch (Exception e) {
756: e.printStackTrace(System.err);
757: return;
758: }
759: try {
760: wsdl.getServices().size();
761: } catch (Exception e) {
762: e.printStackTrace(System.err);
763: return;
764: }
765:
766: try {
767: for (Iterator serviceIter = wsdl.getServices().iterator(); serviceIter
768: .hasNext();) {
769: ServiceInfo service = (ServiceInfo) serviceIter.next();
770: comboService.add(service.getName());
771: for (Iterator portIterator = service.getPorts()
772: .iterator(); portIterator.hasNext();) {
773: portIterator.next();
774: }
775:
776: }
777:
778: } catch (Exception e) {
779: e.printStackTrace(System.err);
780: return;
781: }
782:
783: if (comboService.getItemCount() != 0) {
784: if (defaultService == null || defaultService.equals(""))
785: comboService.select(0);
786: else
787: comboService.select(comboService
788: .indexOf(defaultService));
789: }
790: }
791:
792: private void serviceChange() {
793: String cur_service = comboService.getText();
794: if (!cur_service.equals("")) {
795: if (comboPort.getItemCount() != 0)
796: comboPort.removeAll();
797: if (defaultOperationCombo.getItemCount() != 0)
798: defaultOperationCombo.removeAll();
799: try {
800: try {
801: wsdl.getServices().size();
802: } catch (Exception e) {
803: e.printStackTrace(System.err);
804: return;
805: }
806:
807: for (Iterator serviceIter = wsdl.getServices()
808: .iterator(); serviceIter.hasNext();) {
809: ServiceInfo service = (ServiceInfo) serviceIter
810: .next();
811: if (service.getName().equals(cur_service)) {
812: for (Iterator portIterator = service.getPorts()
813: .iterator(); portIterator.hasNext();) {
814: PortInfo port = (PortInfo) portIterator
815: .next();
816: comboPort.add(port.getName());
817:
818: }
819: }
820:
821: }
822:
823: } catch (Exception e) {
824: e.printStackTrace(System.err);
825: return;
826: }
827:
828: if (comboPort.getItemCount() != 0) {
829: if (defaultPort == null || defaultPort.equals(""))
830: comboPort.select(0);
831: else
832: comboPort.select(comboPort.indexOf(defaultPort));
833: }
834:
835: if (defaultOperationCombo.getItemCount() != 0) {
836: if (defaultOperation.equals(""))
837: defaultOperationCombo.select(0);
838: else
839: defaultOperationCombo.select(defaultOperationCombo
840: .indexOf(defaultOperation));
841: }
842: }
843: }
844:
845: private void portChange() {
846:
847: if (defaultOperationCombo.getItemCount() != 0)
848: defaultOperationCombo.removeAll();
849:
850: try {
851:
852: PortInfo port = wsdl.getServiceInfo(comboService.getText())
853: .getPort(comboPort.getText());
854:
855: for (int i = 0; i < port.getOperationNames().length; i++) {
856: defaultOperationCombo.add(port.getOperationNames()[i]);
857:
858: }
859:
860: } catch (Exception e) {
861: e.printStackTrace(System.err);
862: return;
863: }
864:
865: if (defaultOperationCombo.getItemCount() != 0) {
866: if (defaultOperation.equals(""))
867: defaultOperationCombo.select(0);
868: else
869: defaultOperationCombo.select(defaultOperationCombo
870: .indexOf(defaultOperation));
871: }
872:
873: }
874:
875: public ArrayList<String> getValues(String fileName, String url,
876: String defaultOperaiton) {
877:
878: if (fileName.equals(""))
879: return null;
880: ArrayList<String> list = new ArrayList<String>();
881: filePath = ResourcesPlugin.getWorkspace().getRoot().getProject(
882: fileName.split("::")[0]).getLocation().toOSString()
883: .concat("/" + fileName.split("::")[1]);
884: File file = new File(filePath);
885: WsdlInfo newWsdl = null;
886: String serviceName = "";
887: String portName = "";
888: String operatioName = "";
889: try {
890: newWsdl = WsdlInfo.load(file);
891: } catch (Exception e) {
892: e.printStackTrace();
893: }
894:
895: try {
896: newWsdl.getServices().size();
897: } catch (Exception e) {
898: e.printStackTrace();
899: return null;
900: }
901:
902: try {
903: for (Iterator serviceIter = newWsdl.getServices()
904: .iterator(); serviceIter.hasNext();) {
905: ServiceInfo service = (ServiceInfo) serviceIter.next();
906: comboService.add(service.getName());
907: serviceName = service.getName();
908: for (Iterator portIterator = service.getPorts()
909: .iterator(); portIterator.hasNext();) {
910: PortInfo port = (PortInfo) portIterator.next();
911: if (port.getLocationURI().equals(url)) {
912: portName = port.getName();
913: list.add(serviceName);
914: list.add(portName);
915: for (String operation : port
916: .getOperationNames()) {
917: if (operation.equals(defaultOperaiton)) {
918: operatioName = operation;
919: list.add(operatioName);
920: }
921: }
922: return list;
923: }
924:
925: }
926:
927: }
928:
929: } catch (Exception e) {
930: e.printStackTrace(System.err);
931: return null;
932: }
933: return null;
934:
935: }
936:
937: }
|