In running my application, I receive an error: Cannot find a default KieBaseException! called from KieContainerImpl.
I cannot find KieContainerImpl in the source code for drools-7.23.0.Final.
I have searched the source code org.kie.api.KieBase and drools.compiler.builder.imp, but unable to find KieContainerImpl
try
{
kContainer = ks.newKieContainer();
System.out.println("\ninitialized KieContainer:\t" + kContainer);
// Verify that kContainer was properly loaded
Results results = kContainer.verify();
...
/*
* A KieBase represents a compiled version of a set of assets.
*/
kBase = kContainer.getKieBase();
System.out.println("\ninitialized kBase:\n" + kBase);
}
catch (NoClassDefFoundError e)
{
e.printStackTrace();
}
catch (Exception ex)
{
System.out.println("Exception!");
ex.printStackTrace();
}
I expected the verify function to work. Here is the result:
initialized KieContainer: org.drools.compiler.kie.builder.impl.KieContainerImpl#767e20cf
Exception!
java.lang.RuntimeException: Cannot find a default KieBaseException at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:553)
at chemistryAdvisor.ChemistryAdvisor.initializeRuleEngine(ChemistryAdvisor.java:477)
at chemistryAdvisor.ChemistryAdvisor.main(ChemistryAdvisor.java:227)
java.lang.RuntimeException: Cannot find a default KieSession
at org.drools.compiler.kie.builder.impl.KieContainerImpl.findKieSessionModel(KieContainerImpl.java:684)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:677)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:660)
at chemistryAdvisor.ChemistryAdvisor.initializeRuleEngine(ChemistryAdvisor.java:496)
at chemistryAdvisor.ChemistryAdvisor.main(ChemistryAdvisor.java:227)
Welcome to ChemistryAdvisor!
When invoking kContainer.getKieBase(); without specifying any parameter, Drools expects to find a KieBase marked as default in your kmodule.xml.
Take a look at my answer in this other question.
Hope it helps,
Related
I'm getting an unhandled message exception for IOException. As you can see in the pasted code I've handled the IOException. The JDK for both eclipse & the project is Java 8 update 121 so I know catching multiple exceptions is supported. What am I doing wrong?
try (InputStream inputStream = BatchMessageProperties.class.getClassLoader().
getResourceAsStream(propertiesFileName)) {
load(inputStream);
//need to make sure all properties are present & not null.
validate(this);
} catch (IOException | InvalidBatchMessagePropertiesFileException ex) {
logger.error(ex.getLocalizedMessage());
ex.printStackTrace();
throw ex;
}
You do rethrow ex inside your catch block, which may be an IOException, right?
Hi all i am trying to deploy process definiton in activiti-rest by using java rest.But getting error as 'Exception in thread "main" Bad Request (400)'.I have tried a lots in google but not found any solution for that.Please help me where is the actual fault in my code.Find below my java code and errors.
My Errors
Starting the internal HTTP client
Exception in thread "main" Bad Request (400) - The request could not be understood by the server due to malformed syntax
at org.restlet.resource.ClientResource.doError(ClientResource.java:590)
at org.restlet.resource.ClientResource.handleInbound(ClientResource.java:1153)
at org.restlet.resource.ClientResource.handle(ClientResource.java:1048)
at org.restlet.resource.ClientResource.handle(ClientResource.java:1023)
at org.restlet.resource.ClientResource.post(ClientResource.java:1485)
at org.restlet.resource.ClientResource.post(ClientResource.java:1424)
at com.bizruntime.activiti.rest.Activiti_Rest_BuyEconomyOrBusinsessClassTIcket.TicketClass.createdeployment(TicketClass.java:40)
at com.bizruntime.activiti.rest.Activiti_Rest_BuyEconomyOrBusinsessClassTIcket.Ticke_Test.main(Ticke_Test.java:13)
My Java Code
/**
*Client Resource
*/
private static ClientResource getClientResource(String uri){
ClientResource resource=new ClientResource("http://localhost:8431/activiti-rest/service");
resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC,kermit,kermit);
return resource;
}
/**
* Creating Deployment
*/
public static JSONObject createdeployment(){
String uri=REST_URI+"/repository/deployments";
log.debug("uri(Create Deploymnet):: "+uri);
JSONObject my_data=new JSONObject();
try {
my_data.put("name","BuyTicket.bpmn20.xml");
Representation response=getClientResource(uri).post(my_data);
JSONObject object=new JSONObject(response.getText());
if(object!=null){
log.info("Deployed Successfully.....");
return object;
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
cfr. http://activiti.org/userguide/index.html#_create_a_new_deployment: the body should not be a json multipart/form-data file that is a bpmn20.xml file (or a .zip in case of multiple files)
I'm in a situation where I have a function executing an SQL query whose results I would like to pass into a function that will save them as a CSV file. I wrote this try-with-resource block to take advantage of AutoClosable:
public static ResultSet getRiderHistory(File file, Calendar date) throws FileNotFoundException {
try(Connection conn = new dbConnect("psql", "localhost", ****, "*****", "****", "").get_conn();
PreparedStatement pstmt = createPreparedStatement(conn, getSerialFromFile(file), date);
ResultSet rs = pstmt.executeQuery()) {
if(!rs.isBeforeFirst()) {
throw new SQLException("ResultSet retuned empty!");
}
return rs;
} catch (FileNotFoundException e) {
throw new FileNotFoundException();
} catch (Exception e) {
e.printStackTrace();
}
}
but the compiler is quitting with this error:
compile:
[javac] Compiling 2 source files to /home/****
[javac] /home/****/****.java:50: error: missing return statement
[javac] }
[javac] ^
[javac] 1 error
I think I understand the reason the nature of the problem. I'm guessing it's because I'm trying to return a resource that's going to be closed, instead of a copy of the results like I want (please correct me if I'm wrong). As I'm new to Java, however, I don't really know how to resolve this and get the results I want. Should I use a finally on the ResultSet somehow, or ought I change the return value into something like an ArrayList, an object that doesn't have to closed?
No, the error is saying that your last catch (Exception) block does not return a value. The body of the try returns a value, and the first catch throws an exception, but the last catch does nothing except print a stacktrace. All return paths in this method must either 1) return a ResultSet or null, or 2) throw an exception.
I could use Refactor->Inine when I need to inline a method.
This the code skeleton that I tried, I used the code in this post - Is there any eclipse refactoring API that I can call programmatically?.
// 1. Get ICompiationUnit for type "smcho.Hello"
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("Hello");
project.open(null /* IProgressMonitor */);
IJavaProject javaProject = JavaCore.create(project);
IType itype = javaProject.findType("smcho.Hello");
org.eclipse.jdt.core.ICompilationUnit icu = itype.getCompilationUnit();
// 2. Contribution and Description creation
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(IJavaRefactorings.INLINE_METHOD);
InlineMethodDescriptor descriptor = (InlineMethodDescriptor) contribution.createDescriptor();
descriptor.setProject(icu.getResource().getProject().getName( ));
// 3. executing the refactoring
RefactoringStatus status = new RefactoringStatus();
try {
Refactoring refactoring = descriptor.createRefactoring(status);
IProgressMonitor monitor = new NullProgressMonitor();
refactoring.checkInitialConditions(monitor);
refactoring.checkFinalConditions(monitor);
Change change = refactoring.createChange(monitor);
change.perform(monitor);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
When I execute the code, I got this error
org.eclipse.core.runtime.CoreException: The refactoring script argument 'input' is missing
in the refactoring script.
I think I need to give the refactored method name to the API. What might be wrong in the code?
You never supply the method to the refactoring operation in the above code, you only give it the project context. But I don't know the necessary API for that.
If you look at this source code, you will notice the use of JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, which is probably the one you also need to set. Maybe you can search the refactoring.ui plugin sources for references to that attribute.
This is the code that works with inline refactoring JDT API.
It requires start position and length to be inlined.
int[] selection= {start, length}; // getSelection();
InlineMethodRefactoring refactoring= InlineMethodRefactoring.create(this.icu, new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(this.icu, true), selection[0], selection[1]);
refactoring.setDeleteSource(true);
refactoring.setCurrentMode(Mode.INLINE_ALL); // or INLINE SINGLE based on the user's intervention
IProgressMonitor pm= new NullProgressMonitor();
RefactoringStatus res = refactoring.checkInitialConditions(pm);
res = refactoring.checkFinalConditions(pm);
final PerformRefactoringOperation op= new PerformRefactoringOperation(
refactoring, getCheckingStyle());
op.run(new NullProgressMonitor());
When you know the name of the method that is going to be inlined, you can use the code in - Getting startPosition and length of a method invocation using JDT
I inherited some code that is using the Apache commons-dbcp Connection pools in an OSGi bundle. This code works fine with Eclipse/Equinox OSGi version 3.4.3 (R34x_v20081215), commons-dbcp 1.2.2 and the postgres jdbc3 8.3.603 bundles from springsource.org.
I wanted to modernize, maybe this was my first mistake!
When I use the new version of Felix or Equinox OSGI Cores with the new postgresql JDBC3 or JDBC4 bundles along with the latest version of commons-dbcp (1.4.1), I am getting a classloading issue. I have done numerous searches and found that the commons-dbcp code should have a fix DBCP-214, but it still seems to fail.
I have tried to put the org.postgresql on the commons-dbcp MANIFEST.MF import-package line, but that did not work either.
I wrote a simple test in an activator that first does a basic class.forName() and DriverManager.getConnection(), this works fine, but when I add in BasicDataSource() and setup the connection with BasicDataSource.getConnection(), I get the ClassNotFoundException. See the code example below.
Thanks in Advance for any help, suggestions, ...
Sau!
// This one fails with an exception
public void dsTest() {
BasicDataSource bds = new BasicDataSource();
ClassLoader cl;
try {
logger.debug("ContextClassLoader: {}",
Thread.currentThread().getContextClassLoader().toString());
cl = this.getClass().getClassLoader();
logger.debug("ClassLoader: {}", cl);
if (bds.getDriverClassLoader() != null) {
logger.debug(bds.getDriverClassLoader().toString());
}
// The failure is the same with and with the setDriverClassLoader() line
bds.setDriverClassLoader(cl);
bds.setDriverClassName("org.postgresql.Driver");
bds.setUrl("jdbc:postgresql://127.0.0.1/dbname");
bds.setUsername("user");
bds.setPassword("pword");
Class.forName("org.postgresql.Driver").newInstance();
conn = bds.getConnection();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT COUNT(*) FROM table");
conn.close();
logger.debug("Closed DataSource Test");
} catch (Exception ex) {
ex.printStackTrace();
logger.debug("Exception: {} ", ex.getMessage());
}
}
// This one works
public void managerTest() {
ClassLoader cl;
try {
cl = this.getClass().getClassLoader();
logger.debug("ClassLoader: {}", cl);
Class.forName("org.postgresql.Driver").newInstance();
String url = "jdbc:postgresql://127.0.0.1/dbname";
conn = DriverManager.getConnection(url, "user", "pword");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT COUNT(*) FROM table");
conn.close();
logger.debug("Closed Manger Test");
} catch (Exception ex) {
ex.printStackTrace();
logger.debug("Exception: {} ", ex.getMessage());
}
}
this is due to the fact that the commons-dbcp bundle cannot look at the actual driver class, because of the osgi class loader. The solution to this is to attach a fragment to the commons-dbcp class with Dynamic Import *. The actual headers that you need in your MANIFEST are the following:
Fragment-Host: org.apache.commons.dbcp
DynamicImport-Package: *
After this, the code you mentioned worked. Hope this doesnt come too late.