我发现了一些与我有关的问题,但是他们都没有帮我... 所以,我有webservice,我使用JERSEY来做。当我尝试使用ajax在其上发布一些数据时,它似乎甚至没有进入我的web服务(我有web服务的日志,并且没有任何地方出现任何调用)。
这是我的Java类:
@Path(WebConstants.VEHICLE_URI)
public class VehicleResource extends AbstractResource {
private static final Logger logger = LoggerFactory.getLogger(VehicleResource.class);
@POST
@Path(WebConstants.VEHICLE_GET_BY_USER)
@Consumes(MediaType.APPLICATION_JSON + CHARSET)
@Produces(MediaType.APPLICATION_JSON + CHARSET)
public Response getByUser(VehicleGetListForm form){
try {
logger.info("VehicleResource - getForUser - Start get vehicle for user.");
if (validator.hasErrors(form)) {
ValidationResponse validationResponse = validator
.getFieldErrors(form);
validationResponse.setMessage(MessageConstants.GENERIC_VALID);
return Response.ok(validationResponse).build();
}
List<ErrorMessage> errors = new ArrayList<ErrorMessage>();
String[] userTimestamp = rsaEncryption.decrypt(form.getUserTimeStamp()).split("\\ ");
String userGet = userTimestamp[0];
String userTime = userTimestamp[1];
if((userGet.length()<1) || (userGet.length()>64)){
ValidationResponse validationResponse = new ValidationResponse();
errors = new ArrayList<ErrorMessage>();
errors.add(new ErrorMessage("Usuário", MessageConstants.USER_INVALID_MESSAGE));
validationResponse.setErrorMessageList(errors);
validationResponse.setCode(2);
validationResponse.setMessage(MessageConstants.GENERIC_VALID);
return Response.ok(validationResponse).build();
}else{
User user = serviceLocator.getUserService().findByName(userGet);
if(user == null){
user = saveUser(userGet);
}
Long timeGet = Long.valueOf(userTime).longValue();
Timestamp timestampGet = new Timestamp(timeGet);
Boolean valid = validatorTimestamp.validateTimestampAuth(user.getDatLastAuth(), timestampGet);
if (valid){
authUser(user, false);
String typeVehicle = "";
Integer typeInt = Integer.parseInt(form.getType());
if(EnumVehicle.CAR.getValueInt().equals(typeInt))
typeVehicle = EnumVehicle.CAR.getValue();
else if(EnumVehicle.MOTO.getValueInt().equals(typeInt))
typeVehicle = EnumVehicle.MOTO.getValue();
else if(EnumVehicle.TRUCK.getValueInt().equals(typeInt))
typeVehicle = EnumVehicle.TRUCK.getValue();
// Valid type
if(typeVehicle.isEmpty()){
responseService.setCode(2);
responseService.setMessage(MessageConstants.VEHICLE_TYPE_INVALID);
return Response.ok(responseService).build();
}
List<Vehicle> vehicles = serviceLocator.getVehicleService().lisByUser(Integer.parseInt(form.getStart()), Integer.parseInt(form.getRows()), typeVehicle, user);
if (vehicles == null || vehicles.size() == 0){
responseService.setCode(1);
responseService.setMessage(MessageConstants.GENERIC_NOT_FOUND);
return Response.ok(responseService).build();
}
List<VehicleBean> list = VehicleBean.toListBean(vehicles);
VehicleReturnBean returnBean = VehicleReturnBean.toBean(list, user.getDatLastUpdate());
return Response.ok(returnBean).build();
}else{
responseService.setCode(2);
responseService.setMessage(MessageConstants.USER_INVALID_TIMESTAMP);
return Response.ok(responseService).build();
}
}
} catch (Exception e) {
logger.error("Error on get all State", e);
responseService.setException(MessageConstants.GENERIC_ERROR_MESSAGE);
}
return Response.ok(responseService).build();
}
这是我的AJAX:
$(document).ready(function() {
var dataJ = {"userTimeStamp":"3244a58ad474a924e915c77ecde54376c8985b0616a68b0a71a4d263a43d91dbfc7a9a4573510d546133b7a0ff26d2c2e58cd54939b8674a12f2ca59b8b803333b98726fbf09cf6a33dd53e47d683c0044b1d326a71c83e54dfdee3227d7de9ada24164ef8bd8580e9c200372ce1f62494cc2744161c4cf8a76a2b2605f1e859","brandmodel":"gol","type":"1","start":"1","rows":"10"};
$.ajax({
url: 'http://localhost:8280/rest/fipe/get/search',
type: 'POST',
data: JSON.stringify(dataJ),
dataType: 'json',
contentType: "application/json;charset=utf-8",
success: function(jqXHR, textStatus, errorThrown){
alert('Success');
},
error: function(jqXHR, textStatus, errorThrown){
alert("jqXHR - " + jqXHR.statusText + "\n" +
"textStatus - " + textStatus + "\n" +
"errorThrown - " + errorThrown);
}
});});
有人知道这里有什么问题吗?
我非常感谢你的关注。