i am getting a 406 error while running the below code on my localhost:-
Controller Code:-
//imports
import AvailabilityReportService;
import SAvailabilityReport;
@Controller
@RequestMapping("/service/*")
public class SAvailabilityController {
@Autowired
@Qualifier("AvailabilityReportService")
private AvailabilityReportService availabilityReportService;
@RequestMapping(value = "/{cat}", method = RequestMethod.GET)
public @ResponseBody
SAvailabilityReport getAvailabilityReport(@PathVariable String cat) {
try
{
return availabilityReportService.generateAvailabilityReport(cat);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
The Availability Report Service Class:-
import SAvailabilityReport;
public interface AvailabilityReportService {
public SAvailabilityReport generateAvailabilityReport(String cat) throws Exception;
}
Now the availabilityreportserviceimpl class that implements the above class:-
//The required imports
@Service("AvailabilityReportService")
public class AvailabilityReportServiceImpl implements AvailabilityReportService {
private @Value("${username}")
String username;
private @Value("${password}")
String password;
private @Value("${username1}")
String username1;
private @Value("${password1}")
String password1;
private PropertiesConfiguration propConfig;
@PostConstruct
public void initIt() throws Exception {
String propertiesFile = "/META-INF/common.properties";
propConfig = new PropertiesConfiguration(this.getClass().getResource(
propertiesFile));
propConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
}
public SAvailabilityReport generateAvailabilityReport(String cat)
throws Exception {
String user;
String pass;
String time;
if (cat == null)
return null;
String url = (String) propConfig.getProperty("s_"
+ cat.toLowerCase());
if (url == null)
return null;
SAvailabilityReport availabilityReport = new SAvailabilityReport();
if((cat.toLowerCase()).equals("h") || (cat.toLowerCase()).equals("f"))
{
user=username;
pass=password;
}
else
{
user=username1;
pass=password1;
}
WebClient webClient = provideCredentials(user,pass);
HtmlPage resultPage = webClient.getPage(url);
HtmlTable resultTable = (HtmlTable) resultPage.getByXPath(
"//table[@class='data']").get(0);
List<HtmlTableRow> rowsList = resultTable.getRows();
int rowsSize = rowsList.size();
time=(resultTable.getCellAt((rowsSize-1),1)).asText();
availabilityReport.settime(time);
return availabilityReport;
}
private WebClient provideCredentials(String username, String password) {
WebClient webClient = new WebClient();
DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient
.getCredentialsProvider();
credentialsProvider.addCredentials(username, password);
return webClient;
}
Finally the savailabilityreport class is:-
//imports
public class SAvailabilityReport {
private String time;
public SAvailabilityReport()
{
}
public void settime(String time)
{
this.time=time;
}
}
I had done some research about entering the jackson-core-asl and jackson-mapper-asl into my pom.xml, and also .I have done those but still the same 406 error.. The url from which i am getting the value has been defined in the common.proprties file along with the username and password.