be.ordina.msdashboard.nodes.aggregators.NettyServiceCaller Maven / Gradle / Ivy
/*
* Copyright 2012-2016 the original author or authors.
*
* 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 be.ordina.msdashboard.nodes.aggregators;
import static java.text.MessageFormat.format;
import io.netty.buffer.ByteBuf;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.protocol.http.AbstractHttpContentHolder;
import io.reactivex.netty.protocol.http.client.HttpClientRequest;
import java.nio.charset.Charset;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.json.JacksonJsonParser;
import rx.Observable;
/**
* Convenience class for retrieving JSON using
* RxNetty.
*
* @author Andreas Evers
*/
public class NettyServiceCaller {
private static final Logger logger = LoggerFactory.getLogger(NettyServiceCaller.class);
private ErrorHandler errorHandler;
public NettyServiceCaller(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
/**
* Calls the remote service using the provided request, applies error handling and
* converts the response into a {@link Map}. The entire request and response are
* executed and handled in a hot observable.
*
* @param serviceId the id of the service for which the request is made
* @param request the request which has to be executed using RxNetty
* @return an {@link Observable} emitting the JSON response as a Map with String keys
* and Object values.
*/
public Observable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy