mvc:annotation-driven doesnt solve 406 error - java

I am trying to write a Junit test case for Spring and after a lot of reading I got everything working for a method that returns text/plain. When I tried to return application/json I ran into issues.
The consensus on SO seems to be: use mvc:annotation-driven. I tried this (by creating spring-web-servlet.xml shown below according to here. That didn't solve my issue however. Anyone know what I'm still doing wrong?
spring-web-servlet.xml (in WEB-INF folder)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans>
The method in question (in class HelloService)
#GET
#RequestMapping("/json2")
#Produces({"application/json"})
#ResponseBody
public Object getUserInfoJSON(#RequestParam(value="p",defaultValue="0") Integer userId){
try (Connection conn = conn()) {
String query = "SELECT * FROM pulse.customer WHERE userId = ?";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setInt(1, userId);
ResultSet rs=preparedStmt.executeQuery();
if(rs.next())
return Json.createObjectBuilder().add("login name", rs.getString("loginName"));
return Json.createObjectBuilder().add("login name", "shit broke yo!!!");
}
catch(SQLException s){
return "sql exception:"+s.toString();
}
catch (NoResultException nre) {
//throw new UserNotFoundException(userId);
return "UserNotFoundException";
} catch (PersistenceException e) {
//throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
return "WebApplicationException";
}
}
The Junit test method (the version that takes in String works perfectly)
#Test
public void testUserInfoResponseJSON() throws Exception{
MvcResult result=mockMvc.perform(get("/helloservice/json2?p=103")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith("application/json"))
.andReturn();
String content = result.getResponse().getContentAsString();
assertNotNull(content,"{login name:jbray}");
}
If needed, heres my pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<!-- Adding RESTEasy support to Bean Validations -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-validator-provider-11</artifactId>
<version>3.1.4.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-links -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-links</artifactId>
<version>3.1.4.Final</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<!--SPRING-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.paypal.springboot</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>2.3.3-RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!--JUNIT-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.0.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

I saw your dependency and your code in detail and found that you are using Glassfish's provider implementation of the JSR 353. those classes are org.glassfish.json.JsonObjectBuilderImpl$JsonObjectImpl, org.glassfish.json.JsonStringImpl, and org.glassfish.json.JsonNumberImpl, and javax.json.JsonValue$3 (an anonymous class for the value FALSE).
You need to change below code
return Json.createObjectBuilder().add("login name", rs.getString("loginName"));
return Json.createObjectBuilder().add("login name", "shit broke yo!!!");
to
return Json.createObjectBuilder().add("login name", rs.getString("loginName")).build().toString();
return Json.createObjectBuilder().add("login name", "shit broke yo!!!").build().toString();
and change return type of to getUserInfoJSON() method to String. Detailed explanation of JSR 353 classes and it mapping to ObjectMapper is available at https://stackoverflow.com/a/19205116/3530898

Related

NullPointerException on JerseyTest.target

I'm trying to test controller with Jersey and get NullPointerExcetion on target().
Here is my pom.xml
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<slf4j.version>1.7.26</slf4j.version>
<persistence-api.version>1.0.2</persistence-api.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<lombok.version>1.18.22</lombok.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<ojdbc6.version>11.2.0.4</ojdbc6.version>
<spring.version>4.2.4.RELEASE</spring.version>
<jersey.version>2.26</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<!-- Spring Test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.4.6</version>
<scope>test</scope>
</dependency>
<!-- Hamcrest assertions -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<!-- AssertJ assertions -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-inmemory</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
and test class
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.*;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.*;
public class EndpointTest extends JerseyTest {
#Override
protected Application configure() {
return new ResourceConfig(Endpoint.class);
}
#Test
void whenTestThenOK() {
Response response = target("/endpoint")
.request()
.post(Entity.json("{}"));
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
}
On javax.ws.rs-api version 2.0.1, there was a NoClassDefFoundError error on javax/ws/rs/client/RxInvokerProvider. I changed it to 2.1 and now I get NPE.
Also, I tried to add other dependencies, change versions, but even such a simple test cannot be run
Please help me.
What is the expected body (json entity)? Try with at least one...
.post(Entity.json("{"name":"value"}"));
It seems that you are sending (post) an empty body.

after importing spring-aspects,some controller not found

I write 2 controllers--GoodController and UserController, after importing spring-aspects, my UserController url 404, but GoodController is normal, I can't find the reason and don't know how to resolve. All my pom.xml is bellow:
project parent pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<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-test</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.43</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!--shiro-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<!--shiro-web-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.4.0</version>
</dependency>
<!--shiro-spring-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.0</version>
</dependency>
<!--shiro缓存-->
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-ehcache -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>1.4.0 </version>
</dependency>
<!-- swagger生成接口API -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- 接口API生成html文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<!-- StringUtils -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
<!-- log :slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!--json:fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
</dependencies>
user module pom.xml:-- no dependency
good module pom.xml
<dependencies>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
ApplicationStarter module pom.xml
<dependencies>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>good</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>top.lovely6</groupId>
<artifactId>user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
common module pom.xml:-- no dependency
UserController.java
#RestController
#RequestMapping("/user")
#EnableSwagger2
public class UserController {
#Resource
private UserService userService;
#RequiresRoles("admin")
#RequiresPermissions("create")
#PostMapping("")
#ResponseBody
public User createUser(#RequestBody User user) {
user.setCreateTime(new Date());
userService.save(user);
System.out.print(user);
return user;
}
//...
}
and GoodController is almost same as UserController.
log aop config:
#Slf4j
#Aspect
#Component
public class SysLogAspect {
#Pointcut("#annotation(top.lovely6.annotation.SysLog)")
public void logPointCut() {
}
#Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
long beginTime = System.currentTimeMillis();
//执行方法
Object result = point.proceed();
//执行时长(毫秒)
Long time = System.currentTimeMillis() - beginTime;
log.info(time.toString());
return result;
}
//...
}

#RequestBody annotation not working in Spring and give NoSuchMethodError erro

Through angular I am sending update request to SPRING in controller I have method to map this request but in this #RequestBody not able to map to my class and give
Error:
**2017-10-06 12:42:43.496 ERROR 5856 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.type.TypeFactory.constructType(Ljava/lang/reflect/Type;Ljava/lang/Class;)Lcom/fasterxml/jackson/databind/JavaType;] with root cause**
**java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.type.TypeFactory.constructType(Ljava/lang/reflect/Type;Ljava/lang/Class;)Lcom/fasterxml/jackson/databind/JavaType;**
**at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.getJavaType(AbstractJackson2HttpMessageConverter.java:319) ~[spring-web-4.2.7.RELEASE.jar:4.2.7.RELEASE]**
**at org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter.canRead(TypeConstrainedMappingJackson2HttpMessageConverter.java:63) ~[spring-hateoas-0.19.0.RELEASE.jar:na]**
But I have check in com.fasterxml.jackson.databind.type.TypeFactory class their is method
#Deprecated
public JavaType constructType(Type type, Class<?> contextClass) {
TypeBindings bindings = (contextClass == null)
? TypeBindings.emptyBindings() : constructType(contextClass).getBindings();
return _fromAny(null, type, bindings);
}
Angular Request Code
function updateActivityByActivityID(ENDPOINTS, ActivityID, bodyJSON) {
var url = ENDPOINTS.SERVICE_ADDRESS
+ ENDPOINTS.UPDATE_ACTIVITY_BY_ACTIVITY_ID
+ ActivityID;
return HttpHandler.PUT(url, bodyJSON);
}
url : http://localhost:8080/Integration/Activity/updateCron/14
bodyJSON : cronExpression: "0 0/1 * 1/1 * ? *"
Controller Code
#ApiOperation(value = "update Activity scheduled expression")
#RequestMapping(method = RequestMethod.PUT, path = "/Integration/Activity/updateCron/{activityID}", produces = "application/json")
#ApiResponses(value = {
#ApiResponse(code = 200, message = "Success", response = String.class),
#ApiResponse(code = 401, message = "Unauthorized"),
#ApiResponse(code = 403, message = "Forbidden"),
#ApiResponse(code = 404, message = "Not Found"),
#ApiResponse(code = 500, message = "Failure") })
#ResponseBody
public IntegrationProcessResultVO updateActivityScheduledExpression(
#PathVariable("activityID") Long activityID,
#RequestBody ScheduledSetupVO scheduledSetupVO)
throws ActivityNotFoundException, IOException,
ActivitySchedulerException {
System.out.println("Activity ID : "+activityID);
System.out.println("Request Body : "+scheduledSetupVO);
IntegrationProcessResultVO integrationProcessResultVO = activityService
.updateActivityCronExpression(activityID, scheduledSetupVO);
return integrationProcessResultVO;
}
ScheduledSetupVO Class
package com.data.integration.service.vo;
public class ScheduledSetupVO {
private String cronExpression;
public ScheduledSetupVO(String cronExpression) {
super();
this.cronExpression = cronExpression;
}
public ScheduledSetupVO() {
super();
// TODO Auto-generated constructor stub
}
public String getCronExpression() {
return cronExpression;
}
public void setCronExpression(String cronExpression) {
this.cronExpression = cronExpression;
}
#Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
}
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>
<name>dataintegrationservice</name>
<description>Data Integration</description>
<url>http://iquantifi.com/</url>
<groupId>com.data.integration</groupId>
<artifactId>dataintegrationservice</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<!-- Configures repository location for pentaho libraries -->
<repositories>
<repository>
<id>pentaho-releases</id>
<url>https://public.nexus.pentaho.org/content/groups/omni/</url> <!-- Location changed Previous - http://repository.pentaho.org/artifactory/repo/ -->
</repository>
<repository>
<id>clojars-releases</id>
<url>http://clojars.org/repo/</url>
</repository>
</repositories>
<!-- lookup parent from repository -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<pentaho.kettle.version>6.1.0.0-192</pentaho.kettle.version>
<vertx.version>3.3.0</vertx.version>
<commons.lang.version>3.4</commons.lang.version>
<jtds.version>1.3.1</jtds.version>
<pentaho-reporting-version>6.1.0.1-196</pentaho-reporting-version>
<quartz.version>2.2.3</quartz.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-dbcp</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.7</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.7</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
<!-- pentaho libraries -->
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>${pentaho.kettle.version}</version>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
<version>${pentaho.kettle.version}</version>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-ui-swt</artifactId>
<version>${pentaho.kettle.version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libformula</artifactId>
<version>${pentaho.kettle.version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libbase</artifactId>
<version>${pentaho.kettle.version}</version>
</dependency>
<!-- Jar required for Pentaho Transformation/job -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>jsonpath</groupId>
<artifactId>jsonpath</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>2.5.15</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>com.enterprisedt</groupId>
<artifactId>edtFTPj</artifactId>
<version>2.1.0</version>
</dependency>
<!-- pentaho reporting -->
<!-- Start pentaho reporting jar dependencies -->
<dependency>
<groupId>pentaho-reporting-engine</groupId>
<artifactId>pentaho-reporting-engine-classic-core</artifactId>
<version>${pentaho-reporting-version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>pentaho-reporting-engine</groupId>
<artifactId>pentaho-reporting-engine-classic-extensions</artifactId>
<version>${pentaho-reporting-version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libdocbundle</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libfonts</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libformat</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libloader</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>librepository</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libserializer</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libxml</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libswing</artifactId>
<version>${pentaho-reporting-version}</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>net.sourceforge.stripes</groupId>
<artifactId>stripes</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.7R3</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.15</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>bsh</groupId>
<artifactId>bsh</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.barbecue</groupId>
<artifactId>barbecue</artifactId>
<version>1.0.6d</version>
</dependency>
<dependency>
<groupId>bsf</groupId>
<artifactId>bsf</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libsparkline</artifactId>
<version>5.0.3</version>
</dependency>
<!-- end of Jar required for Pentaho Transformation/job -->
<!-- Apache commons util libraries -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<!-- Apache commons util libraries end -->
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
</dependency>
<!-- end Swagger UI -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<!-- Quartz Scheduler -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<!-- Neo4j JDBC Driver -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-jdbc-driver</artifactId>
<version>3.0</version>
</dependency>
<!-- MySQL connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- for NoSuchMethod Error while executing jar -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version><!--$NO-MVN-MAN-VER$-->
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeDevtools>true</excludeDevtools>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
<scm>
<url>https://bitbucket.org/kscloud/dataintegrationservice.git</url>
<connection>scm:git:https://kaniket_kanaka#bitbucket.org/kscloud/dataintegrationservice.git</connection>
<developerConnection>scm:git:https://kaniket_kanaka#bitbucket.org/kscloud/dataintegrationservice.git</developerConnection>
</scm>
If I removed the #RequestBody from the controller method then it is working fine
You are using an incompatible Jackson version. You are managing the version yourself don't do that.
Either remove the following dependencies from your pom.xml the spring-boot-starter-web already adds them. :
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version><!--$NO-MVN-MAN-VER$-->
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
Or at least remove the <version> tag from the dependencies so that Spring Boot can manage the version.

Spring Integration JDBC Insert Statement

I'm new to Spring integration. I'm trying to write a POJO for my database. I'm getting this error, which I don't quite understand. Is my syntax wrong, or am I using channels/adapters/gateways in the wrong manner?
no declaration can be found for element int-jdbc:outbound-channel-adapter.
Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:util="http://www.springframework.org/schema/util" xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xsi:schemaLocation="http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<int-jdbc:outbound-gateway id="transmissionGateway"
query="insert into MSRB_RTRS (Sec_ID, SourceLoad_ID, TradeDate) values (:Sec_ID,
:SourceLoad_ID, :TradeDate)"
data-source="rmsa">
</int-jdbc:outbound-gateway>
public interface DatabaseService {
public void insertMessage(int secID, int sourceLoadID, String tradeDate);
}
#Inject
DatabaseService service;
service.insertMessage(-1, -1, "20170830");
Here are my dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jdbc</artifactId>
<version>4.3.5.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.0.8112.100</version>
</dependency>
<dependency>
<groupId>com.companyname</groupId>
<artifactId>spring-boot-common</artifactId>
<version>1.0.0.COMMON-SBCOMMON-14</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- End -->
<dependency>
<groupId>com.companyname</groupId>
<artifactId>companyname-spring-core-spring-4</artifactId>
<version>1.1-M20160505-01</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
The spring integration jdbc pom contains
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>4.3.5.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
spring-integration-jdbc-2.2.xsd
Don't put a version on the schema import. It has to match the version you are using (4.3).
If you leave the version off, Spring will resolve the right version for you (see /META-INF/spring.schemas in the jar).
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
In any case; everything (jars, schema) must have matching versions.

URI is not mapped with Controller in Spring REST

I am trying to build a REST API using Spring. The code gets compiled without any error. But when I hit the URI using POSTMAN I do not get any result. I checked and found that the controller is not mapping the request to the given URI. Here is my code:
APIController.java
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
#RestController
public class APIController {
APIService apiservice = new APIService();
#RequestMapping(value="/getPerson/{id}",method = RequestMethod.GET,headers="Accept=application/json")
public Person getPerson(#PathVariable #RequestBody int id) throws ParseException {
System.out.println("Inside get method");
Person person=apiservice.getPersonInfo(id);
return person;
}
}
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>edu.cmpe275.lab2</groupId>
<artifactId>CMPE275Lab2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CMPE275Lab2</name>
<description>CMPE275Lab2 project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>CMPE275Lab2.CMPE275Lab2Application</start-class>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<!-- twilio sms api -->
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio-java-sdk</artifactId>
<version>3.4.5</version>
</dependency>
<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<!-- Mongodb driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
<!-- Bean Copyutils -->
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.commons- beanutils</artifactId>
<version>1.8.3_2</version>
</dependency>
<!-- Joda time if java <= 1.7, not needed for java 1.8 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- servlet container provided dependencies -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.30</version>
<scope>provided</scope>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>net.wimpi</groupId>
<artifactId>telnetd-x</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
URI Mapping is in the APIController class, which is not being called.
Please advice.

Categories