I'm writing a Stash plugin and trying to use the ContentService's streamDifff() method. My code executes right up until the line before this call, but then I am logged out of Stash with no error messages about what happened.
Community moderators have prevented the ability to post new answers.
Putting a try/catch around the invocation showed that the code was throwing the following exception:
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
In order for the call to work, I need to execute it as a specific user, I assume so that the Stash API can internally check that the user has the correct permissions for using reading the repository content.
You can easily do this using the SecurityService's doAsUser() method:
securityService.doAsUser("Reading repository changesets", user.getName(), new Operation<Object, Throwable>() { ... contentService.streamDiff(new Builder(repository, changeSet.getCommitHash()).whitespace(DiffWhitespace.IGNORE_ALL).build(), new DiffContentCallback() { ...
Assuming you want to get the current user (of the request) in order to execute the call, you can use the StashAuthenticationContext's getCurrentUser() method.
I am trying to use contentService.streamDiff in my java code but I am getting different errors:
no suitable method found for streamDiff,
cannot find symbol for variable Builder and many others.
I am using this to create email template with diff patches. You can check snippet and let me know what's wrong here.
String link = contentService.streamDiff(repository);
public String streamDiff(String request){
String output = contentService.streamDiff(new Builder(repository, changeSet.getCommitHash()).whitespace(DiffWhitespace.IGNORE_ALL).build(), new DiffContentCallback();
}
I am constructing class and calling it.
Thanks in advance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi iihitp,
What version of Stash are you compiling and running against? I'm assuming you're compiling against 2.x (specified in your pom.xml) and running against Stash 3.x? In 3.0 Stash started removing deprecated methods and interfaces, of which ContentService.streamDiff() was one:
https://developer.atlassian.com/stash/docs/3.0.1/reference/api-changelog.html
The one you want instead is CommitSerice.streamDiff():
https://developer.atlassian.com/static/javadoc/stash/3.0.1/api/reference/com/atlassian/stash/commit/CommitService.html#streamDiff(com.atlassian.stash.content.DiffRequest, com.atlassian.stash.content.DiffContentCallback)
I hope that helps.
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Charles,
Thank you for your response. I am using Stash SDK to test this. The version of Stash is 2.5.0 and it is not able to resolve commit.CommitService. Error: package com.atlassian.stash.commit does not exist.
So can you provide solution for 2.5.0 version.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi iihitp,
Apologies, oh in that case you still want to use ContentService. I couldn't say what is wrong. Could you possibly expose part of your plugin on bitbucket and share here? Will be much easier to see what's wrong and suggest a solution.
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Charles,
Please find my source code on bitbucket https://bitbucket.org/iihitp/push-notifier/src/909e7b5d3718?at=master. I have uploaded only java files and soy template. As I metioned earlier I am using SDK, so I have atlassian-plugin.xml and pom.xml on my local to compile this.
Thanks for your help.
iihitp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I gave you access. I was not aware of this. Please try now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi iihitp,
So just to confirm - you're getting compiler errors? You don't appear to be importing RefChange and PageRequest. The call to writeCommitData is missing an argument and your call to streamDirectory is trying to call methods on the String objectId.
Is that what you're asking help for?
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Charles,
Sorry for bugging you. I am new to Java coding. So have so many questions. I have modified java files by passing missing argument. But still I am getting errors for ContentTreeNode and ContentTreeCallback. I am not sure how can I fix this. Please check the latest files on bitbucket and error below.
ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/atlastutorial/helloworld/src/main/java/be/foreach/stash/hook/PushEmailNotifier.java:[117,59] cannot find symbol
symbol: method Type()
location: interface com.atlassian.stash.content.ContentTreeNode
[ERROR] /C:/atlastutorial/helloworld/src/main/java/be/foreach/stash/hook/SmtpNotificationRenderer.java:[101,17] method writeCommitData in class be.foreach.stash.hook.SmtpNotificationRenderer cannot be applied to given types;
required: com.atlassian.stash.repository.Repository,com.atlassian.stash.util.Page<com.atlassian.stash.content.Changeset>,java.lang.StringBuilder,com.atlassian.stash.content.Changeset,java.lang.String,java.lang.String,boolean,java.lang.String,com.atlassian.stash.content.ContentTreeNode,com.atlassian.stash.content.ContentTreeCallback
found: com.atlassian.stash.repository.Repository,com.atlassian.stash.util.Page<com.atlassian.stash.content.Changeset>,java.lang.StringBuilder,com.atlassian.stash.content.Changeset,java.lang.String,java.lang.String,boolean,java.lang.String,com.atlassian.stash.content.ContentTreeNode
reason: actual and formal argument lists differ in length
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.876 s
[INFO] Finished at: 2014-07-18T09:35:14-05:00
[INFO] Final Memory: 36M/310M
[INFO] ------------------------------------------------------------------------
I appreciate your help.
iihitp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Charles,
contentService.streamDirectory(repository, objectId, path, recursive, new AbstractContentTreeCallback(){
//@Override
public boolean onTreeNode(ContentTreeNode node) throws IOException {
nodes.add(node);
//List all the tree nodes- this can be false if you want to 'stop'
return true;
}
}, new PageRequestImpl(0, PushEmailNotifier.MAX_PAGE_REQUEST));
}
is not returning anything. I am trying to get node value so I can have it as my diff URL in the notifier email. I tried printing/ getting node values but no luck. Error incompatible types.
Thanks for any help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.