Ich rufe einen Spring Boot REST Service von meinem eckigen UI. Es funktionierte gut, solange der Spring Boot Rest Service als Spring Boot App ausgeführt wurde. Aber sobald ich es in eine WAR-Datei konvertiert und auf einem Jboss 6.2.4-Server implementiert habe, bekomme ich 404. Ich sehe, dass der REST-Service-Aufruf von der UI erfolgreich ist, aber die Anfrage JSON nicht übergeben wird. Auf der Anfrage JSON übergebe ich 2 Strings und eine hochgeladene Excel-Datei.Angular http und Spring Boot Rest Service
Dies ist mein Winkel UI http Aufruf
App.service('getHeatMapDataService', ['$http', '$q', function ($http, $q) {
this.getHeatMapData = function (scope) {
var url = 'http://localhost:8080/rest-services/fusiontables/upload';
var deferred = $q.defer();
$http({
method: 'POST',
url: url,
headers: {
'Content-Type': undefined
},
data: {
stateCd: scope.stateCd,
addressExtras: scope.addressExtras,
uploadFile: scope.upFile
},
transformRequest: function (data, headersGetter) {
var formData = new FormData();
angular.forEach(data, function (value, key) {
formData.append(key, value);
});
var headers = headersGetter();
delete headers['Content-Type'];
return formData;
}
})
.success(function (data) {
deferred.resolve(data);
console.log("Success");
console.log(data);
})
.error(function (data, status) {
deferred.reject(status);
console.log("Failed");
});
return deferred.promise;
}
}]);
Das ist mein Frühling Boot Rast Controller, wenn es funktioniert
@RequestMapping(value="/upload", method=RequestMethod.POST)
@ResponseBody
public String getBoundaries(HeatMapUploadCommand uploadCommand) {
logger.info("Heat Map Controller invoked " + uploadCommand);
return null;
}
Dies ist mein Upload-Befehl
public class HeatMapUploadCommand {
private String stateCd;
private String addressExtras;
private MultipartFile uploadFile;
Nach i Auf Jboss implementiert, trifft die Anfrage immer noch die Spring Boot App, aber dann hat sie alle Anfrageparameter als null.
Dies ist die Anfrage-Payload
------WebKitFormBoundaryvCCnl3nhIgoW1MwR
Content-Disposition: form-data; name="stateCd"
CA
------WebKitFormBoundaryvCCnl3nhIgoW1MwR
Content-Disposition: form-data; name="addressExtras"
1234
------WebKitFormBoundaryvCCnl3nhIgoW1MwR
Content-Disposition: form-data; name="uploadFile"; filename="CAdata.xlsx"
Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet
------WebKitFormBoundaryvCCnl3nhIgoW1MwR--
ich als
Änderung der Controller versucht@RequestMapping(value="/upload", method=RequestMethod.POST)
@ResponseBody
public String getBoundaries(@RequestParam(value="stateCd") String stateCd,
@RequestParam(value="addressExtras") String addressExtras,
@RequestParam(value="uploadFile") MultipartFile file) {
System.out.println("Heat Map Controller invoked " + stateCd);
return null;
}
Noch kein Glück. Das ist die Antwort, die ich bekommen habe.
{"timestamp":1464840821648,"status":400,"error":"Bad Request","exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required String parameter 'stateCd' is not present","path":"/rest-services/fusiontables/upload"}
Jetzt bekomme ich HTTP-Status 415 nicht unterstützten Medientyp. {"timestamp": 1464874683832, "status": 415, "error": "Nicht unterstützter Medientyp", "Ausnahme": "org.springframework.web.HttpMediaTypeNotSupportedException", "message": "Inhaltstyp" multipart/form-data ; boundary = ---- WebKitFormBoundarymRKqwcUfa6CJzALs; charset = UTF-8 'nicht unterstützt "," Pfad ":"/rest-services/fusiontables/upload "} –