
org.rapidoid.http.DynamicRESTClient Maven / Gradle / Ivy
package org.rapidoid.http;
import org.rapidoid.RapidoidThing;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.OfType;
import org.rapidoid.annotation.Since;
import org.rapidoid.beany.Metadata;
import org.rapidoid.commons.Arr;
import org.rapidoid.concurrent.Callback;
import org.rapidoid.config.Conf;
import org.rapidoid.config.Config;
import org.rapidoid.lambda.Dynamic;
import org.rapidoid.u.U;
import org.rapidoid.util.Constants;
import java.lang.reflect.Method;
import java.util.concurrent.Future;
/*
* #%L
* rapidoid-http-client
* %%
* Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors
* %%
* 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.
* #L%
*/
@Authors("Nikolche Mihajlovski")
@Since("4.4.0")
public class DynamicRESTClient extends RapidoidThing implements Dynamic, Constants {
private final Class> clientInterface;
private final Config config;
public DynamicRESTClient(Class> clientInterface) {
this(clientInterface, Conf.section(clientInterface));
}
public DynamicRESTClient(Class> clientInterface, Config config) {
this.clientInterface = clientInterface;
this.config = config;
}
@SuppressWarnings("unchecked")
@Override
public Object call(Method m, Object[] args) {
U.must(!config.isEmpty(), "Cannot find configuration for the REST client interface: %s", clientInterface.getSimpleName());
Config cfg = config.sub(m.getName());
String verb = verbOf(cfg);
String url = cfg.entry(verb).str().get();
U.must(!U.isEmpty(verb), "The [verb: url] entry is not configured for the method: %s", m);
U.must(!U.isEmpty(url), "Cannot find 'url' configuration for the method: %s", m);
Class
© 2015 - 2025 Weber Informatics LLC | Privacy Policy