[google-appengine] How can I use java.io.File(filePath) in AppEngine?

2014-01-21 Thread Juan de Dios Becerra
I am trying to use Google + Domains API in GAE, but when I try to create a 
GoogleCredential I need to use this:

.setServiceAccountPrivateKeyFromP12File(new java.io.File(filePath))

Where filePath is a .p12 extension file(private key for authentication) 
this file I put in WEB-INF folder and I granted permissions to all, but 
when I try to create the GoogleCredential I get this error:

java.security.AccessControlException: access denied (java.io.FilePermission 
/WEB-INF/file.p12 read)

Obviously the file has the correct name in my folder, this process works in 
my project which is not AppEngine, so I guess is a problem in the way to 
access files in AppEngine using java.io.File.

If somebody has idea, I would be very thankful.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [google-appengine] How can I use java.io.File(filePath) in AppEngine?

2014-01-21 Thread Vinny P
On Tue, Jan 21, 2014 at 3:55 PM, Juan de Dios Becerra <
j.becerra4...@gmail.com> wrote:

> I am trying to use Google + Domains API in GAE, but when I try to create a
> GoogleCredential I need to use this:
>
> .setServiceAccountPrivateKeyFromP12File(new java.io.File(filePath))
>
> Where filePath is a .p12 extension file(private key for authentication)
> this file I put in WEB-INF folder and I granted permissions to all, but
> when I try to create the GoogleCredential I get this error:
>
> java.security.AccessControlException: access denied
> (java.io.FilePermission /WEB-INF/file.p12 read)
>
> Obviously the file has the correct name in my folder, this process works
> in my project which is not AppEngine, so I guess is a problem in the way to
> access files in AppEngine using java.io.File.
>



Java I/O classes, such as File, are limited on App Engine. Try using
ServletContext's stream services to collect an inputstream, then read the
file normally. For example:

*InputStream stream = this.getServletContext().getResourceAsStream(path);*


-
-Vinny P
Technology & Media Advisor
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [google-appengine] How can I use java.io.File(filePath) in AppEngine?

2014-01-22 Thread Juan de Dios Becerra
What you mean when say "then read file normally" is that I can use the same 
new ava.io.File(filePath) function?

I guess this line:

*InputStream stream = this.getServletContext().getResourceAsStream(path);*

is only to collect the inputsream that you refer, but I don't use *stream *
variable?

El martes, 21 de enero de 2014 22:39:14 UTC-6, Vinny P escribió:
>
> On Tue, Jan 21, 2014 at 3:55 PM, Juan de Dios Becerra 
> 
> > wrote:
>
>> I am trying to use Google + Domains API in GAE, but when I try to create 
>> a GoogleCredential I need to use this:
>>
>> .setServiceAccountPrivateKeyFromP12File(new java.io.File(filePath))
>>
>> Where filePath is a .p12 extension file(private key for authentication) 
>> this file I put in WEB-INF folder and I granted permissions to all, but 
>> when I try to create the GoogleCredential I get this error:
>>
>> java.security.AccessControlException: access denied 
>> (java.io.FilePermission /WEB-INF/file.p12 read)
>>
>> Obviously the file has the correct name in my folder, this process works 
>> in my project which is not AppEngine, so I guess is a problem in the way to 
>> access files in AppEngine using java.io.File.
>>
>
>
>
> Java I/O classes, such as File, are limited on App Engine. Try using 
> ServletContext's stream services to collect an inputstream, then read the 
> file normally. For example:
>
> *InputStream stream = this.getServletContext().getResourceAsStream(path);*
>
>  
> -
> -Vinny P
> Technology & Media Advisor
> Chicago, IL
>
> App Engine Code Samples: http://www.learntogoogleit.com
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [google-appengine] How can I use java.io.File(filePath) in AppEngine?

2014-01-22 Thread Alejandro Gonzalez
Hello Juan, maybe with an example is more clear:

URI keyURL;
String fileName = "google_bigq.p12";
keyURL =
BigQueryAPIManager.class.getClassLoader().getResource(fileName).toURI();

GoogleCredential credential = new
GoogleCredential.Builder().setTransport(TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(EMAIL_ID)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(new
File(keyURL))
.build();

Regards,
Alejandro




Alejandro González Rodrigo
*www.nextinit.com* 
*alejandro.gonza...@nextinit.com *
*+34  666 57 79 13*


2014/1/22 Juan de Dios Becerra 

> What you mean when say "then read file normally" is that I can use the
> same new ava.io.File(filePath) function?
>
> I guess this line:
>
> *InputStream stream = this.getServletContext().getResourceAsStream(path);*
>
> is only to collect the inputsream that you refer, but I don't use *stream
> *variable?
>
> El martes, 21 de enero de 2014 22:39:14 UTC-6, Vinny P escribió:
>>
>> On Tue, Jan 21, 2014 at 3:55 PM, Juan de Dios Becerra > com> wrote:
>>
>> I am trying to use Google + Domains API in GAE, but when I try to create
>>> a GoogleCredential I need to use this:
>>>
>>> .setServiceAccountPrivateKeyFromP12File(new java.io.File(filePath))
>>>
>>> Where filePath is a .p12 extension file(private key for authentication)
>>> this file I put in WEB-INF folder and I granted permissions to all, but
>>> when I try to create the GoogleCredential I get this error:
>>>
>>> java.security.AccessControlException: access denied
>>> (java.io.FilePermission /WEB-INF/file.p12 read)
>>>
>>> Obviously the file has the correct name in my folder, this process works
>>> in my project which is not AppEngine, so I guess is a problem in the way to
>>> access files in AppEngine using java.io.File.
>>>
>>
>>
>>
>> Java I/O classes, such as File, are limited on App Engine. Try using
>> ServletContext's stream services to collect an inputstream, then read the
>> file normally. For example:
>>
>> *InputStream stream = this.getServletContext().getResourceAsStream(path);*
>>
>>
>> -
>> -Vinny P
>> Technology & Media Advisor
>> Chicago, IL
>>
>> App Engine Code Samples: http://www.learntogoogleit.com
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-appengine+unsubscr...@googlegroups.com.
> To post to this group, send email to google-appengine@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-appengine.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [google-appengine] How can I use java.io.File(filePath) in AppEngine?

2014-01-22 Thread Nick
This is how we load it during our DI phase:

String certificate = "/someuniqueid-privatekey.p12";

File privateKey = new File(getClass().getResource(certificate).toURI());

...

builder.setServiceAccountPrivateKeyFromP12File(privateKey);


In this example, the p12 file is in our src/main/resources.

On Thursday, January 23, 2014 2:33:43 AM UTC+11, Alejandro Gonzalez wrote:
>
> Hello Juan, maybe with an example is more clear:
>
> URI keyURL;
> String fileName = "google_bigq.p12";
> keyURL = 
> BigQueryAPIManager.class.getClassLoader().getResource(fileName).toURI();
>
> GoogleCredential credential = new 
> GoogleCredential.Builder().setTransport(TRANSPORT)
> .setJsonFactory(JSON_FACTORY)
> .setServiceAccountId(EMAIL_ID)
> .setServiceAccountScopes(SCOPES)
> .setServiceAccountPrivateKeyFromP12File(new 
> File(keyURL))
> .build();
>
> Regards,
> Alejandro
>
>
>
>
> Alejandro González Rodrigo
> *www.nextinit.com* 
> *alejandro...@nextinit.com *
> * +34  666 57 79 13*
>
>
> 2014/1/22 Juan de Dios Becerra >
>
>> What you mean when say "then read file normally" is that I can use the 
>> same new ava.io.File(filePath) function?
>>
>> I guess this line:
>>
>> *InputStream stream = this.getServletContext().getResourceAsStream(path);*
>>
>> is only to collect the inputsream that you refer, but I don't use *stream 
>> *variable?
>>
>> El martes, 21 de enero de 2014 22:39:14 UTC-6, Vinny P escribió:
>>>
>>> On Tue, Jan 21, 2014 at 3:55 PM, Juan de Dios Becerra >> com> wrote:
>>>
>>> I am trying to use Google + Domains API in GAE, but when I try to create 
 a GoogleCredential I need to use this:

 .setServiceAccountPrivateKeyFromP12File(new java.io.File(filePath))

 Where filePath is a .p12 extension file(private key for authentication) 
 this file I put in WEB-INF folder and I granted permissions to all, but 
 when I try to create the GoogleCredential I get this error:

 java.security.AccessControlException: access denied 
 (java.io.FilePermission /WEB-INF/file.p12 read)

 Obviously the file has the correct name in my folder, this process 
 works in my project which is not AppEngine, so I guess is a problem in the 
 way to access files in AppEngine using java.io.File.

>>>
>>>
>>>
>>> Java I/O classes, such as File, are limited on App Engine. Try using 
>>> ServletContext's stream services to collect an inputstream, then read the 
>>> file normally. For example:
>>>
>>> *InputStream stream = 
>>> this.getServletContext().getResourceAsStream(path);*
>>>
>>>  
>>> -
>>> -Vinny P
>>> Technology & Media Advisor
>>> Chicago, IL
>>>
>>> App Engine Code Samples: http://www.learntogoogleit.com
>>>  
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google App Engine" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-appengi...@googlegroups.com .
>> To post to this group, send email to 
>> google-a...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/google-appengine.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.