Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* anaptecs GmbH, Ricarda-Huch-Str. 71, 72760 Reutlingen, Germany
*
* Copyright 2004 - 2019. All rights reserved.
*/
package com.anaptecs.spring.service.restproxy;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;
import com.anaptecs.jeaf.rest.executor.api.ContentType;
import com.anaptecs.jeaf.rest.executor.api.HttpMethod;
import com.anaptecs.jeaf.rest.executor.api.ObjectType;
import com.anaptecs.jeaf.rest.executor.api.RESTRequest;
import com.anaptecs.jeaf.rest.executor.api.RESTRequestExecutor;
import com.anaptecs.jeaf.validation.api.ValidationExecutor;
import com.anaptecs.spring.base.BookingID;
import com.anaptecs.spring.base.DoubleCode;
import com.anaptecs.spring.base.IntegerCodeType;
import com.anaptecs.spring.base.LongCode;
import com.anaptecs.spring.base.StringCode;
import com.anaptecs.spring.base.TimeUnit;
import com.anaptecs.spring.service.DataTypesQueryBean;
import com.anaptecs.spring.service.MultiValuedHeaderBeanParam;
import com.anaptecs.spring.service.PathlessService;
/**
* Class implements a proxy for REST Service {@link PathlessService}. The proxy is implemented as Spring services. This
* way to developers it looks like a plain Spring Service.
*
* This implementation deals with everything that is required to call the external REST service including the following
* things:
*
*
Serialization / deserialization between Java and JSON
*
Proper connection pooling and timeouts for HTTP requests
*
Proper setting of HTTP header
*
Circuit breaker in case of availabilities problems of the REST service
*
*
* However, as an transactional context can not be propagated to another REST resource developers still have to take
* care about proper transaction handling if needed.
*/
@Service
public class PathlessServiceRESTProxy implements PathlessService {
/**
* REST request executor is used to send REST request to the proxied REST resource. Depending on the Spring
* configuration the matching implementation will be injected here.
*/
private final RESTRequestExecutor requestExecutor;
/**
* REST Service Proxy was generated with request / response validation enabled. The actual validation will be
* delegated to the implementation of this interface.
*/
private final ValidationExecutor validationExecutor;
/**
* Initialize object.
*
* @param pRequestExecutor Dependency on concrete {@link RESTRequestExecutor} implementation that should be used.
*/
public PathlessServiceRESTProxy( RESTRequestExecutor pRequestExecutor, ValidationExecutor pValidationExecutor ) {
requestExecutor = pRequestExecutor;
validationExecutor = pValidationExecutor;
}
/**
* @return {@link String}
*/
@Override
public String getSomething( ) {
// Create builder for GET request
RESTRequest.Builder lRequestBuilder = RESTRequest.builder(PathlessService.class, HttpMethod.GET, ContentType.JSON);
// Build path of request
StringBuilder lPathBuilder = new StringBuilder();
lPathBuilder.append('/');
lPathBuilder.append("doSomething");
lRequestBuilder.setPath(lPathBuilder.toString());
// Execute request and return result.
RESTRequest lRequest = lRequestBuilder.build();
ObjectType lObjectType = ObjectType.createObjectType(String.class);
String lResult = requestExecutor.executeSingleObjectResultRequest(lRequest, 200, lObjectType);
// Validate response and return it.
validationExecutor.validateResponse(PathlessService.class, lResult);
return lResult;
}
/**
* @param pHeaderBean
* @param pTechContext
*/
@Override
public void processTechParam( MultiValuedHeaderBeanParam pHeaderBean ) {
// Validate request parameter(s).
validationExecutor.validateRequest(PathlessService.class, pHeaderBean);
// Create builder for POST request
RESTRequest.Builder lRequestBuilder = RESTRequest.builder(PathlessService.class, HttpMethod.POST, ContentType.JSON);
// Build path of request
StringBuilder lPathBuilder = new StringBuilder();
lPathBuilder.append('/');
lPathBuilder.append("processTechParam");
lRequestBuilder.setPath(lPathBuilder.toString());
// Set HTTP header(s)
if (pHeaderBean != null) {
if (pHeaderBean.getNames() != null) {
lRequestBuilder.setHeader("names", pHeaderBean.getNames());
}
if (pHeaderBean.getInts() != null) {
lRequestBuilder.setHeader("ints", pHeaderBean.getInts());
}
if (pHeaderBean.getDoubles() != null) {
lRequestBuilder.setHeader("doubles", pHeaderBean.getDoubles());
}
if (pHeaderBean.getCodes() != null) {
List