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.
«EXTENSION java::GeneratorCommons»
«EXTENSION java::Naming»
«EXTENSION jeaf::RESTFunctions»
«EXTENSION java::OpenAPIFunctions»
«EXTENSION functions::Property»
«EXTENSION functions::Class»
«EXTENSION functions::RESTOperation»
«IMPORT uml»
«IMPORT JMM»
«DEFINE GenerateRESTServiceProxy FOR RESTResource»
«IF isTargetRuntimeSpring()»
«EXPAND GenerateRESTServiceProxySpring»
«ENDIF»
«IF isTargetRuntimeJEAF()»
«EXPAND GenerateRESTProxyServiceProviderInterface»
«EXPAND GenerateRESTProxyServiceProviderFactory»
«EXPAND GenerateRESTProxyServiceProviderImpl»
«ENDIF»
«ENDDEFINE»
«DEFINE GenerateRESTProxyServiceProviderInterface FOR RESTResource»
«FILE packagePath()+"/restproxy/"+name+"RESTProxyServiceProvider.java" src_gen»
«getFileHeader()»
package «packageName()».restproxy;
/**
* Service Provider Interface is generated so that a proxy for a REST Resource can be provided as JEAF Service Provider.
*/
public interface «name»RESTProxyServiceProvider extends com.anaptecs.jeaf.core.api.ServiceProvider {
«EXPAND JEAFOperation::InterfaceOperation FOREACH this.getAllOperations().typeSelect(RESTOperation)»
}
«ENDFILE»
«ENDDEFINE»
«DEFINE GenerateRESTProxyServiceProviderFactory FOR RESTResource»
«FILE packagePath()+"/restproxy/"+name+"RESTProxyServiceProviderFactory.java" src_gen»
«getFileHeader()»
package «packageName()».restproxy;
import com.anaptecs.jeaf.core.api.ServiceProvider;
import com.anaptecs.jeaf.core.spi.ServiceProviderImplementation;
import com.anaptecs.jeaf.core.servicechannel.api.ServiceProviderFactory;
/**
* This class is the factory class the service provider implementation {@link «name»RESTProxyServiceProviderImpl}.
*/
@com.anaptecs.jeaf.core.annotations.ServiceProviderFactory
public final class «name»RESTProxyServiceProviderFactory extends ServiceProviderFactory {
/**
* Initialize object. No actions have to be performed.
*/
public «name»RESTProxyServiceProviderFactory( ) {
// Nothing to do.
}
/**
* Method creates a new instance of the service provider.
*
* @return {@link ServiceProviderImplementation} Instance of service provider. The method never returns null.
*
* @see com.anaptecs.jeaf.core.servicechannel.api.ServiceProviderFactory#createServiceProviderImplementation()
*/
public ServiceProviderImplementation createServiceProviderImplementation( ) {
return new «name»RESTProxyServiceProviderImpl();
}
/**
* Method returns the interface of the service provider created by this factory.
*
* @return Class Class object of interface that belongs to the service provider that is created by this factory. The
* method never returns null.
*
* @see com.anaptecs.jeaf.core.servicechannel.api.ServiceProviderFactory#getServiceProviderInterface()
*/
public Class extends ServiceProvider> getServiceProviderInterface( ) {
return «packageName()».restproxy.«name»RESTProxyServiceProvider.class;
}
}
«ENDFILE»
«ENDDEFINE»
«DEFINE GenerateRESTProxyServiceProviderImpl FOR RESTResource»
«FILE packagePath()+"/restproxy/"+name+"RESTProxyServiceProviderImpl.java" src_gen»
«getFileHeader()»
package «packageName()».restproxy;
import com.anaptecs.jeaf.core.api.ServiceProvider;
import com.anaptecs.jeaf.core.spi.ServiceProviderImplementation;
import com.anaptecs.jeaf.core.servicechannel.api.ServiceProviderFactory;
/**
* Class implements a service provider that acts as proxy for REST service {@link «this.fqn()»}.
*/
public final class «name»RESTProxyServiceProviderImpl implements com.anaptecs.jeaf.core.spi.ServiceProviderImplementation, «packageName()».restproxy.«name»RESTProxyServiceProvider {
/**
* 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.
*/
@com.anaptecs.jeaf.core.annotations.JEAFServiceProvider
private com.anaptecs.jeaf.rest.executor.api.jeaf.RESTRequestExecutorServiceProvider requestExecutor;
/**
* Determine configuration of the service provider implementation and initialize httpo client to call REST service.
*/
@Override
public void initialize( ) {
// Nothing to do.
}
/**
* Method checks state of this service provider implementation.
*
* @return {@link HealthCheckResult} Result of the check.
*/
@Override
public com.anaptecs.jeaf.xfun.api.health.HealthCheckResult check( com.anaptecs.jeaf.xfun.api.health.CheckLevel pLevel ) {
return null;
}
«EXPAND RESTProxyOperationOperation(this) FOREACH this.getAllOperations().typeSelect(RESTOperation)»
}
«ENDFILE»
«ENDDEFINE»
«DEFINE GenerateRESTServiceProxySpring FOR RESTResource»
«FILE packagePath()+"/restproxy/"+name+"RESTProxy.java" src_gen»
«getFileHeader()»
package «packageName()».restproxy;
/**
* Class implements a proxy for REST Service {@link «this.fqn()»}. 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.
*/
@org.springframework.stereotype.Service
public class «name»RESTProxy implements «this.fqn()» {
/**
* 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 com.anaptecs.jeaf.rest.executor.api.RESTRequestExecutor requestExecutor;
«IF generateRESTRequestValidation() || generateRESTResponseValidation()»
/**
* REST Service Proxy was generated with request / response validation enabled. The actual validation will be delegated to the implementation of this interface.
*/
private final com.anaptecs.jeaf.validation.api.ValidationExecutor validationExecutor;
«ENDIF»
/**
* Initialize object.
*
* @param pRequestExecutor Dependency on concrete {@link RESTRequestExecutor} implementation that should be used.
*/
public «name»RESTProxy( com.anaptecs.jeaf.rest.executor.api.RESTRequestExecutor pRequestExecutor «IF generateRESTRequestValidation() || generateRESTResponseValidation()», com.anaptecs.jeaf.validation.api.ValidationExecutor pValidationExecutor«ENDIF» ) {
requestExecutor = pRequestExecutor;
«IF generateRESTRequestValidation() || generateRESTResponseValidation()»
validationExecutor = pValidationExecutor;
«ENDIF»
}
«EXPAND RESTProxyOperationOperation(this) FOREACH this.getAllOperations().typeSelect(RESTOperation)»
}
«ENDFILE»
«ENDDEFINE»
«DEFINE RESTProxyOperationOperation(RESTResource service) FOR RESTOperation»
«EXPAND functions::Javadoc::JavadocForOperation»
«EXPAND java::Helper::GenerateDeprecationAnnotation-»
«EXPAND java::Helper::GenerateDeprecationAnnotation FOR this.getReturnResult() -»
@Override
«visibility» «getReturnTypeName()» «name» («EXPAND jeaf::JEAFOperation::ParameterSignatureNoValidationAnnotation»)«getThrownExceptionsAsString()» {
«IF generateRESTRequestValidation() && this.getInputParameters().select(e|e.isParameterSuppressed() == false).isEmpty == false»
«IF isTargetRuntimeSpring()»
// Validate request parameter(s).
validationExecutor.validateRequest(«((NamedElement)owner).fqn()».class, «this.asParameterListNames()»);
«ENDIF»
«ENDIF»
// Create builder for «this.httpMethods.selectFirst(e|e!=null)» request
com.anaptecs.jeaf.rest.executor.api.RESTRequest.Builder lRequestBuilder = com.anaptecs.jeaf.rest.executor.api.RESTRequest.builder(«service.fqn()».class, com.anaptecs.jeaf.rest.executor.api.HttpMethod.«this.httpMethods.selectFirst(e|e!=null)», com.anaptecs.jeaf.rest.executor.api.ContentType.JSON);
// Build path of request
StringBuilder lPathBuilder = new StringBuilder();
«IF service.path.length > 0»
lPathBuilder.append("«service.path»");
«ENDIF»
«IF this.getRESTOperationPath(service).length > 0»
lPathBuilder.append('/');
«FOREACH splitRESTPath(this.getRESTOperationPath(service), this.getAllPathParams(), this.getAllPathParamNamnes()) AS pathPart»
lPathBuilder.append(«pathPart»);
«ENDFOREACH»
«ENDIF»
lRequestBuilder.setPath(lPathBuilder.toString());
«IF this.getQueryParams().size > 0 || this.getBeanParams().type.getAllAttributesFromHierarchy().typeSelect(JMM::QueryParam).size > 0»
// Add query parameter(s) to request
«ENDIF»
«FOREACH this.getQueryParams() AS queryParam »
«IF queryParam.type.isPrimitiveType() == false || queryParam.isMultivalued()»
if («queryParam.name» != null) {
«ENDIF»
«IF queryParam.isMultivalued() == true && (queryParam.type.isOpenAPIDataType() || queryParam.type.isAnyDateType())»
java.util.List