在 Xpages 中。如何将值从 serviceBean(由 extlib REST 服务调用)传递回注释文档
In Xpages. How can I pass values from a serviceBean (called by extlib REST service) back to a notes document
在 Xpages (9.0.1FP9) 中。我正在使用 extlib 从支付网关 (Braintree) 接收一个 webhook。 REST 服务/serviceBean。我从 webhook 获取包,我可以解析信息。
但是我无法在 JAVA 中获取 Domino 会话的句柄,因此我可以创建或更新 Notes 文档。
我的 JAVA 技能有限,所以我被困住了。任何帮助将不胜感激。
Xpage
{
<xe:restService id="JSONSearch" pathInfo="test1" state="false">
<xe:this.service>
<xe:customRestService contentType="application/json"
serviceBean="com.mydomain.bt_Webhook1">
</xe:customRestService>
</xe:this.service>
</xe:restService>
}
package com.mydomain;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.domino.services.ServiceException;
import com.ibm.domino.services.rest.RestServiceEngine;
import com.ibm.xsp.extlib.component.rest.CustomService;
import com.ibm.xsp.extlib.component.rest.CustomServiceBean;
import com.braintreegateway.*;
import lotus.domino.*;
public class bt_Webhook1 extends CustomServiceBean{
//=====================================================================
String btMerchantID = "abcdefgh1i2jk3lm";
String btPrivateKey = "abcdefghijkl2mnopq3rstuv4wxyz";
String btPublicKey = "zyxwvutsr1qpo2nm";
BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX, //Environment.SANDBOX or Environment.PRODUCTION
btMerchantID, //Merchant ID
btPublicKey, //Public Key
btPrivateKey //Private Key
);
//=====================================================================
@Override
//wissel.net; http://dominoherald.blogspot.com/2016/02/rest-via-service-bean.html
public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {
HttpServletRequest request = engine.getHttpRequest();
HttpServletResponse response = engine.getHttpResponse();
response.setHeader("Content-Type", "application/json; charset=UTF-8");
response.setStatus(200);
try {
String btsignature = request.getParameter("bt_signature");
String btpayload = request.getParameter("bt_payload");
WebhookNotification webhookNotification = gateway.webhookNotification().parse(
btsignature,
btpayload
);
String tKind = webhookNotification.getKind().toString();
String tTimeStamp = webhookNotification.getTimestamp().getTime().toString();
String tMerchantAcctID = webhookNotification.getMerchantAccount().getId();
System.out.println("------------------------------------------------");
System.out.println("tMerchantAcctID: " + tMerchantAcctID);
System.out.println("tKind: " + tKind);
System.out.println("tTimeStamp: " + tTimeStamp);
System.out.println("------------------------------------------------");
/*
//There is no way to create a new Domino Session in a Java Code element.
//The current Domino Session object must be passed as a parameter to the method via the global session object. (TLCC Java courseware)
Session session = getCurrentSession(); // -- ERROR The method getCurrentSession() is undefined for the type bt_Webhook1
Database db = session.getCurrentDatabase();
Document doc = db.createDocument();
doc.replaceItemValue("Form", "Webhook");
doc.replaceItemValue("webhook_Timestamp", "Timestamp");
doc.replaceItemValue("webhook_Kind", "Kind");
doc.replaceItemValue("webhook_MerchantAccountID", "MerchantAccountID");
doc.save();
doc.recycle();
db.recycle();
*/
response.getWriter().close();
System.out.println("done");
return;
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
return;
}
}
}
您可以通过从 XPages 运行时解析 session
对象来获取它,例如Session s = (Session) ExtLibUtil.resolveVariable("session");
这是 Eric McCormick 在其博客 post https://edm00se.io/xpages-servlets/servlets-handling-data-round-house-kick/ 中的代码的扩展。 ExtLibUtil
给出了他使用 FacesContext
的快捷方式。
在 Xpages (9.0.1FP9) 中。我正在使用 extlib 从支付网关 (Braintree) 接收一个 webhook。 REST 服务/serviceBean。我从 webhook 获取包,我可以解析信息。
但是我无法在 JAVA 中获取 Domino 会话的句柄,因此我可以创建或更新 Notes 文档。
我的 JAVA 技能有限,所以我被困住了。任何帮助将不胜感激。
Xpage
{
<xe:restService id="JSONSearch" pathInfo="test1" state="false">
<xe:this.service>
<xe:customRestService contentType="application/json"
serviceBean="com.mydomain.bt_Webhook1">
</xe:customRestService>
</xe:this.service>
</xe:restService>
}
package com.mydomain;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.domino.services.ServiceException;
import com.ibm.domino.services.rest.RestServiceEngine;
import com.ibm.xsp.extlib.component.rest.CustomService;
import com.ibm.xsp.extlib.component.rest.CustomServiceBean;
import com.braintreegateway.*;
import lotus.domino.*;
public class bt_Webhook1 extends CustomServiceBean{
//=====================================================================
String btMerchantID = "abcdefgh1i2jk3lm";
String btPrivateKey = "abcdefghijkl2mnopq3rstuv4wxyz";
String btPublicKey = "zyxwvutsr1qpo2nm";
BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX, //Environment.SANDBOX or Environment.PRODUCTION
btMerchantID, //Merchant ID
btPublicKey, //Public Key
btPrivateKey //Private Key
);
//=====================================================================
@Override
//wissel.net; http://dominoherald.blogspot.com/2016/02/rest-via-service-bean.html
public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {
HttpServletRequest request = engine.getHttpRequest();
HttpServletResponse response = engine.getHttpResponse();
response.setHeader("Content-Type", "application/json; charset=UTF-8");
response.setStatus(200);
try {
String btsignature = request.getParameter("bt_signature");
String btpayload = request.getParameter("bt_payload");
WebhookNotification webhookNotification = gateway.webhookNotification().parse(
btsignature,
btpayload
);
String tKind = webhookNotification.getKind().toString();
String tTimeStamp = webhookNotification.getTimestamp().getTime().toString();
String tMerchantAcctID = webhookNotification.getMerchantAccount().getId();
System.out.println("------------------------------------------------");
System.out.println("tMerchantAcctID: " + tMerchantAcctID);
System.out.println("tKind: " + tKind);
System.out.println("tTimeStamp: " + tTimeStamp);
System.out.println("------------------------------------------------");
/*
//There is no way to create a new Domino Session in a Java Code element.
//The current Domino Session object must be passed as a parameter to the method via the global session object. (TLCC Java courseware)
Session session = getCurrentSession(); // -- ERROR The method getCurrentSession() is undefined for the type bt_Webhook1
Database db = session.getCurrentDatabase();
Document doc = db.createDocument();
doc.replaceItemValue("Form", "Webhook");
doc.replaceItemValue("webhook_Timestamp", "Timestamp");
doc.replaceItemValue("webhook_Kind", "Kind");
doc.replaceItemValue("webhook_MerchantAccountID", "MerchantAccountID");
doc.save();
doc.recycle();
db.recycle();
*/
response.getWriter().close();
System.out.println("done");
return;
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
return;
}
}
}
您可以通过从 XPages 运行时解析 session
对象来获取它,例如Session s = (Session) ExtLibUtil.resolveVariable("session");
这是 Eric McCormick 在其博客 post https://edm00se.io/xpages-servlets/servlets-handling-data-round-house-kick/ 中的代码的扩展。 ExtLibUtil
给出了他使用 FacesContext
的快捷方式。