从angular调用JavaEE rest服务
我试图从Angular工厂调用JavaEE6REST服务,但遇到了一些问题 JavaREST服务是由其他人创建的,我正在尝试使用它,但我对JavaEE还不是非常精通,所以如果您需要更多信息,我会尽我所能提供从angular调用JavaEE rest服务,java,angularjs,rest,java-ee-6,Java,Angularjs,Rest,Java Ee 6,我试图从Angular工厂调用JavaEE6REST服务,但遇到了一些问题 JavaREST服务是由其他人创建的,我正在尝试使用它,但我对JavaEE还不是非常精通,所以如果您需要更多信息,我会尽我所能提供 @Path("bills") public class BillResource { @EJB @Resource private BillableEventBean billableEventBean; private final BillableEventMapper billabl
@Path("bills")
public class BillResource {
@EJB
@Resource
private BillableEventBean billableEventBean;
private final BillableEventMapper billableEventMapper = new BillableEventMapper();
BillService implementation not working
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("query")
public List<BillableEventDuplicate> listBillableEvents(BillableEventQueryFilter queryFilter) {
List<BillableEvent> ejbRet = billableEventBean.listBillableEvents(queryFilter.getUserID(),
queryFilter.getBillingTeamID(), queryFilter.getBillStatus(), null);
List<BillableEventDuplicate> ret = billableEventMapper.toBillableEventDuplicateList(ejbRet);
return ret;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{billableEventI}")
public BillableEventDuplicate getBillableEvent(@PathParam("billableEventI") String id) {
BillableEvent ejbRet = billableEventBean.getBillableEvent(id);
BillableEventDuplicate ret = billableEventMapper.toBillableEventDuplicate(ejbRet);
return ret;
}
}
因此,从控制器调用中的工厂:
'use strict';
angular.module('app.bills', ['ngRoute','appBills'])
.config(['$routeProvider', function($routeProvider)
{
$routeProvider.
when('/bills',
{
templateUrl: 'bills/bill-list.html',
controller: 'BillListCtrl'
}).
when('/bills/:billId',
{
templateUrl: 'bills/bill-detail.html',
controller: 'BillDetailCtrl'
}).
when('/billsearch',
{
templateUrl: 'bills/bill-search.html',
controller: 'BillSearchCtrl'
});
}])
.controller('BillListCtrl', ['$scope', '$http', '$routeParams', 'Bills',
function($scope, $http, $routeParams, Bills)
{
Bills.getList({},{}).$promise.then(function(billList)
{
$scope.billList = billList;
});
}])
.controller('BillDetailCtrl', ['$scope', '$http', '$routeParams', 'Bills',
function($scope, $http, $routeParams, Bills)
{
Bills.get({},{billNumber: $routeParams.billNumber }).$promise.then(function(bill)
{
$scope.bill = bill;
});
}]);
据我所知,我需要在工厂中创建一个自定义操作,以利用
URL
选项,因为有一个POST
可以使用相同的根调用获取票据列表。我遇到的问题是,即使使用Consumes
注释,我似乎也无法将任何参数输入queryFilter
对象。我到底做错了什么吗?首先,你可以使用chrome插件Postman检查你的rest服务是否正常工作,如果是真的,你的angular$资源有问题。我认为您的请求中缺少标题“Content Type=application/json”。我从来没有这样使用过angular,您可以尝试创建这样的服务(教程也应该很有帮助)
所以,事实证明,这一直是一个基础设施问题。我们已经部署到WebSphereLiberty服务器,它不包含JavaEE6识别rest服务所需的整个WebProfile。它们可能是一些解决方案,但最快的短期解决方案是运行完整的Websphere服务器进行部署 谢谢你的帮助
'use strict';
angular.module('app.bills', ['ngRoute','appBills'])
.config(['$routeProvider', function($routeProvider)
{
$routeProvider.
when('/bills',
{
templateUrl: 'bills/bill-list.html',
controller: 'BillListCtrl'
}).
when('/bills/:billId',
{
templateUrl: 'bills/bill-detail.html',
controller: 'BillDetailCtrl'
}).
when('/billsearch',
{
templateUrl: 'bills/bill-search.html',
controller: 'BillSearchCtrl'
});
}])
.controller('BillListCtrl', ['$scope', '$http', '$routeParams', 'Bills',
function($scope, $http, $routeParams, Bills)
{
Bills.getList({},{}).$promise.then(function(billList)
{
$scope.billList = billList;
});
}])
.controller('BillDetailCtrl', ['$scope', '$http', '$routeParams', 'Bills',
function($scope, $http, $routeParams, Bills)
{
Bills.get({},{billNumber: $routeParams.billNumber }).$promise.then(function(bill)
{
$scope.bill = bill;
});
}]);
app.service("billsService", function ($resource) {
var bills = $resource("/ua_appcore/api/v1/bills/query");
this.getBills = function () {
var billsResource = new bills();
billsResource.sampleVar = 'value'; // here you can place your vars
return billsResource.$save();
}
});