hu.icellmobilsoft.roaster.jaxrs.response.ResponseProcessor Maven / Gradle / Ivy
The newest version!
/*-
* #%L
* Roaster
* %%
* Copyright (C) 2020 - 2024 i-Cell Mobilsoft Zrt.
* %%
* 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%
*/
package hu.icellmobilsoft.roaster.jaxrs.response;
import java.text.MessageFormat;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.core.UriBuilder;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataWriter;
import hu.icellmobilsoft.coffee.module.mp.restclient.provider.DefaultBaseExceptionResponseExceptionMapper;
import hu.icellmobilsoft.coffee.module.mp.restclient.provider.DefaultLoggerClientRequestFilter;
import hu.icellmobilsoft.coffee.module.mp.restclient.provider.DefaultLoggerClientResponseFilter;
import hu.icellmobilsoft.roaster.api.TestException;
/**
* Base Response REST handler based on JXRS
*
* @param
* response class (any type)
* @author imre.scheffer
* @since 0.8.0
*/
public abstract class ResponseProcessor {
/**
* Default constructor, constructs a new object.
*/
public ResponseProcessor() {
super();
}
/**
* Base URI config key
*
* @return config key like "project.service.base.uri"
*/
public abstract String baseUriKey();
/**
* Get value by {@link #baseUriKey()} from microprofile config
*
* @return value like "http://localhost:8080"
*/
public String baseUri() {
return ConfigProvider.getConfig().getValue(baseUriKey(), String.class);
}
/**
* HTTP path to call
*
* @return value like "/test/service/generate/testData"
*/
public abstract String path();
/**
* Expected REST response status code
*
* Default value is {@value Status#OK}
*/
private int expectedStatusCode = Status.OK.getStatusCode();
/**
* Call and get JSON object from HTTP GET method
*
* @param responseClass
* response class
* @param pathParams
* The path parameters.
* @return response object cast to responseClass
*/
public RESPONSE getOctetStream(Class responseClass, Object... pathParams) {
// REST obtaining client
ResteasyClient client = (ResteasyClient) ClientBuilder.newClient();
ResteasyWebTarget target = client.target(UriBuilder.fromUri(baseUri() + path()).build(pathParams));
target.register(MultipartFormDataWriter.class);
CDI
© 2015 - 2025 Weber Informatics LLC | Privacy Policy