com.pivotal.gemfirexd.internal.drda.NetServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfirexd-core Show documentation
Show all versions of gemfirexd-core Show documentation
SnappyData store based off Pivotal GemFireXD
/*
Derby - Class com.pivotal.gemfirexd.internal.drda.NetServlet
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* Changes for GemFireXD distributed data platform (some marked by "GemStone changes")
*
* Portions Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.pivotal.gemfirexd.internal.drda;
import java.io.*;
import java.util.*;
import java.net.*;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import javax.servlet.*;
import javax.servlet.http.*;
import com.pivotal.gemfirexd.internal.iapi.reference.Property;
import com.pivotal.gemfirexd.internal.iapi.tools.i18n.LocalizedResource;
/**
This servlet can be used to start GemFireXD Network Server from a remote location.
These servlet configuration parameters are understood by this servlet.
portNumber
- Port number to use. The default is 1527.
startNetworkServerOnInit
- Starts the GemFireXD Network Server at servlet
initialization if 'true'.
tracingDirectory
- Directory for trace files
*/
public class NetServlet extends HttpServlet {
private final static int MAX_CONNECT_TRYS = 20;
private final static String SERVLET_PROP_MESSAGES = "com.pivotal.gemfirexd.internal.loc.drda.servlet";
private final static String SERVLET_ADDRESS = "derbynet";
private String formHeader = null;
private String host = "localhost";
private int portNumber=1527;
private String tracingDirectory;
private boolean logStatus= false; /* Logging off */
private boolean traceStatus = false; /* Tracing off */
private String[] knownLang = {"cs","en","es","de_DE","fr","hu","it",
"ja_JP","ko_KR","pl","pt_BR","ru","zh_CN","zh_TW"};
private String locale;
private final static int NOT_GIVEN = -2;
private final static int INVALID = -3;
private NetworkServerControl server;
private PrintWriter out;
// for doPri block
private Runnable service;
/**
Initialize the servlet.
Configuration parameters:
portNumber
- Port number
host
- Host name
traceDirectory
- location of trace directory
startNetworkServerOnInit
- start the server on initialization
*/
public void init(ServletConfig config)
throws ServletException
{
LocalizedResource langUtil = new LocalizedResource(null,null,SERVLET_PROP_MESSAGES);
String port = config.getInitParameter("portNumber");
if (port != null) {
int p = Integer.valueOf(port).intValue();
if (p > 0)
portNumber = p;
}
String hostName = config.getInitParameter("host");
if (hostName != null)
host = hostName;
this.tracingDirectory = config.getInitParameter("tracingDirectory");
if ( this.tracingDirectory == null ) {
this.tracingDirectory = "";
}
String startup = config.getInitParameter("startNetworkServerOnInit");
// test if the server is already running
try {
//don't send output to console
if (server == null) {
server = new NetworkServerControl(InetAddress.getByName(host), portNumber);
// assert this.tracingDirectory != null
if ( ! this.tracingDirectory.trim().equals("")) {
server.setTraceDirectory(this.tracingDirectory);
}
}
if (isServerStarted(server,1))
return;
} catch (Exception e) {}
if (startup != null) {
boolean start = Boolean.valueOf(startup).booleanValue();
if (start)
{
runServer(langUtil, null, null);
return;
}
}
}
/**
Get the form of NetServlet. Provides buttons and forms to control the
Network server.
*/
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String logOnMessage;
String logOffMessage;
String traceOnMessage;
String traceOffMessage;
String traceOnOffMessage;
String startMessage;
String stopMessage;
String returnMessage;
String traceSessionMessage;
String traceDirMessage;
String contMessage;
String setParamMessage;
String setParamMessage2;
String netParamMessage;
LocalizedResource langUtil;
langUtil = getCurrentAppUI(request);
response.setContentType("text/html; charset=UTF-8");
//prevent caching of the servlet since contents can change - beetle 4649
response.setHeader("Cache-Control", "no-cache,no-store");
formHeader = "