Looking up a Remote Bean, getting a EjbNamingContext in JBoss 7.1 - ejb

I have a Maven project, in which I want to try integration-testing an EAR sub-module.
In the integration-test submodule, I do the following:
Properties env;
Context ctx;
env = new Properties();
env.setProperty( "java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.setProperty( "java.naming.provider.url", "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "jboss-user");
env.put(Context.SECURITY_CREDENTIALS, "*******");
ctx = new InitialContext( env );
IBMPFacadeRemote bmpFacade = ( IBMPFacadeRemote ) ctx.lookup( "ejb:DeDomain-ejb-1.0-SNAPSHOT/BMPFacade!de.domain.service.IBMPFacadeRemote");
bmpFacade.executeBMPProcess( model1, model2);//model1 & model2 are some entities
The problem: when calling mvn integration-test it ends up with the following Exception
java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to de.domain.service.IBMPFacadeRemote
Could someone help me to solve this problem? Are there any possibilities to integration-test this using a Local Bean (the maven project uses the failsafe-plugin)?

It is now hard to say what exactly solved the problem, but I will try to mention all made changes that solved the problem.
Added to the pom.xml the dependencies
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.1.1.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-jms-client-bom</artifactId>
<version>7.1.1.Final</version>
<type>pom</type>
</dependency>
Changed the JNDI lookup as follows (after changing the deployed name of the EAR&EJB projects)
IBMPFacadeRemote bmpFacade = ( IBMPFacadeRemote ) ctx.lookup( "ejb:DeDomain-ear/DeDomain-ejb//BMPFacadeBean!de.domain.service.IBMPFacadeRemote");
Got rid of the EJB maven plugin from the EJB Project & of some other resources, like jndi.properties
Probably it is worth mentioning, that the Properties instance remained the same as in the stated in the question.

The JNDI Properties are looking strange for me. I was always successfull with the following Properties for JBoss:
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
jnp.socket.Factory=org.jnp.interfaces.TimedSocketFactory
May be you should double check them.

Related

openapi.yaml not generated successfully - Swagger Doc does not open for Windows machines

So I am working on a spring-mvc project, which suddenly started giving this issue when installed on Windows machines only. It's a thick client app.
When trying to access the swagger docs, following error comes :
The logs show following error in the stacktrace :
2022-04-20 04:15:44.821utc WARN Configuration,main:117 - couldn't read inflector config from resource stream
2022-04-20 04:15:44.821utc WARN Configuration,main:131 - couldn't read inflector config from system property
2022-04-20 04:15:44.853utc WARN OpenAPIV3Parser,main:91 - Exception while reading:
io.swagger.v3.parser.exception.ReadContentException: Unable to read location `openapi.yaml`
at io.swagger.v3.parser.OpenAPIV3Parser.readContentFromLocation(OpenAPIV3Parser.java:238) ~[swagger-parser-v3-2.0.27.jar:2.0.27]
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:87) ~[swagger-parser-v3-2.0.27.jar:2.0.27]
..
..
2022-04-19 17:19:16.980utc ERROR [swagger-inflector],http-nio-8080-exec-8:175 - Allocate exception for servlet [swagger-inflector]
*java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.OpenAPI.getComponents()" because "openAPI" is null
at io.swagger.oas.inflector.utils.ExtensionsUtil.removeExtensions(ExtensionsUtil.java:26) ~[swagger-inflector-2.0.6.jar:2.0.6]
at io.swagger.oas.inflector.OpenAPIInflector.getExposedAPI(OpenAPIInflector.java:543) ~[swagger-inflector-2.0.6.jar:2.0.6]*
at io.swagger.oas.inflector.OpenAPIInflector.init(OpenAPIInflector.java:139) ~[swagger-inflector-2.0.6.jar:2.0.6]
at io.swagger.oas.inflector.OpenAPIInflector.<init>(OpenAPIInflector.java:117) ~[swagger-inflector-2.0.6.jar:2.0.6]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at
OpenAPIInflector.getExposedAPI reads swaggerURL location from inflector.yaml file. For some reason on windows, configuration is not picking up openapi.yaml file or corresponding openapi.json file as shown in the screenshot. xxx-openapi.yaml is something defined inside inflector.yaml which in my understanding is being used to generate an openapi.yaml file. In MacOs/local setup I can see this file getting generated and the docs coming up fine.
Please help debug, what the potential cause could be. Permissions are fine on the system this tool is running for inflector.yaml inside classes folder?
here is how the inflector.yaml is defined.
swaggerUrl: xxx-openapi.yaml
xxx-openapi.yaml & inflector.yaml are present in
src/main/resources/
I am also wondering if windows OS is not able to read the files from this path properly. Bases on other posts I have already tried different URLs such as following but they did not work for me.
http://windows-machine-ip:8080/swagger-ui/
http://windows-machine-ip:8080/swagger-ui/index.html
http://windows-machine-ip:8080/v3/api-docs/swagger-ui.html
Note**
openapi: 3.0.0
Dependencies :
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-inflector</artifactId>
<version>2.0.6</version>
</dependency>
Please guide. I am new to this project as well as swagger on spring-mvc. I will be happy to read about stuff which can lead me to fix this. Not looking for a readymade solution but I have tried almost all relevant solutions across multiple forums and hence the post as I am still not able to find the root cause to this. Also I cannot change the existing implementations (like writing it all from scratch) hence I am here more to understand the root cause.
I'm just installing OpenAPI 3 on Spring Core 5.3.18 (Not Boot) projetc :
1/`<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>`
2/ Configurer :
#Configuration
#EnableOpenApi
public class SwaggerConfig {
private static final Logger log = LoggerFactory.getLogger(SwaggerConfig.class);
private static String line = "=".repeat(100);
#Bean
public Docket api(ServletContext servletContext) {
log.info(line);
log.info("Docket swagger called : {} , name :{} ", servletContext.getContextPath(), servletContext.getContext("/rs"));
log.info(line);
return new Docket(DocumentationType.OAS_30)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
;
}
3/ WebConfigurer :
`
#Configuration
#EnableWebMvc
public class WebConfigurer implements WebMvcConfigurer {
private static final Logger log = LoggerFactory.getLogger(WebConfigurer.class);
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}`
4/ URL of Swagger UI is :
[root path]/v3/api-docs for documentation
[root path]/swagger-ui/index.html
Hope that help ;-)

Issue when flink upload a job with stream sql query

I used the latest flink version(1.10.0) and sbt(1.3.7). I have this exception when upload a job with streaming sql query:
Caused by: java.lang.ClassCastException:
org.codehaus.janino.CompilerFactory cannot be cast to
org.codehaus.commons.compiler.ICompilerFactory
at org.codehaus.commons.compiler.CompilerFactoryFactory.getCompilerFactory(CompilerFactoryFactory.java:129)
at org.codehaus.commons.compiler.CompilerFactoryFactory.getDefaultCompilerFactory(CompilerFactoryFactory.java:79)
at org.apache.calcite.rel.metadata.JaninoRelMetadataProvider.compile(JaninoRelMetadataProvider.java:432)
When I running main class with sbt run it works perfectly. I made jar with the sbt assembly command and I have conflicts between libraries. For this reason add this in the build.sbt:
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs # _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
I read a similar case with hive connector https://issues.apache.org/jira/browse/FLINK-14849 and this is the answer:
After https://issues.apache.org/jira/browse/FLINK-13749 , flink-client will use default child-first resolve-order.
If user jar has some conflict dependents, there will be some problem.
My question is: How to resolve these conflicts? Any assembly merge strategy suggest for this case?
Help would be appreciated.
I faced the same issue and the following solution helped me get through :
assembly / assemblyMergeStrategy := {
case PathList("org", "codehaus", "janino", "CompilerFactory.class") => MergeStrategy.discard // discard
case x => MergeStrategy.first // first
}
Also, took help from the this link.
The above addition needs to be done in sbt.build file and make sure you're building using assembly command.
In case one is building using package-bin in case of legacy applications, follow this link.
Another solution includes checking the scope of the flink libraries. If by any chance you have accidentally pushed libraries that were earlier set to 'provided' with something like 'compile', do revert the changes and test.
Hope this helps.
I have same problem.
Maybe you have package your code with flink-table-planner_${scala.binary.version}, so you need to change your maven config with those settings:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner-blink_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
I had the same issue. My problem was, that I added the dependency
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>
without the provided scope. Therefore, maven packaged it in my jar, which lead to the ClassCastException when trying to submit the job to my local flink cluster.

How to build runnable JAR using Javalite framework as standalone http?

As questioned, how to build runnable JAR using Javalite framework?
Javalite doesn't have known entry point / main class. I browse some of the examples but not found any clue.
This jar will run as stand-alone on server using java -jar command.
Below snippet of my plugin on pom.xml file
Packaging
<modelVersion>4.0.0</modelVersion>
<groupId>org.javalite</groupId>
<artifactId>activeweb-simple</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
<name>ActiveWeb Example WebApp</name>
Plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!-- Jar file entry point -->
<mainClass>com.company.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
And the Application.java,
public class Application {
public static void main(String[] args) throws Exception {
String webappDirLocation = "src/main/webapp/";
Tomcat tomcat = new Tomcat();
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8081";
}
tomcat.setPort(Integer.valueOf(webPort));
StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
File additionWebInfClasses = new File("target/classes");
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
additionWebInfClasses.getAbsolutePath(), "/"));
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
}
Note : I'm currently using tomcat as embedded http-server to enable the JAR file run as stand-alone. But, Javalite ActiveWeb probably has a way for this.
You can build any number of different types of JavaLite projects, such as standalone that use some features: JavaLite HTTP, ActiveJDBC, JavaLite Async, etc. In addition, if you want to build a web application, you also will need ActiveWeb.
Here is a list of examples from the JavaLite repo:
ActiveJDBC:
https://github.com/javalite/standalone-example
https://github.com/javalite/simple-example
https://github.com/javalite/ant-example
https://github.com/javalite/activejdbc-gradle
https://github.com/javalite/multiple-db-example
ActiveWeb:
https://github.com/javalite/activeweb-simple
https://github.com/javalite/kitchensink
https://github.com/javalite/activeweb-secure
https://github.com/javalite/activeweb-bootstrap
https://github.com/javalite/activeweb-lessc
Every example app has a README file you can read to see what the example is for.
In order to start any project, just clone a repo, get it running then start modifying it to your liking.
Additionally, pay attention to the Releases page http://javalite.io/releases and keep your dependencies up to date.

How do I add Thymeleaf SpringSecurityDialect to spring boot

In the configuration of my template engine I would like to add SpringSecurityDialect() like:
#Bean
public TemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.addDialect(new SpringSecurityDialect());
engine.setEnableSpringELCompiler(true);
engine.setTemplateResolver(templateResolver());
return engine;
}
However eclipse is telling me:
The type org.thymeleaf.dialect.IExpressionEnhancingDialect cannot be resolved. It is indirectly referenced from required .class files
What does this mean and how can I fix it?
In pom.xml I have:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
As #Lachezar already answered, you have to add those missing dependencies. But the specified version with ext['thymeleaf.version'] = '3.0.0.RELEASE should be the same as in the compile dependencies so you better use ext['thymeleaf.version'] = '3.0.1.RELEASE'.
Furthermore, please note that it is enough to just specify a bean for the security dialect without providing a bean for the template engine. With Thymeleaf on the classpath, it will automatically recognize that the bean is an instance of IDialect and adds it directly to the dialects:
#Bean
public SpringSecurityDialect springSecurityDialect() {
return new SpringSecurityDialect();
}
It means that org.thymeleaf.extras:thymeleaf-extras-springsecurity4 has a dependency to org.thymeleaf:thymeleaf as you can see in the link to the repo above. Apparently you haven't provided this dependency. The class IExpressionEnhancingDialect is there. You can resolve that by adding the dependency to your project.
Since this may get a bit complicated... I'm also playing around with Spring Boot, spring security and the security dialect for thymeleaf (plus spring data with h2). Here are my gradle dependencies for reference, they may help you somehow:
ext['thymeleaf.version'] = '3.0.1.RELEASE'
ext['thymeleaf-layout-dialect.version'] = '2.0.0'
dependencies {
compile("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.1.RELEASE")
compile("com.h2database:h2")
}
Note that I want to use thymeleaf 3 instead of 2, that is why there are some extra unpleasant tweaks in my configuration.
EDIT: The version of thymeleaf-extras-springsecurity4 should be the same as thymeleaf.version as suggested in the other answer.

Maven - SQLite - Missing database

I'm new to maven and I'm trying to make my project work with an sqlite database.
Code works as a normal java project.
I made a Maven project with the exact same working code and added the dependacies in the pom.
pom.xml
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.1</version>
</dependency>
Also, the Library.sqlite is in the root folder of the project (where it works as a normal java project)
works in java, not in maven
"jdbc:sqlite:‪Library.sqlite"
The error reads "[SQLITE_ERROR] SQL error or missing database"
Since it's the same code as the java project, I'm sure there is no syntax error, so it must be something with the location of the Library.sqlite?
How can I make this work?
SOLUTION
It seems my program created a new empty Library.sqlite in my folder and that's why it couldn't find my tables. After deleting the original and editing the new one, it works!
I tried using the same library as you and it seems to work fine for me. Take a look: https://github.com/ajorpheus/SqliteHelloWorld
Sample output after a successful build:
name = leo
id = 1
name = yui
id = 2
Process finished with exit code 0

Resources