erratic failure of sessionAsSignerWithFullAccess - xpages

The code below is a some test code that I have in an action button on an XPage. I need to get a handle on the current database with FullAccess in the code WFSUtils.sysOut just formats a printed message to the server console. Periodically the error message in the catch returns
2015-01-09 12:49:11 PM HTTP JVM: WFS ~~~ Error in Update Demo 'sessionAsSignerWithFullAccess' not found
I am the signer of the XPage and the database is signed by the server ID. Sometimes it runs through just fine other time it fails with the message above. If I shut everything down then restart it will generally run but then start failing. It is very random and unpredictable.
debug = true;
try{
if (debug) WFSUtils.sysOut("Starting YYY New SetupDemo");
var serverName = database.getServer();
var repID = database.getReplicaID();
thisDB = sessionAsSignerWithFullAccess.getDatabase("","");
thisDB.openByReplicaID(serverName,repID);
if (debug) WFSUtils.sysOut( "SetupDemo Success" + thisDB.getTitle());
}catch(e){
WFSUtils.sysOut("Error " + e.toString())
}finally{
try{
WFSUtils.recycleObjects([]);
if (debug) WFSUtils.sysOut("SetupDemo Recycle Success");
}catch(e){
if (debug) WFSUtils.sysOut("SetupDemo recycle Failed");
}
}

For one reason or another, it's important that all XPage elements be signed by the same ID when running. When they're not, sessionAsSigner and sessionAsSignerWithFullAccess get erratic as you describe - that may be the cause.

Related

Docusign Listener Argument Null (dev Sandbox)

I have created a webmethod in a C# webservice that listens for Docusign to call when an Envelope status changes:
[WebMethod]
public void DocuSignConnectUpdate(DocuSignEnvelopeInformation DocuSignEnvelopeInformation)
{
//Check if null
if (DocuSignEnvelopeInformation == null)
{
File.WriteAllText("C:\\websites\\DataAPI\\datalog.txt", "Data: " + "Data is null");
}
else
{
string envelopeId = "";
try
{
//Write a line in a file
File.WriteAllText("C:\\websites\\DataAPI\\datalog.txt", "Data: " + DocuSignEnvelopeInformation.ToString());
//Get some data out
envelopeId = DocuSignEnvelopeInformation.EnvelopeStatus.EnvelopeID;
//Write Data to a file
File.WriteAllText("C:\\websites\\DataAPI\\innerdatalog.txt", "Data: " + DocuSignEnvelopeInformation.ToString());
}
catch (Exception ex)
{
// could not serialize
File.WriteAllText("C:\\websites\\DataAPI\\errorlog.txt", "Exception: " + ex.Message);
throw new SoapException(ex.Message, SoapException.ClientFaultCode);
}
}
The issue I am having is that DocuSignEnvelopeInformation argument is not being set when called, so the code keeps terminating at the if==null statement. When I run the envelope data to the API using SoapUI everything works correctly. Any ideas what I'm missing would be appreciated.
EDIT: I wanted to Add the Interface here too since I forgot it originally
[ServiceContract(ConfigurationName = "IOperations", Namespace = "https://www.docusign.net/API/3.0")]
public interface IOperations
{
[OperationContract(Action = "DocuSignConnectListener/Operations/DocuSignConnectUpdate")]
[XmlSerializerFormat]
string DocuSignConnectUpdate(DocuSignEnvelopeInformation DocuSignEnvelopeInformation);
}
When a DocuSign webhook is set to use SOAP mode, the notification is sent as a SOAP request to your server (your listener).
If SOAP mode is off, then the notification is sent as a regular POST request with an XML body.
In your question, you say that
When I run the envelope data to the API using SoapUI everything works correctly
So it sounds like everything is worked as designed.
Ok I finally figured this out, turns out it just wasn't pretty enough so I added a decoration specifically:
[SoapDocumentMethod("http://tempuri.org/DocuSignConnectUpdate",
RequestNamespace = "http://tempuri.org",
ResponseNamespace = "http://tempuri.org",
Use = System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
on the method and now everything works like its supposed too. Now that I look at it, it makes a lot more sense.

Azure WebJob does not get response from PostAsync call

I have taken a Windows Service, modified it to be a Console app, then Published it as a WebJob. When it does a PostAsync command it gets no response AND does not execute the Console.WriteLine immediately following the PostAsync command.
Here's the code:
Console.WriteLine("Querying for access credentials...");
HttpResponseMessage responsePut = null;
try
{
Console.WriteLine("PostAsync call");
responsePut = await client.PostAsync("/oauth/access_token", new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded"));
Console.WriteLine("Returned from PostAsync call");
}
catch (System.Net.Http.HttpRequestException err)
{
Console.WriteLine("Unable to connect to the server (HttpRequestException)..." + err.InnerException);
throw new Exception("Unable to connect to the server (HttpRequestException)..." + err.InnerException);
}
catch (Exception err)
{
Console.WriteLine("Unable to connect to the server (Exception)..." + err.Message + "::" + err.InnerException);
throw new Exception("Unable to connect to the server (Exception)..." + err.InnerException);
}
The Azure Console Log is as follows:
[05/01/2018 05:45:31 > e559bd: INFO] Querying for access credentials...
[05/01/2018 05:45:31 > e559bd: INFO] PostAsync call
[05/01/2018 05:45:32 > e559bd: SYS INFO] Status changed to Success
[05/01/2018 05:45:32 > e559bd: SYS INFO] Process went down, waiting for 60 seconds
This code works as a Windows Service and as a Windows Console App, but fails on Azure.
What can I do to determine what Azure is doing to me and/or suggestions to do this differently.
I created a support ticket and got a reasonably quick response.
The line of code that includes the PostAsync had to be modified as follows:
responsePut = client.PostAsync("/oauth/access_token", new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded")).Result;
Note the removal of the await and the addition of the .Result.
This was considered a 'syntax error', which I disagree with! But it solved the problem.

HTTP JVM: CLFAD0134E when performing getDocumentByKey method

On an xpage I run the following code:
function setPersonInfoCommon(x) {
//print("test printing to console value: " + x)
var serv = getPreferenceField("tx_server");
//e.g. "Development1";
var dbname = getPreferenceField("tx_loc_personal_common");
//e.g. "CustomerX\\Personnel.nsf"
var db:NotesDatabase = session.getDatabase(serv,dbname);
if (db == null) {
requestScope.status = "Database not found.";
return;
}
var vw:NotesView = db.getView("LookUpUsersUNID");
if (vw == null) {
requestScope.status = "View not found.";
return;
}
var doc:NotesDocument = vw.getDocumentByKey(x);
if (doc == null) {
requestScope.status = "Document not found.";
return;
}
else{
requestScope.status = "Document created:" + getCreated();
}
}
This freezes my XPage and in the log I see the following notation:
2014-08-19 12:46:11 HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: com.ibm.xsp.FacesExceptionEx: java.io.NotSerializableException: lotus.domino.local.DateTime
2014-08-19 12:46:11 HTTP JVM: CLFAD0134E: Exception processing XPage request. For more detailed information, please consult error-log-0.xml located in E:/Domino/data/domino/workspace/logs
The XPage resides in a different NSF than the one I perform the getDocumentByKey method in. However I do not get any indication that the database (db) or view (vw) can not be found. If I check it by outputting the filepath or something I get the correct values returned.
I tested to run the code from within the NSF I perform the getDocumentByKey method and then the code runs just fine.
What can be the cause?
I am logged in via the web and have the proper rights.
Please always look at those more detailed logs in the location specified before posting a question. Those messages give much more information which will help identify the code causing the problem and usually a more detailed explanation.
In this particular case, the message on the console logs includes "java.io.NotSerializableException: lotus.domino.local.DateTime". Assuming this is relating to the line requestScope.status = "Document created:" + getCreated(); (the detailed logs will confirm) and that getCreated() is actually doc.getCreated(), that returns a NotesDateTime object.
NotesDateTime objects and any other Domino objects cannot be put in any scoped variable (there are various blogs explaining that Domino objects are not serializable).
If you want to put a date/time in a scope, you can get the Java date equivalent using NotesDateTime.toJavaDate(), so doc.getCreated().toJavaDate().

Pusher Window Refresh Issue

i am very new to pusher.com:
I am trying to set up a presence-channel Chat.
Here is my code:
var PresenceChannel = pusher.subscribe('presence-test_channel');
PresenceChannel.bind('pusher:subscription_succeeded', function(members){
$("#chatMembers").empty();
members.each(function(member) {
$("#chatMembers").prepend("<li id='"+member.info.employee_id+"'>"+member.info.customer_id+"</li>");
});
});
PresenceChannel.bind('pusher:member_added',function(member){
$("#chatMembers").prepend("<li id='"+member.info.employee_id+"'>"+member.info.customer_id+"</li>");
});
PresenceChannel.bind('pusher:member_removed',function(member){
$("li#"+member.info.employee_id).remove();
});
Its working as expected.
But i have a problem:
When i refresh one of the opened browser windows, the following events get fired:
PresenceChannel.bind('pusher:member_added',function(member){...
And directly after that,
PresenceChannel.bind('pusher:member_removed',function(member){...
get fired.
So, after a refresh of one window, the user get removed from my list, and
1 second later, the user again is added to the list....
1) Reload 1 browser window
2) The other window triggers 'pusher:member_removed': User removed from List
3) The other window triggers 'pusher:member_added': User added to the list agein
What to do ?
The 2nd window receives a pusher:member_removed because the 1st window has unloaded and the user had therefore left the presence channel. When the 2nd window reloads and the user resubscribes to the presence channel the pusher:member_added is triggered.
This is expected behaviour.
However, Pusher do add a delay to these event in order to try and stop events being triggered in this scenario. In your case it would seem that the delay in not long enough to stop that happening. In your situation there is an FAQ which provides some information about what you can do to work around this:
How can I stop users going offline for an instant when they navigate between pages?
It is simply solved.
Try this.
Pusher dashboard -> Webhooks
and add Webhook url & event type to Presense.
$app_secret = 'YOUR PUSHER SECRET KEY';
$app_key = $request->headers->get('X-Pusher-Key');
$webhook_signature = $request->headers->get('X-Pusher-Signature');
$body = file_get_contents('php://input');
$expected_signature = hash_hmac( 'sha256', $body, $app_secret, false );
if($webhook_signature == $expected_signature) {
// decode as associative array
$payload = json_decode( $body, true );
foreach($payload['events'] as &$event) {
// do something with the event
if ($event['name'] == 'member_added') {
// do process user joind & trigger message
$this->setAddMember($event);
} elseif ($event['name'] == 'member_removed') {
// do process user out & trigger message
$this->setRemoveMember($event);
}
}
header("Status: 200 OK");
}
else {
header("Status: 401 Not authenticated");
}
More detailed information see document this.
https://pusher.com/docs/webhooks

Displaying results of an SPLongOperation

I am using SPLongOperation to run a lengthy operation. After completing, the gears page redirects back to the original page from which the long operation was launched. I am not able to write anything to the oriignal page using SPLongOperation.Endscript. Here is the code I am using
using (SPLongOperation operation = new SPLongOperation(this.Page))
{
//.......................
//.......................
StringBuilder endScript = new StringBuilder();
endScript.Append("document.write('Success!!');");
operation.End(Request.Url.ToString(), SPRedirectFlags.UseSource, HttpContext.Current, String.Empty, endScript.ToString());
}
You won't be able to write anything to the calling page, a new http request has been made to show you the page with the spinning wheel while your operation is under progress and then you're redirected back to the specified url (using a new request).
The easiest way to show a success message is to pass a specific querystring to your calling url by replacing your string.empty parameter with something like
operation.End(Request.Url.ToString(), SPRedirectFlags.UseSource, HttpContext.Current, "success=1");
http://msdn.microsoft.com/en-us/library/ms450341.aspx
and then on the load event, check if you have this parameter and display the relevant message (it would be better to add an item to the HttpContext.Items or doing a post instead of a get to remove the querystring but the suggested implementation will prevent you from changing your long operation call and behaviour)
Hope this will help.
Try an alert - that worked for me..
Script.Append("alert('Success!!');");
This might be of help: http://www.sharepoint-tips.com/2012/07/reporting-code-errors-when-running-code.html
SPLongOperation longOp = new SPLongOperation(this.Page);
StringBuilder sbErrors = new StringBuilder();
longOp.Begin();try
{
throw new Exception("Sample");
}
catch(Exception ex)
{
sbErrors.Append("An error occurred: " + ex.MEssage);
}
if
(sbErrors.Length > 0)
{
longOp.EndScript("document.getElementById('s4-simple-card-content').innerHTML = \"Errors have occurred during the submission. Details: " + sbErrors.ToString() + " \";");
}
//close the dialog if there were no errors
longOp.EndScript("window.frameElement.commitPopup();");

Resources