我已将CDI功能添加到server.xml文件中<feature>cdi-1.2</feature>.
我的行家模块包含的beans.xml里面<module_name>/src/main/resources/META-INF的文件夹.
这是beans.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
Run Code Online (Sandbox Code Playgroud)
但是当我使用@Inject注释它不起作用时,我的bean总是如此null.
码:
package ch.webapp.presentation;
...
@Path("/test/")
public class MyController {
@Inject
private MyService myService;
@GET
@Path("/foo/{count}")
@OAuthSecurity(scope = "login")
@Produces("application/json")
public Response news(@PathParam("count") int count) {
return Response
.ok(myService.getBar(count))
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
那是我的豆子
package ch.webapp.service;
...
@RequestScoped
public class MyService {
public String getBar(int count) {
return "foo";
}
}
Run Code Online (Sandbox Code Playgroud)
我通过扩展MFPJAXRSApplication类来初始化jax-rs …
cdi websphere-liberty ibm-mobilefirst mobilefirst-adapters open-liberty
我有一个关于mobilefirst的大问题,当我尝试调用受保护的资源时,我遇到了这个问题:
问题仅在Android上,iOS完美运行.
evaluateJavascript = cordova.callbackFromNative('WLResourceRequestPlugin368975848',false,9,[{"status":400,"statusText":"Bad Request","responseText":"{\"errorCode \":\"invalid_client \",\ "errorMsg \":\"错误的JWT格式\"}","responseJSON":{"errorCode":"invalid_client","errorMsg":"不正确的JWT格式"},"responseHeaders":{"X-Powered-By ":" 的Servlet/3.1" , "内容类型": "应用/ JSON", "内容语言": "EN-US", "传输编码": "分块", "连线": "关闭", "日期":"2017年5月31日星期三16:13:55 GMT","OkHttp-Sent-Millis":"1496218412371","OkHttp-Received-Millis":"1496218412405"},"errorMsg":"JWT不正确格式", "的errorCode": "invalid_client"}],假);
问题是我检查了客户端的时间和服务器时间,它们是相同的,但是当我更改客户端时间并添加一天它就可以了!我该如何解决这个问题?
cordova okhttp ibm-mobilefirst mobilefirst-adapters mobilefirst-server
我正在使用mobilefirst平台v7,我使用WLResourceRequest/sendFormParameters api发送post请求,但是,我无法从js适配器端获取提交的参数...
以下是示例代码:
var resourceRequest = new WLResourceRequest("adapters/businessAdapter/flightsearch", WLResourceRequest.POST);
var params={
"flightNum":'mu8899',
"departCity":'SHA',
"destCity" :'PEK'
};
resourceRequest.sendFormParameters(params).then(
callSuccess,
callFailure
);
Run Code Online (Sandbox Code Playgroud)
js适配器代码:
function flightsearch(params) {
WL.Logger.info("get params "+params);
var input = {
method : 'post',
returnedContentType : 'json',
path : 'restapi/api/flightsearch',
body :{
contentType: 'application/json; charset=utf-8',
content:params
},
headers: {"Accept":"application\/json"}
};
return WL.Server.invokeHttp(input);
}
Run Code Online (Sandbox Code Playgroud) 我需要能够在java适配器中获取用户登录用户ID /密码.阅读了很多文章之后,最好的方式就是打电话
WL.Server.getActiveUser来自从java适配器调用的javascript函数.所以,我在http适配器上添加了一个getIdentity函数来验证我们的应用程序.我已经验证了getActiveUser在登录页面调用的身份验证功能中工作...
当我调用getIdentity函数时,getActiveUser使用相同的身份验证领域返回null.我在application_descriptor文件中设置了域.不知道我还有什么要做的.有任何想法吗?
function performAuthentication(username, password) {
WL.Logger.info("In performAuthentication: username = " + username + " password = " + password + "Time = " + new Date(new Date().getTime()).toLocaleString());
var invocationData = {
adapter : 'BluePages',
procedure : 'authenticate',
parameters : [username, password]
};
var invocationResult = WL.Server.invokeProcedure(invocationData);
var fullName = invocationResult.result.fullName;
if (invocationResult.result.success == false) {
return {
authRequired: true,
loginPassed: false
};
}
else {
userIdentity = {
userId: username,
credentials: password,
displayName: username, …Run Code Online (Sandbox Code Playgroud) 我在MFP V8.0中编写了一个适配器程序.通过安全检查确保此过程.我想在调用此适配器过程之前检查用户是否已登录:
过程映射到范围如下:
<procedure name="searchData" scope="restrictedResource"/>
Run Code Online (Sandbox Code Playgroud)
安全检查定义如下:
<securityCheckDefinition name="UserValidationSecurityCheck" class="com.sample.UserValidationSecurityCheck">
Run Code Online (Sandbox Code Playgroud)
我也完成了服务器的Scope Element映射.
我写了下面调用适配器方法的方法:
function callAdapterProcedure(invocationData){
var procedureName = invocationData.procedure;
var successHandler = invocationData.successHandler;
var failureHandler = invocationData.failureHandler;
var parameters = invocationData.parameters;
var isuserLoggedIn = checkForLoggedInUser();
alert('is logged in' + isuserLoggedIn);
if(isuserLoggedIn){
var dataRequest = new WLResourceRequest(getAdapterPath(procedureName), WLResourceRequest.GET);
dataRequest.setQueryParameter("params", [JSON.stringify(parameters)]);
dataRequest.send().then(successHandler,failureHandler);
}else{
hideProgressBar();
showAlert(Messages.ALERT_SESSION_TIME_OUT);
logoutWithoutConfirmation();
openLogin();
}
}
Run Code Online (Sandbox Code Playgroud)
以下是checkForLoggedInUser()方法的实现:
function checkForLoggedInUser(){
var userAlreadyLoggedIn = undefined;//WL.Client.isUserAuthenticated(mrmGlobal.realms.authenticationRealm,null);
WLAuthorizationManager.obtainAccessToken("restrictedResource").then(
function (accessToken) {
alert("obtainAccessToken onSuccess");
userAlreadyLoggedIn = true;
},
function (response) {
alert("obtainAccessToken …Run Code Online (Sandbox Code Playgroud) 我正在使用MobileFirst CLI 8.0.0-2016070716,Java 1.8.0_91(如果重要的话,在Mac OS X 10.11.6上).我一直在努力通过本教程创建使用MobileFirst CLI的Java适配器.
按照创建,构建和部署适配器的步骤后,打开操作控制台并选择刚刚部署的适配器 - >资源 - >"查看Swagger文档".当我在任何操作上按"试用"时,我收到"401 - 未经授权"的响应代码.
知道可能是什么问题吗?