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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.command.common;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.ws.internal.consumption.plugin.WebServiceConsumptionPlugin;
import org.eclipse.jst.ws.internal.data.TypeRuntimeServer;
import org.eclipse.wst.command.internal.provisional.env.core.EnvironmentalOperation;
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment;
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils;
import org.eclipse.wst.command.internal.provisional.env.core.common.StatusUtils;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.ServerPort;
import org.eclipse.wst.server.core.internal.IMonitoredServerPort;
import org.eclipse.wst.server.core.internal.IServerMonitorManager;
import org.eclipse.wst.server.core.internal.ServerMonitorManager;
public class CreateMonitorCommand extends EnvironmentalOperation
{
private static final String WEB_SERVICES = "Web services";
private Boolean monitorService;
private String serviceServerInstanceId;
private Integer monitoredPort;
public CreateMonitorCommand() {
}
public IStatus execute( IProgressMonitor monitor, IAdaptable adaptable )
{
Environment env = getEnvironment();
if (monitorService != null && monitorService.booleanValue()) {
IServer server = ServerCore.findServer(serviceServerInstanceId);
if (server != null) {
// IMonitorableServer monitorableServer = (IMonitorableServer)
// serverDelegate;
ServerPort[] ports = server.getServerPorts(null);
ServerPort port = null;
for (int it = 0; it < ports.length; it++) {
ServerPort p = ports[it];
String protocol = p.getProtocol();
if (protocol != null && protocol.trim().toLowerCase().equals("http")) {
port = p;
break;
}
}
if (port != null) {
IServerMonitorManager serverMonitorManager = ServerMonitorManager.getInstance();
IMonitoredServerPort[] monitoredPorts = serverMonitorManager.getMonitoredPorts(server);
for (int it2 = 0; it2 < monitoredPorts.length; it2++) {
IMonitoredServerPort imsPort = monitoredPorts[it2];
if (port.getPort() == imsPort.getServerPort().getPort() && hasContentWebServices(imsPort)) // port
// already
// being
// monitored
{
if (!imsPort.isStarted()) {
try {
serverMonitorManager.startMonitor(imsPort);
}
catch (CoreException ce) {
MessageUtils msgUtils = new MessageUtils(WebServiceConsumptionPlugin.ID + ".plugin", this);
IStatus error = StatusUtils.errorStatus( msgUtils.getMessage("MSG_ERROR_UNABLE_TO_START_MONITOR",
new Object[] { String.valueOf(port.getPort()), server.getName()}), ce);
env.getStatusHandler().reportError(error);
return error;
}
}
monitoredPort = new Integer(imsPort.getMonitorPort());
return Status.OK_STATUS;
}
}
try {
IMonitoredServerPort imsPort = serverMonitorManager.createMonitor(server, port, -1, new String[] { WEB_SERVICES});
serverMonitorManager.startMonitor(imsPort);
monitoredPort = new Integer(imsPort.getMonitorPort());
return Status.OK_STATUS;
}
catch (CoreException ce) {
MessageUtils msgUtils = new MessageUtils(WebServiceConsumptionPlugin.ID + ".plugin", this);
IStatus error = StatusUtils.errorStatus( msgUtils.getMessage("MSG_ERROR_UNABLE_TO_START_MONITOR", new Object[] {
String.valueOf(port.getPort()), server.getName()}), ce);
env.getStatusHandler().reportError(error);
return error;
}
}
else {
MessageUtils msgUtils = new MessageUtils(WebServiceConsumptionPlugin.ID + ".plugin", this);
IStatus info = StatusUtils.infoStatus( msgUtils.getMessage("MSG_INFO_MONITORING_NOT_SUPPORTED",
new Object[] { server.getName()}) );
env.getStatusHandler().reportInfo(info);
return info;
}
}
}
return Status.OK_STATUS;
}
private boolean hasContentWebServices(IMonitoredServerPort imsPort) {
String[] contents = imsPort.getContentTypes();
for (int i = 0; i < contents.length; i++)
if (WEB_SERVICES.equals(contents[i])) return true;
return false;
}
public void setServiceTypeRuntimeServer(TypeRuntimeServer typeRuntimeServer) {
this.serviceServerInstanceId = typeRuntimeServer.getServerInstanceId();
}
public void setServiceServerInstanceId(String serviceServerInstanceId) {
this.serviceServerInstanceId = serviceServerInstanceId;
}
public Integer getMonitoredPort() {
return monitoredPort;
}
public void setMonitorService(Boolean value) {
monitorService = value;
}
}
|