Liferay from fileentry to java file object - java

Anyone know how to retrieve a contentStream from a DLFileEntry (http://docs.liferay.com/portal/6.0/javadocs/com/liferay/portlet/documentlibrary/model/DLFileEntry.html) using an httpservlet?
I tried using DLFileEntry.getContentStream() but it fails giving me the error
com.liferay.portal.security.auth.PrincipalException: PermissionChecker not initialized
I solved in part that problem setting hardcode my userId:
long userId=2
PrincipalThreadLocal.setName(userId);
User user = UserLocalServiceUtil.getUserById(userId);
PermissionChecker permissionChecker;
permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
The problem of this solution is how to get the real userId, and how happen if the user is a guest?
I tried Long.parseLong(req.getRemoteUser()); but fail also.

DLFileEntryLocalServiceUtil.getFile(userId, fileEntryId, version, incrementCounter)
gives you the File. Did you try using this?

If you're using Liferay 6.1 then the following code will get you a InputStream for the That DLFileEntry.
InputStream inputStream = DLFileEntryLocalServiceUtil.getFileAsStream(fileEntry.getUserId(), fileEntry.getFileEntryId(), fileEntry.getVersion());
Howwever the error you're getting is seems to be due you not authenticating with Liferay before making this call to the server.
How are you calling this code?

Please use PermissionThreadLocal.getPermissionChecker() to get the permissionChecker object of the current logged in user with current state. If the user is guest, still you will get the permissionChecker object.
-Felix

Related

How to query Custom Object in Salesforce?

Ok, I am reposting this question because it really drives me crazy.
I have enterprise.wsdl downloaded from salesforce and generated to some jars.
I build path those jars to my Android project in Eclipse.
Here is my code:
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(authEndPoint);
config.setUsername(userID);
config.setPassword(password + securityToken);
config.setCompression(true);
con = new EnterpriseConnection(config);
con.setSessionHeader(UserPreference.getSessionID(mContext));
String sql = "SELECT something FROM myNameSpace__myCustomObject__c";
con.query(sql);
but it returns me this error:
[InvalidSObjectFault [ApiQueryFault [ApiFault
exceptionCode='INVALID_TYPE' exceptionMessage='sObject type 'abc__c'
is not supported.'] row='-1' column='-1' ]]
I am pretty sure that my userID has been assigned with profile that has read, edit access to that custom object.
My code also can query standard object.
Anyone can advise me what could be wrong?
From what I know there are three reasons it may give this error.
1. User permission which you said is setup correctly.
2. Do you have the custom object deployed to the org where you are trying to establish the connection?
3. Check the enterprise WSDL if it contains the custom object name which you are trying to query.
Hope it helps.

java.lang.IllegalArgumentException: no JSON input found while trying google calendar Api in java

I downloaded google calendar api sample from http://code.google.com/p/google-api-java-client/source/browse/calendar-cmdline-sample/?repo=samples and created a project in eclipse.
Now when i try to run the project am getting java.lang.IllegalArgumentException: no JSON input found at this line
FileCredentialStore credentialStore = new FileCredentialStore(
new File(System.getProperty("user.home"), ".credentials/calendar.json"), JSON_FACTORY);
Have any of you tried this example? what is wrong here?
This error can be resolved by providing input to the .credentials/calendar.json file. If you manually provided the following entry in the calendar.json , it will work :
{
"installed": {
"client_id": "client_id",
"client_secret": "client_secret"
}
}
It seems to be the Windows problem which is not allowing to set writable permissions on calendar.json file . The method setWritable(boolean,boolean) is returning false and so is the cause of this problem. Still providing json input manually is not a perfect solutions but your application will work.
That may happen when your application executed before and it created empty .credentials/calendar.json file in you home dir. That may happen if you're running your application in Windows, cause FileCredentialStore tries to do:
file.setReadable(false, false)
and fails.
To solve it just remove calendar.json. Although you might have another error: [unable to set file permissions]
which I don't know how to solve yet.
Is that project having calendar.json resource file. Please share complete exception stack trace.
Seems some required configuration missed from calendar.json file

how do I link to a servlet within javascript code

I got an XLS pic inside of an HTML link, and i need to verify some information first before calling to the servlet, that's why i'm not including the servlet inside of the href="". So i've created a javascript function that verifies the input information in order to be used by the servlet.
(The Servlet returns a XLS in order to be saved by the user).
Tried this:
document.location.href = 'saveExcelServlet.do?' + <<GET method attributes>>;
But it didn't work.
It says:
Problem accessing /wscall-metrics-web/saveExcelServlet.do. Reason:
null
Caused by:
java.lang.NumberFormatException: null
If i write it works...
Can anyone help me?
Thanks.
M.
There's a good chance the URL isn't quite built the way you expect. A great poorman's technique for debugging this kind of thing is to assign a variable and pop it up in an alert:
var newLoc = 'saveExcelServlet.do?' + <<GET method attributes>>;
alert(newLoc);
You can see exactly what URL is getting fetched.

writing a simple ofx4j program

I have been using http://ofx4j.sourceforge.net/userguide.html as a guide to write a small java program to download my bank account statement from wells fargo. I keep getting an error saying Invalid Signon. I have the right url. I am using the same password and username as I use to logon to their webpage. Does anyone have any other simple samples that I could look at or use?
I had the same problem.
I was trying to log into Chase Bank but I was getting an Invalid Signon.
The problem that I had is that I was using the wrong data, oxf4j might have obsolete data
stored for the banks it has stored.
Go to gnucash to get the right updated setting for your bank:
http://wiki.gnucash.org/wiki/OFX_Direct_Connect_Bank_Settings.
Then you need to create a new BaseFinancialInstitutionData object
like this (this example is for chase credit card):
BaseFinancialInstitutionData data = new BaseFinancialInstitutionData();
data.setFinancialInstitutionId("10898");
data.setOFXURL(new URL("https://ofx.chase.com"));
data.setOrganization("B1");
FinancialInstitutionService service = new FinancialInstitutionServiceImpl();
FinancialInstitution fi = service.getFinancialInstitution(data);

How to set/get profile data with XMPP using Smack

I am working on a XMPP client on Android, using the Smack library. The roster/messaging/presence stuff is running very well. However, I didn't find a way to store additional profile information (userpicture, the dogs name, ...).
The only way I see from googling is using VCards. But it simply did not work. I tried the following:
VCard vCard = new VCard();
vCard.load(connection);
vCard.setEmailHome("meine_home#email.de");
vCard.setLastName("Scheller");
vCard.setField("blafasel", "asdf");
vCard.save(connection);
Then I was looking for a way to see that VCard information. It did neither show up in iChat nor in this System.out:
vCard.load(connection, user);
System.out.println(user + " has this vCard: " + vCard.toXML());
So anything went wrong, but theres no indication what it was. I tried this with the google talk server and my own copy of openfire with the same result. Btw, I am using this version of Smack: http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/
What am I doing wrong here? What is the correct way of storing profile related information with Smack?
I have checked out the source of Smack and went through the important parts with a debugger, as well as using the Smack Debug Window. The problem is inside the VCard implementation of the Smack API. Saving a VCard does work as described, however the loading is broken.
parseIQ(XmlPullParser parser) is part of the PacketReader.java class and handles different types of packages. It only handles tags with the following namespaces:
"jabber:iq:auth",
"jabber:iq:roster",
"jabber:iq:register",
"urn:ietf:params:xml:ns:xmpp-bind"
It also looks if there is any registered IQProvider in the ProviderManager. And this is the root of my problem. There is no IQProvider for VCards registered. So whatever information is inside of the vCard tag simply gets dropped.
It is not too hard to register this IQProvider though:
ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());
This solved my little example above for saving my own vCard and downloading it again. I am still having trouble with downloading other users vcards... Gonna have a closer look into this and maybe open up another thread for that issue.
You can use the following code to get info.
VCard card = new VCard();
card.load(connection, "user#fqdn");
System.out.println("Voice: "+card.getPhoneHome("VOICE"));
Try setting a vCard for that user with another client first, and see how that changes your results. In order to diagnose further, you'll need to turn on protocol debugging in Smack (use "-Dsmack.debugEnabled=true" on a desktop machine), and post the relevant bits here.

Categories