Search in sources :

Example 16 with ServerPort

use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.

the class MonitorDialog method createDialogArea.

/**
 */
protected Control createDialogArea(Composite parent) {
    // create a composite with standard margins and spacing
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    layout.numColumns = 2;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setFont(parent.getFont());
    // WorkbenchHelp.setHelp(composite, ContextIds.TERMINATE_SERVER_DIALOG);
    Label label = new Label(composite, SWT.WRAP);
    label.setText(NLS.bind(Messages.dialogMonitorAddDescription, new String[] { server.getName() }));
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.horizontalSpan = 2;
    data.widthHint = 275;
    label.setLayoutData(data);
    table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    data.heightHint = 100;
    data.horizontalSpan = 2;
    table.setLayoutData(data);
    table.setLinesVisible(true);
    tableViewer = new TableViewer(table);
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    table.setHeaderVisible(true);
    tableLayout.addColumnData(new ColumnWeightData(12, 120, true));
    TableColumn col = new TableColumn(table, SWT.NONE);
    col.setText(Messages.dialogMonitorColumnType);
    tableLayout.addColumnData(new ColumnWeightData(4, 40, true));
    col = new TableColumn(table, SWT.NONE);
    col.setText(Messages.dialogMonitorColumnPort);
    tableViewer.setContentProvider(new PortContentProvider(server));
    tableViewer.setLabelProvider(new PortLabelProvider(server));
    tableViewer.setInput(AbstractTreeContentProvider.ROOT);
    tableViewer.setSorter(new ViewerSorter() {

        public int compare(Viewer viewer, Object e1, Object e2) {
            ServerPort port1 = (ServerPort) e1;
            ServerPort port2 = (ServerPort) e2;
            if (port1.getPort() == port2.getPort())
                return 0;
            else if (port1.getPort() > port2.getPort())
                return 1;
            else
                return -1;
        }
    });
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.dialogMonitorMonitorPort);
    final Text portText = new Text(composite, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 150;
    portText.setLayoutData(data);
    if (monitorPort >= 0)
        portText.setText(monitorPort + "");
    portText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            try {
                monitorPort = Integer.parseInt(portText.getText());
                if (ok != null)
                    ok.setEnabled(true);
            } catch (Exception ex) {
                monitorPort = -1;
                if (ok != null)
                    ok.setEnabled(false);
            }
            portChanged = true;
        }
    });
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.dialogMonitorContentType);
    final Combo combo = new Combo(composite, SWT.READ_ONLY);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 150;
    combo.setLayoutData(data);
    combo.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            int size = combo.getItemCount();
            int sel = combo.getSelectionIndex();
            if (sel == size - 1)
                contentTypes = portContentTypes;
            else
                contentTypes = new String[] { portContentTypes[sel] };
        }
    });
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            port = (ServerPort) getSelection(tableViewer.getSelection());
            if (port == null)
                return;
            if (!portChanged) {
                portText.setText((port.getPort() + 1) + "");
                portChanged = false;
            }
            portContentTypes = port.getContentTypes();
            String[] s = null;
            String all = Messages.dialogMonitorContentTypeAll;
            if (portContentTypes == null || portContentTypes.length == 1) {
                s = new String[] { all };
            } else {
                int size = portContentTypes.length;
                s = new String[size + 1];
                for (int i = 0; i < size; i++) {
                    s[i] = MonitorLabelProvider.getContentTypeString(portContentTypes[i]);
                }
                s[size] = all;
            }
            combo.setItems(s);
            combo.setText(all);
        }
    });
    Dialog.applyDialogFont(composite);
    if (port != null) {
        portChanged = true;
        String[] ct = contentTypes;
        tableViewer.setSelection(new StructuredSelection(port));
        if (ct != null && ct.length > 0)
            combo.setText(MonitorLabelProvider.getContentTypeString(ct[0]));
    } else if (tableViewer != null) {
        try {
            Object obj = tableViewer.getElementAt(0);
            if (obj != null)
                tableViewer.setSelection(new StructuredSelection(obj));
        } catch (Exception e) {
        // ignore
        }
    }
    portChanged = false;
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ServerPort(org.eclipse.wst.server.core.ServerPort)

Example 17 with ServerPort

use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.

the class AbstractTomcatServerTestCase method createServer.

public IServer createServer() throws Exception {
    IServerType st = ServerCore.findServerType(getServerTypeId());
    IRuntime runtime = createRuntime();
    IServerWorkingCopy wc = st.createServer(null, null, runtime, null);
    ServerPort[] ports = wc.getServerPorts(null);
    TomcatServer tomcatServer = (TomcatServer) wc.getAdapter(TomcatServer.class);
    ITomcatConfigurationWorkingCopy configuration = (ITomcatConfigurationWorkingCopy) tomcatServer.getServerConfiguration();
    // if no ports from the server, use the configuration
    if (ports == null || ports.length == 0) {
        List portsList = configuration.getServerPorts();
        if (portsList != null && portsList.size() > 0) {
            ports = (ServerPort[]) portsList.toArray(new ServerPort[portsList.size()]);
        }
    }
    if (ports != null) {
        int size = ports.length;
        for (int i = 0; i < size; i++) {
            configuration.modifyServerPort(ports[i].getId(), 22100 + i);
        }
    }
    return wc.save(true, null);
}
Also used : IServerType(org.eclipse.wst.server.core.IServerType) ITomcatConfigurationWorkingCopy(org.eclipse.jst.server.tomcat.core.internal.ITomcatConfigurationWorkingCopy) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) List(java.util.List) TomcatServer(org.eclipse.jst.server.tomcat.core.internal.TomcatServer) ServerPort(org.eclipse.wst.server.core.ServerPort) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 18 with ServerPort

use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.

the class GenericServerBehaviour method setupLaunch.

/**
 * Setup for starting the server. Checks all ports available
 * and sets server state and mode.
 *
 * @param launch ILaunch
 * @param launchMode String
 * @param monitor IProgressMonitor
 */
protected void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException {
    if (// $NON-NLS-1$ //$NON-NLS-2$
    "true".equals(launch.getLaunchConfiguration().getAttribute(ATTR_STOP, "false")))
        return;
    String host = getServer().getHost();
    ServerPort[] ports = getServer().getServerPorts(null);
    ServerPort sp = null;
    if (SocketUtil.isLocalhost(host)) {
        for (int i = 0; i < ports.length; i++) {
            sp = ports[i];
            if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
                throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, NLS.bind(GenericServerCoreMessages.errorPortInUse, Integer.toString(sp.getPort()), sp.getName()), null));
        }
    }
    setServerState(IServer.STATE_STARTING);
    setMode(launchMode);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) ServerPort(org.eclipse.wst.server.core.ServerPort)

Example 19 with ServerPort

use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.

the class ExternalServerBehaviour method setupLaunch.

/**
 * Override to set status to unknown if the port was in use and to reset the status if the state was
 * unknown and an exception was not thrown. Will want to change logic once external generic server pings
 * server process to determine state instead of maintaining handle to process.
 */
protected void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException {
    int state = getServer().getServerState();
    try {
        super.setupLaunch(launch, launchMode, monitor);
    } catch (CoreException ce) {
        ServerPort portInUse = portInUse();
        if (portInUse != null) {
            // $NON-NLS-1$//$NON-NLS-2$
            Trace.trace(Trace.WARNING, "Port " + portInUse.getPort() + " is currently in use");
            Status status = new Status(IStatus.WARNING, CorePlugin.PLUGIN_ID, IStatus.OK, NLS.bind(GenericServerCoreMessages.errorPortInUse, Integer.toString(portInUse.getPort()), portInUse.getName()), null);
            setServerStatus(status);
            setServerState(IServer.STATE_UNKNOWN);
        }
        throw ce;
    }
    resetStatus(state);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ServerPort(org.eclipse.wst.server.core.ServerPort)

Example 20 with ServerPort

use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.

the class ExternalServerBehaviour method portInUse.

private ServerPort portInUse() {
    ServerPort[] ports = getServer().getServerPorts(null);
    ServerPort sp;
    for (int i = 0; i < ports.length; i++) {
        sp = ports[i];
        if (SocketUtil.isPortInUse(sp.getPort(), 5)) {
            return sp;
        }
    }
    return null;
}
Also used : ServerPort(org.eclipse.wst.server.core.ServerPort)

Aggregations

ServerPort (org.eclipse.wst.server.core.ServerPort)26 CoreException (org.eclipse.core.runtime.CoreException)14 ArrayList (java.util.ArrayList)10 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)9 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)9 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 Iterator (java.util.Iterator)3 TableItem (org.eclipse.swt.widgets.TableItem)3 IOException (java.io.IOException)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 IModule (org.eclipse.wst.server.core.IModule)2 IStaticWeb (org.eclipse.wst.server.core.util.IStaticWeb)2 Element (org.w3c.dom.Element)2 List (java.util.List)1 IWebModule (org.eclipse.jst.server.core.IWebModule)1 Port (org.eclipse.jst.server.generic.servertype.definition.Port)1 IMemento (org.eclipse.jst.server.preview.adapter.internal.IMemento)1 XMLMemento (org.eclipse.jst.server.preview.adapter.internal.XMLMemento)1 ITomcatConfigurationWorkingCopy (org.eclipse.jst.server.tomcat.core.internal.ITomcatConfigurationWorkingCopy)1