org.yx.http.act.HttpActions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sumk Show documentation
Show all versions of sumk Show documentation
A quick developing framewort for internet company
/**
* Copyright (C) 2016 - 2030 youtongluan.
*
* 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.
*/
package org.yx.http.act;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import org.yx.annotation.http.Web;
import org.yx.bean.Loader;
import org.yx.common.ActInfoUtil;
import org.yx.common.matcher.WildcardMatcher;
import org.yx.conf.AppInfo;
import org.yx.exception.SimpleSumkException;
import org.yx.main.SumkServer;
import org.yx.util.StringUtil;
public final class HttpActions {
private static final Map actMap = new ConcurrentHashMap<>();
private static Function nameResolver;
public static synchronized void init() {
nameResolver = Loader.newInstanceFromAppKey("sumk.http.name.resolver");
if (nameResolver == null) {
nameResolver = new ActNameResolver(AppInfo.getBoolean("sumk.http.act.ingorecase", false));
}
}
public static HttpActionInfo getHttpInfo(String act) {
return actMap.get(act);
}
public static void putActInfo(final String rawName, HttpActionNode actInfo) {
String act = nameResolver.apply(rawName);
if (actMap.putIfAbsent(act, new HttpActionInfo(rawName, actInfo)) != null) {
throw new SimpleSumkException(1242435, act + " already existed");
}
}
public static HttpActionInfo getDefaultInfo() {
return actMap.get(WildcardMatcher.WILDCARD);
}
public static String solveAct(String rawName) {
return nameResolver.apply(rawName);
}
public static String[] acts() {
String[] acts = actMap.keySet().toArray(new String[0]);
Arrays.sort(acts);
return acts;
}
public static List rawActs() {
Collection infos = actMap.values();
List raws = new ArrayList<>(infos.size());
for (HttpActionInfo info : infos) {
raws.add(info.rawAct());
}
raws.sort(null);
return raws;
}
public static List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy