0

I have the following controller method:

@RequestMapping(method = RequestMethod.GET, value = "/account/{loginId:.+}")
    public @ResponseBody CloudWebServiceResponse getLogin(@PathVariable(value = "loginId") String loginId) throws CloudWebServiceInvocationException {
        return internalService.getLogin(progressId);
    }

When is pass loginId as "abc.com", it gives 406 status code otherwise its working perfectly fine.

I have the following WebConfig file:

@Configuration
@Import(HibernateConfig.class)
@EnableWebMvc
// @EnableAsync()
// @EnableAspectJAutoProxy
@ComponentScan(basePackages = "com.azim.web.service.*",  basePackageClasses = { WebSecurityConfig.class }, excludeFilters = { @ComponentScan.Filter(Configuration.class) })
public class WebConfig extends WebMvcConfigurationSupport {

    @Override
    protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useJaf(false).defaultContentType(MediaType.APPLICATION_JSON)
                .mediaType("xml", MediaType.APPLICATION_XML).mediaType("json", MediaType.APPLICATION_JSON).mediaType("html", MediaType.APPLICATION_JSON);
    }

    @Bean(name = "validator")
    public Validator validator() {
        return new LocalValidatorFactoryBean();
    }
}

Its sending 406 status code for only .com and not for .randomvalue. I tried adding jackson-core-asl and jackson-databind-asl jars suggested by other threads on stackoverdflow but nothing works for me. Please help to sort out this issue.

Azim
  • 1,043
  • 13
  • 27

1 Answers1

0

Finally, I got the solution.

Instead of extending to WebMvcConfigurationSupport class it should extend to WebMvcConfigurerAdapter. Then the code becomes:

@Configuration

@Import(HibernateConfig.class)
@EnableWebMvc
// @EnableAsync()
// @EnableAspectJAutoProxy
@ComponentScan(basePackages = "com.azim.web.service.*",  basePackageClasses = { WebSecurityConfig.class }, excludeFilters = { @ComponentScan.Filter(Configuration.class) })
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useJaf(false).defaultContentType(MediaType.APPLICATION_JSON)
                .mediaType("xml", MediaType.APPLICATION_XML).mediaType("json", MediaType.APPLICATION_JSON).mediaType("html", MediaType.APPLICATION_JSON);
    }

    @Bean(name = "validator")
    public Validator validator() {
        return new LocalValidatorFactoryBean();
    }
}
Azim
  • 1,043
  • 13
  • 27