oubli
This commit is contained in:
parent
a08f5edacf
commit
34957adcbb
4 changed files with 113 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
FROM openjdk:8-jre-slim
|
||||
|
||||
EXPOSE 9080
|
||||
EXPOSE 8090
|
||||
ADD application.properties /application.properties
|
||||
ADD maven/swimmingpool-web.jar app.jar
|
||||
USER root
|
||||
RUN bash -c 'touch /app.jar'
|
||||
ENV JAVA_OPTS "-Dspring.config.location=file:./ "
|
||||
|
||||
ENTRYPOINT exec java $JAVA_OPTS $PYMMA_OPTS -jar /app.jar
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# See http://docs.spring.io/spring-boot/docs/1.1.4.RELEASE/reference/htmlsingle/#boot-features-external-config-profile-specific-properties
|
||||
# for more details about creating profile-specific property files
|
||||
# See http://docs.spring.io/spring-boot/docs/1.1.4.RELEASE/reference/htmlsingle/#howto-initialize-a-database-using-jpa
|
||||
url.swimmingpool.calculate=http://reverse-proxy:9500/
|
||||
server.port=8080
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright 2014 Pymma Software
|
||||
*
|
||||
* 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 org.chtijbug.swimmingpool.web.controller;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RequestCallback;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.training.leisure.swimmingpool.Quote;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* Date: 08/10/14
|
||||
* Time: 10:37
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/quote")
|
||||
public class QuoteController {
|
||||
private static Logger logger = LoggerFactory.getLogger(QuoteController.class);
|
||||
@Value("${url.swimmingpool.calculate}")
|
||||
private String urlCalcul;
|
||||
private RestTemplate restTemplateKieServer = new RestTemplate();
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@RequestMapping(value = "/calculate/{containerId:.+}", method = RequestMethod.PUT)
|
||||
public Quote storeTicket(@PathVariable("containerId") String containerid,
|
||||
@RequestBody Quote quoteRequest) {
|
||||
Quote responseMoteur=null;
|
||||
try {
|
||||
|
||||
String completeurl = urlCalcul+"/"+containerid;
|
||||
logger.info("url moteur reco : " + completeurl);
|
||||
ResponseEntity<Quote> response = restTemplateKieServer
|
||||
.execute(completeurl, HttpMethod.PUT, requestCallback(quoteRequest), clientHttpResponse -> {
|
||||
Quote extractedResponse = null;
|
||||
if (clientHttpResponse.getBody() != null) {
|
||||
Scanner s = new Scanner(clientHttpResponse.getBody()).useDelimiter("\\A");
|
||||
String result = s.hasNext() ? s.next() : "";
|
||||
extractedResponse = mapper.readValue(result, Quote.class);
|
||||
}
|
||||
ResponseEntity<Quote> extractedValue = new ResponseEntity<>(extractedResponse, clientHttpResponse.getHeaders(), clientHttpResponse.getStatusCode());
|
||||
return extractedValue;
|
||||
});
|
||||
Quote reponseMoteur = null;
|
||||
if (response.getBody() != null) {
|
||||
reponseMoteur = response.getBody();
|
||||
} else {
|
||||
reponseMoteur = quoteRequest;
|
||||
}
|
||||
return reponseMoteur;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return responseMoteur;
|
||||
}
|
||||
private RequestCallback requestCallback(final Quote updatedInstance) {
|
||||
return clientHttpRequest -> {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.writeValue(clientHttpRequest.getBody(), updatedInstance);
|
||||
clientHttpRequest.getHeaders().add(
|
||||
HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
clientHttpRequest.getHeaders().add(
|
||||
HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
log4j.rootLogger=debug, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%t %-5p %c{2} - %m%n
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue