I am having a real tough time with this. I have done a ton a research and nothing has worked. Please help. I have a spring REST call and a jquery ajax PUT and POST method that both give a 400 bad request. I have done JSON.stringify, raw object data, everything. I can't seem to find what is wrong and the ONLY clue I have is one 400 bad request error with no stack trace, nothing about how it SHOULD be formatted...nothing. Is there a way I can get more information as to what is wrong? It does not even get to the first line in the spring REST method below.
Spring REST code:
@RequestMapping(value = "/supervisor/agent", method=RequestMethod.PUT)
public void updateAgent(@RequestBody AgentDTO agent)
{
try {
AgentDTO sessionAgent = (AgentDTO) session.getAttribute(ADAuthenticationSuccessHandler.SESSION_AGENT);
RestTemplate restTemplate = new RestTemplate();
log.debug("Supervisor updating agent:"+agent);
String allURL = acrURL+"/company/"+sessionAgent.getCompanyGuid()+"/supervisor/"+sessionAgent.getAgentGuid()+"/agent/"+agent.getAgentGuid();
log.debug("Supervisor updating agent url:"+allURL);
agent.setEnabled(Mytime.ENABLED);
restTemplate.put(allURL, agent);
log.debug("Supervisor Agent updated");
} catch (Exception e) {
log.error("Error supervisor updating agent");
e.printStackTrace();
}
}
Here is the JQuery ajax call:
function editAgent()
{
console.log("edit agent");
console.log("chosenAgent:"+chosenAgent);
var anAgent = myAgents[chosenAgent];
anAgent.firstName = $('#SDEAFirstName').val();
anAgent.lastName = $('#SDEALastName').val();
anAgent.addressEmail = $('#SDEAEmail').val();
console.log(anAgent);
console.log(anAgent.agentGuid);
// var testData = '{"addressEmail": "agent7@csi.com","agentGuid": "EC165F8A-28F4-4765-BDC5-893722FCF6AA","firstName": "Agent","lastName": "0071","workStatus": "Offline}';
$.ajax({
type : 'PUT',
url : "/mytime.agentdesktop/supervisor/agent",
contentType : "application/json; charset=utf-8",
data: JSON.stringify(anAgent),
dataType : 'json',
success : function(result)
{
console.log("Agent edited:",anAgent.agentGuid);
init = false; // needed to reload agent data. Otherwise, it just grabs it but doesn't update gui
getMyAgents(); // reload agent data now that this agent was deleted
},
error : function(jqXHR, textStatus, errorThrown)
{
console.error("editAgent:status:"+textStatus+" error:", errorThrown);
}
});
editAgentDialog.dialog('close');
}