<commit_before>/**
 * 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.
 */

package org.apache.solr.handler;

import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;


/**
 * Ping solr core
 * 
 * @since solr 1.3
 */
public class PingRequestHandler extends RequestHandlerBase 
{

  SimpleDateFormat formatRFC3339 = new SimpleDateFormat("yyyy-MM-dd'T'h:m:ss.SZ");
  protected enum ACTIONS {STATUS, ENABLE, DISABLE, PING};
  private String healthcheck = null;
  
  @Override
  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception 
  {
    
    SolrParams params = req.getParams();
    SolrCore core = req.getCore();
    
    // Check if the service is available
    healthcheck = core.getSolrConfig().get("admin/healthcheck/text()", null );
    
    String actionParam = params.get("action");
    ACTIONS action = null;
    if (actionParam == null){
      action = ACTIONS.PING;
    }
    else {
      try {
        action = ACTIONS.valueOf(actionParam.toUpperCase());
      }
      catch (IllegalArgumentException iae){
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
        "Unknown action: " + actionParam);
      }
    }
    switch(action){
      case PING:
        if( healthcheck != null && !new File(healthcheck).exists() ) {
          throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled");
        }
        handlePing(req, rsp);
        break;
      case ENABLE:
        handleEnable(healthcheck,true);
        break;
      case DISABLE:
        handleEnable(healthcheck,false);
        break;
      case STATUS:
        if( healthcheck == null){
          SolrException e = new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "healthcheck not configured");
          rsp.setException(e);<commit_msg>SOLR-3301: Added Locale to param uppercasing<commit_after>/**
 * 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.
 */

package org.apache.solr.handler;

import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;


/**
 * Ping solr core
 * 
 * @since solr 1.3
 */
public class PingRequestHandler extends RequestHandlerBase 
{

  SimpleDateFormat formatRFC3339 = new SimpleDateFormat("yyyy-MM-dd'T'h:m:ss.SZ");
  protected enum ACTIONS {STATUS, ENABLE, DISABLE, PING};
  private String healthcheck = null;
  
  @Override
  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception 
  {
    
    SolrParams params = req.getParams();
    SolrCore core = req.getCore();
    
    // Check if the service is available
    healthcheck = core.getSolrConfig().get("admin/healthcheck/text()", null );
    
    String actionParam = params.get("action");
    ACTIONS action = null;
    if (actionParam == null){
      action = ACTIONS.PING;
    }
    else {
      try {
        action = ACTIONS.valueOf(actionParam.toUpperCase(Locale.ENGLISH));
      }
      catch (IllegalArgumentException iae){
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
        "Unknown action: " + actionParam);
      }
    }
    switch(action){
      case PING:
        if( healthcheck != null && !new File(healthcheck).exists() ) {
          throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled");
        }
        handlePing(req, rsp);
        break;
      case ENABLE:
        handleEnable(healthcheck,true);
        break;
      case DISABLE:
        handleEnable(healthcheck,false);
        break;
      case STATUS:
        if( healthcheck == null){
          SolrException e = new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "healthcheck not configured");
          rsp.setException(e);
{'fraction_non_alphanumeric': 0.09267965077233042, 'fraction_numerical': 0.004029550033579583, 'mean_word_length': 3.419139465875371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3748882', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1691, 'n_words': 502}