Ajout header transaction ID

This commit is contained in:
Nicolas Héron 2019-01-28 11:15:22 +01:00
commit 7a0913d9cd
5 changed files with 25 additions and 60 deletions

View file

@ -268,14 +268,14 @@ public class DeploymentView extends VerticalLayout implements AddLog{
squeletteComposant.getConsoleDeploy().getLogContent().add(horizontalLayout);
//getUI().get().push();
});
/**
ui.getSession().lock();
try {
ui.push();
}finally {
ui.getSession().unlock();
}
**/
System.out.println(textToAdd);
}

View file

@ -3,7 +3,6 @@ package org.chtijbug.drools.proxy.camel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode;
import org.apache.camel.model.rest.RestParamType;
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
import org.chtijbug.drools.proxy.service.KieServiceCommon;
import org.kie.server.api.model.KieContainerResource;
import org.kie.server.api.model.KieContainerResourceList;

View file

@ -37,7 +37,7 @@ public class DroolsRouter extends RouteBuilder {
// .param().name("containerId").type(path).description("Container ID where the rule artefact id deployed").dataType("integer").endParam()
.param().name("body").type(body).description("The Data drools should work on").endParam()
.responseMessage().code(200).message("Data drools worked on").endResponseMessage()
.to("bean:ruleService?method=runSessionObject("+this.containerId+","+this.processID+",${body})");
.to("bean:ruleService?method=runSessionObject(${header.transactionId},"+this.containerId+","+this.processID+",${body})");
}

View file

@ -19,10 +19,10 @@ import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@Service("ruleService")
public class RuleService {
@ -57,7 +57,7 @@ public class RuleService {
}
}
public Object runSessionObject(String id, String processID, Object input) throws IOException {
public Object runSessionObject(String transactionID,String id, String processID, Object input) throws IOException {
KieContainerInstance kci = registry.getContainer(id);
ChtijbugObjectRequest chtijbugObjectRequest = new ChtijbugObjectRequest();
chtijbugObjectRequest.setObjectRequest(input);
@ -80,73 +80,37 @@ public class RuleService {
}
}
String jsonInString = null;
String filetrace = System.getProperty("org.chtijbug.server.tracelog");
if ("true".equals(filetrace)) {
try {
Class foundClass = input.getClass();
Method traceMethod = foundClass.getMethod("logTrace", String.class);
if (traceMethod != null) {
jsonInString = mapper.writeValueAsString(chtijbutObjectResponse.getSessionLogging());
}
traceMethod.invoke(input, jsonInString);
} catch (Exception e) {
}
}
String fileTemp = System.getProperty("org.chtijbug.server.tracedir");
if (fileTemp != null) {
if (jsonInString == null) {
jsonInString = mapper.writeValueAsString(chtijbutObjectResponse.getSessionLogging());
}
File traceFile = new File(fileTemp + "/" + UUID.randomUUID().toString());
FileUtils.writeStringToFile(traceFile, jsonInString);
String fileUUID=null;
if (transactionID==null){
fileUUID="noTransactionID";
}else{
fileUUID=transactionID;
}
LocalDateTime now = LocalDateTime.now();
int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
int hour = now.getHour();
int minute = now.getMinute();
int second = now.getSecond();
int millis = now.get(ChronoField.MILLI_OF_SECOND);
String fileName=year+"-"+month+"-"+day+"-"+hour+"-"+minute+"-"+second+"-"+millis+"-"+fileUUID.replaceAll("-","")+".json";
File traceFile = new File(fileTemp + "/" +fileName);
FileUtils.writeByteArrayToFile(traceFile, jsonInString.getBytes());
}
Object response = chtijbutObjectResponse.getObjectRequest();
return response;
}
public String runSession(String id, String processID, String className,
String objectRequest) {
ClassLoader localClassLoader = null;
Object response = null;
try {
localClassLoader = Thread.currentThread()
.getContextClassLoader();
} catch (ClassCastException e) {
logger.info("GenericResource.runSession", e);
}
ChtijbugObjectRequest chtijbugObjectRequest = new ChtijbugObjectRequest();
try {
KieContainerInstance kci = registry.getContainer(id);
Set<Class<?>> classes = kci.getExtraClasses();
Class foundClass = this.getClassFromName(classes, className);
if (foundClass != null) {
ClassLoader classLoader = foundClass.getClassLoader();
Object input = mapper.readValue(objectRequest, classLoader.loadClass(className));
response = this.runSessionObject(id, processID, input);
}
//response.setSessionLogging(jsonInString);
logger.debug("Returning OK response with content '{}'", response);
String responseText = mapper.writeValueAsString(response);
return responseText;
} catch (Exception e) {
// in case marshalling failed return the FireAllRulesAndStartProcess container response to keep backward compatibility
String responseMessage = "Execution failed with error : " + e.getMessage();
logger.debug("Returning Failure response with content '{}'", responseMessage);
return objectRequest;
} finally {
if (localClassLoader != null) {
Thread.currentThread().setContextClassLoader(localClassLoader);
}
}
}
private Class getClassFromName(Set<Class<?>> classes, String name) {
Class result = null;
for (Class c : classes) {

View file

@ -10,6 +10,8 @@
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />