Spring mvc 5.2.0 + RabbtMQ + Camel - CamelContext must be specified Exception - spring-mvc

I am trying to use Camel with rabbitMQ in Spring MVC the following way:
camel-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="routeBuilder" />
</camelContext>
</beans>
the routeBuilder class:
#Service(value = "routeBuilder")
public class CamelContextRouteBuilder extends RouteBuilder {
#Value("${flag:true}")
private boolean flag;
#Override
public void configure() throws Exception{
if (flag) {
createRoutes();
}
}
private void createRoutes() {
from(String.format("spring-amqp:...))
.throttle(...).timePeriodMillis(...)
.bean("msgProcessor");
}
}
and the processor class:
#Component(value = "msgProcessor")
public class MsgProcessor implements Processor {
public MsgProcessor() {}
#Override
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getMessage();
...
}
}
the dependencies are:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-javaconfig</artifactId>
<version>2.25.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>2.25.0</version>
<exclusions>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.25.0</version>
<exclusions>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-aop</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>jaxb-impl</artifactId>
<groupId>com.sun.xml.bind</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.bluelock</groupId>
<artifactId>camel-spring-amqp</artifactId>
<version>1.7.0</version>
<exclusions>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-rabbit</artifactId>
<groupId>org.springframework.amqp</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-mapper-asl</artifactId>
<groupId>org.codehaus.jackson</groupId>
</exclusion>
</exclusions>
</dependency>
I manage to build the project and run it, I see the rabbit queue has consumers so the routes are created but when a message is processed (failed to get to the listener), the following exception is thrown:
CamelContext must be specified on: Message[]
{"filename":"CamelLogger.java","lineno":"213","stacktrace":"org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1498)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1409)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1329)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor$MethodInvocationRetryCallback.doWithRetry(StatefulRetryOperationsInterceptor.java:229)
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:286)
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:210)
at org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor.invoke(StatefulRetryOperationsInterceptor.java:173)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\n\tat
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)\n\tat
org.springframework.amqp.rabbit.listener.$Proxy342.invokeListener(Unknown
Source)\n\tat
org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1316)\n\tat
org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1295)\n\tat
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:746)\n\tat
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:730)\n\tat
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$500(SimpleMessageListenerContainer.java:74)\n\tat
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:946)\n\tat
amqp.spring.camel.component.SpringAMQPConsumer$SpringAMQPExecutorTask.run(SpringAMQPConsumer.java:316)\n\tat
amqp.spring.camel.component.SpringAMQPConsumer$SpringAMQPExecutorTask.run(SpringAMQPConsumer.java:316)\n\tat
java.lang.Thread.run(Thread.java:748)\nCaused by:
java.lang.IllegalArgumentException: CamelContext must be specified on:
Message[]\n\tat
org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:340)\n\tat
org.apache.camel.impl.DefaultMessage.createHeaders(DefaultMessage.java:255)\n\tat
org.apache.camel.impl.DefaultMessage.getHeaders(DefaultMessage.java:216)\n\tat
amqp.spring.camel.component.SpringAMQPHeader.setBasicPropertiesToHeaders(SpringAMQPHeader.java:61)\n\tat
amqp.spring.camel.component.SpringAMQPMessage.fromAMQPMessage(SpringAMQPMessage.java:53)\n\tat
amqp.spring.camel.component.SpringAMQPConsumer$RabbitMQMessageListener.onMessage(SpringAMQPConsumer.java:197)\n\tat
org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1406)\n\t...
24
more","level":"WARN","exception_class":"org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException","logger_name":"amqp.spring.camel.component.SpringAMQPConsumer","thread":"SpringAMQPConsumer.SpringAMQPExecutor-5","message":"Caused
by:
[org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException
Listener threw exception]","timestamp":"2020-10-30 14:29:48,876","exception_message":"Listener threw exception"}
Where does the CamelContext usage is missing?

Ok, using the following connection:
from("spring-amqp"...)
is a deprecated package:
<groupId>com.bluelock</groupId>
removing it and using the following instead:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rabbitmq</artifactId>
<version>${camel.version}</version>
</dependency>
from("rabbitmq:...")
solved the issue.

Related

Firebase send request with oauth2 token example not working

Trying to get simple google oauth example from Firebase docs to work using Firebase service account json file https://firebase.google.com/docs/cloud-messaging/auth-server#windows :
private static String getAccessToken() throws IOException {
GoogleCredentials googleCredentials = GoogleCredentials
.fromStream(new FileInputStream("service-account.json"))
.createScoped(Arrays.asList(SCOPES));
googleCredentials.refreshAccessToken();
return googleCredentials.getAccessToken().getTokenValue();
} //Messaging.java
Following is my code in Netbeans IDE:
import com.google.auth.oauth2.GoogleCredentials;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
/**
*
* #author Administrator
*/
public class TrOauth2 {
private static final String MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging";
private static final String[] SCOPES = {MESSAGING_SCOPE};
private static String comeon;
public static void main(String[] args) {
try {
System.out.println("Hello World!");
comeon = getAccessToken();
System.out.println(comeon);
} catch (IOException ex) {
Logger.getLogger(TrOauth2.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("Exception when calling getAcessToken();");
}
}
private static String getAccessToken() throws FileNotFoundException, IOException {
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(new FileInputStream("C:\\Users\\administrator\\Downloads\\lora-alarm-firebase-adminsdk-xxx-xxx.json")).createScoped(Arrays.asList(SCOPES));
System.out.println("googleCredentials: " + googleCredentials.toString());
return googleCredentials.getAccessToken().getTokenValue();
}
}
Maven code:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.midniteit</groupId>
<artifactId>TrOauth2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
<exec.mainClass>TrOauth2</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.34.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
<version>1.1.4c</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>1.11.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>TrOauth2</mainClass>
</configuration>
<executions>
<execution>
<id>execute-after-compile</id>
<goals><goal>java</goal></goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I get the following results from Netbeans IDE when I run it:
Hello World!
googleCredentials: ServiceAccountCredentials{clientId=xxx, clientEmail=firebase-adminsdk-xxx#lora-alarm.iam.gserviceaccount.com, privateKeyId=xxx, transportFactoryClassName=com.google.auth.oauth2.OAuth2Utils$DefaultHttpTransportFactory, tokenServerUri=https://oauth2.googleapis.com/token, scopes=[https://www.googleapis.com/auth/firebase.messaging], defaultScopes=[], serviceAccountUser=null, quotaProjectId=null, lifetime=3600, useJwtAccessWithScope=false, defaultRetriesEnabled=true}
java.lang.NullPointerException
at TrOauth2.getAccessToken (TrOauth2.java:43)
at TrOauth2.main (TrOauth2.java:29)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
at java.lang.Thread.run (Thread.java:835)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
When I run program through command line, I get this, without the googleCredentials line being printed:
C:\Users\administrator\Documents\NetBeansProjects\TrOauth2\target\classes>"c:\progra~1\java\jdk-12~1.1\bin\java" TrOauth2
Hello World!
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/auth/oauth2/GoogleCredentials
at TrOauth2.getAccessToken(TrOauth2.java:41)
at TrOauth2.main(TrOauth2.java:29)
Caused by: java.lang.ClassNotFoundException: com.google.auth.oauth2.GoogleCredentials
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
How is this happening, or what might I be doing wrong? Any ideas would be appreciated.

Spring Cloud Contract org.junit.ComparisonFailure: expected: <[200]> but was:<[404]> while running tests

I've setup a sample project to use Spring Cloud Contract 2.0.0.RC1 just to get it working. When I run the tests I receive the error message:
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.188 sec <<< FAILURE!
validate_shouldGetProfile(com.example.contractdemoserver.ContractdemoserverTest) Time elapsed: 0.443 sec <<< FAILURE!
org.junit.ComparisonFailure: expected:<[200]> but was:<[404]>
at com.example.contractdemoserver.ContractdemoserverTest.validate_shouldGetProfile(ContractdemoserverTest.java:27)
The project builds and runs fine otherwise. I've tried numerous things to resolve this test error including checking to see if the ContractVerifieriBase is being called by adding a System.out.println() message to Contractdemoserverbase.setup() (see below), and it is being called.
I've been trying to follow/emulate just the producer project from here (which runs and tests fine):
https://github.com/spring-cloud-samples/spring-cloud-contract-samples
What am I doing wrong?
Project Structure is laid out in idea like so:
ContractdemoserverApplication:
package com.example.contractdemoserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class ContractdemoserverApplication {
public static void main(String[] args) {
SpringApplication.run(ContractdemoserverApplication.class, args);
}
}
ServerDefaultController:
package com.example.contractdemoserver;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
#Controller
public class ServerDefaultController {
public static final String controllerName = "test";
public static final String controllerPath = "/" + controllerName;
#RequestMapping(value = controllerPath, headers={"application/json"})
#ResponseBody
public TestObject get(){
return new TestObject(1001, new String[0]);
}
}
TestObject:
package com.example.contractdemoserver;
public class TestObject {
private int id;
private String[] cards;
public TestObject(){}
public TestObject(int id, String[] cards){
setId(id);
setCards(cards);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String[] getCards() {
return cards;
}
public void setCards(String[] cards) {
this.cards = cards;
}
}
ContractdemoserverBase:
package com.example.contractdemoserver;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#SpringBootTest
public abstract class ContractdemoserverBase {
#Before
public void setup() {
RestAssuredMockMvc.standaloneSetup(new ServerDefaultController());
}
}
shouldGetProfile.groovy:
package contracts.contractdemoserver
import org.springframework.cloud.contract.spec.Contract
Contract.make {
description("""
Represents a successful scenario of getting a response from the /test endpoint.
```
given:
nothing
when:
a request for a Test is made
then:
returns a test object with id 1001 and no cards
```
""")
request {
method 'GET'
url '/test'
headers {
contentType(applicationJson())
}
}
response {
status 200
body("""
{
"id":1001,
"cards":[]
}
""")
headers {
contentType(applicationJson())
}
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>contractdemoserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>server</name>
<description>POC Server for Service Contract Testing</description>
<properties>
<docker-maven-plugin-version>0.25.0</docker-maven-plugin-version>
<java.version>1.8</java.version>
<maven-resources-plugin.version>3.0.2</maven-resources-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot-dependencies-version>2.0.1.RELEASE</spring-boot-dependencies-version>
<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
<spring-cloud-contract.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.2.RELEASE</version>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<!-- <baseClassForTests>com.example.contractdemoserver.ContractVerifierBase</baseClassForTests> -->
<packageWithBaseClasses>com.example.contractdemoserver</packageWithBaseClasses>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/plugins-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/plugins-release-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Any suggestions would be greatly appreciated.
The method #RequestMapping(value = controllerPath, headers={"application/json"}) is missing/requires the property produces = "application/json" in order for Contract testing to work. Classic Spring feedback.

Swagger 2 + Spring MVC + WAS 8.5.5 throwing java.lang.VerifyError: JVMVRFY013 for AOP classes

I am new to swagger, and trying to integrate swagger2 with my Spring MVC (4.3.10 release) application which will be deployed into WAS 8.5.5. At the time of application startup, I am getting the below error,
Caused by: java.lang.VerifyError: JVMVRFY013 class loading constraint violated; class=org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint, method=getSourceLocation()Lorg/aspectj/lang/reflect/SourceLocation;, pc=0
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:85)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:162)
at org.springframework.aop.aspectj.AspectJAroundAdvice.lazyGetProceedingJoinPoint(AspectJAroundAdvice.java:81)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
My swagger configurations are as below,
Added swagger dependencies in pom.xml
<!-- Swagger dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
Added below annotations to my controller classes/operations
#Api(value="someController", description="services API")
#ApiOperation(value = "someOperation")`
Swagger reource configuration in applicationContext.xml
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<mvc:resources mapping="/swagger-ui.html" location="classpath:/META-INF/resources/swagger-ui.html"/>
<mvc:default-servlet-handler/>
<bean id="swagger2Config" class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"/>
SwaggerConfig class
#Configuration
#EnableSwagger2
public class SwaggerConfig {
#Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("TITLE")
.description("Description")
.version("1.0")
.build();
}
}
Any help on this would be greatly appreciated. Thanks

EJB remote lookup namenotfoundexception

I try to remotely access an EJB in an (eclipse) EJB-Project, packaged as a jar, deployed on a WildFly 10.1.0 Final. The server side is no maven-project, so i added ejb-3.0.jar, javaee-api-7.0.jar, jboss-ejb3-ext-api-1.1.0.jar to the java build path.
My server code is:
package org.maometto.api;
public interface IMyBeanRemote {
void sayHello();
}
package org.maometto.businesslogic;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import org.maometto.api.IMyBeanLocal;
import org.maometto.api.IMyBeanRemote;
#Stateless
#Remote(IMyBeanRemote.class)
public class MyBeanImpl implements IMyBeanRemote {
#Override
public void sayHello() {
System.out.println("I am Server");
}
}
When I start the server from within eclipse the log shows:
21:06:19,015 INFO [org.jboss.as.ejb3.deployment] (MSC service thread
1-4) WFLYEJB0473: JNDI bindings for session bean named 'MyBeanImpl' in
deployment unit 'deployment "MyFirstEJB.jar"' are as follows:
java:global/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote java:app/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote
java:module/MyBeanImpl!org.maometto.api.IMyBeanRemote
java:jboss/exported/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote
java:global/MyFirstEJB/MyBeanImpl java:app/MyFirstEJB/MyBeanImpl
java:module/MyBeanImpl
My Client - a converted maven project in an own project- code is as follows:
package com.maometto.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.maometto.api.IMyBeanRemote;
public class EJbClient {
public static void main(String[] args) {
Properties jndiProps = new Properties();
//jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProps.put("jboss.naming.client.ejb.context", true);
try {
InitialContext initialContext = new InitialContext(jndiProps);
IMyBeanRemote iMyBeanRemote = (IMyBeanRemote) initialContext.lookup("java:global/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote");
iMyBeanRemote.sayHello();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
To get the remote interface in the client, i added the ejb-project to the java build path of the client project.
The POM of the client is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyEJBClient</groupId>
<artifactId>MyEJBClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<version>10.0.0.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-naming</artifactId>
<version>7.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<version>1.4.0.Final</version>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<version>4.0.8.Final</version>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>11.0.0.Final</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I execute the client, i get following stacktrace in the log:
javax.naming.NameNotFoundException: global/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote -- service jboss.naming.context.java.jboss.exported.global.MyFirstEJB."MyBeanImpl!org.maometto.api.IMyBeanRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I tried it with the other jndiBindings as well.
I also tried it with the "ejb:" namespace and its convention ("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName). Still same error. I don't know what I'm missing or what I'm doing wrong.
Can anyone help me, please?

google cloud storage tried to access method com.google.cloud.ServiceOptions.getFromServiceLoader error

I am trying to test google cloud storage in local mvn jetty server.
defining the following java servlet I get the following error during servlet initiallization.
#WebServlet(name = "receiveImage", value = "receiveImage")
#SuppressWarnings("serial")
#MultipartConfig()
public class receiveImage extends HttpServlet {
private static final String BUCKET_NAME = "testbucket";
private static Storage storage = null;
#Override
public void init() {
storage = StorageOptions.defaultInstance().service();
}
HTTP ERROR 500
Problem accessing /receiveImage. Reason:
Server Error
Caused by:
java.lang.IllegalAccessError: tried to access method com.google.cloud.ServiceOptions.getFromServiceLoader(Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object; from class com.google.cloud.HttpServiceOptions
at com.google.cloud.HttpServiceOptions.(HttpServiceOptions.java:154)
at com.google.cloud.storage.StorageOptions.(StorageOptions.java:69)
at com.google.cloud.storage.StorageOptions.(StorageOptions.java:27)
at com.google.cloud.sto
i define the following maven dependency in pom file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>0.4.0</version>
</dependency>
Appreciate for helps.
I could resolve the issue:
there is a conflict between these two dependencies:
dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>0.5.1</version>
</dependency>
I just changed the first dependency to
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
<version>0.5.1</version>
</dependency>

Resources