3

I'm using Quercus/PHP on AppEngine. When I run a simple script with file_get_contents($url); I get an error:

java.lang.NoClassDefFoundError: java.net.Socket is a restricted class. Please see the Google App Engine developer's guide for more details.

I've googled and although I find that other's have run into the same error, but the cause seems the vary. What do you think is cousing this error for me?

I'm using the latest AppEngine Java SDK, and the latest Quercus.

userBG
  • 6,860
  • 10
  • 31
  • 39

4 Answers4

2

When using Google AppEngine/Java, you don't really have access to a complete JVM: your applications run in a restricted sandbox. See documentation here :

https://developers.google.com/appengine/docs/java/runtime?hl=en#The_Sandbox

According to this documentation, you cannot open a socket in this sandbox. That's why it's written that "java.net.Socket is a restricted class".

olivierlemasle
  • 1,219
  • 16
  • 31
2

olivierlemasle is right, but here is the solution that I found after some more searching; in the comments section, user "Phil" recommend:

import java.net.URL;
define('URLFetchServiceFactory', new Java('com.google.appengine.api.urlfetch.URLFetchServiceFactory'));
$data = URLFetchServiceFactory->getURLFetchService()->fetch(new URL($url))->getContent();

Tested, and it worked!

userBG
  • 6,860
  • 10
  • 31
  • 39
1

App Engine support for java.net.Socket is starting to roll out on 1.7.2 with trusted tester submissions being taken now.

There will be some limitations but it should support a majority of uses.

Sign ups are here: https://docs.google.com/a/google.com/spreadsheet/viewform?formkey=dF9QR3pnQ2pNa0dqalViSTZoenVkcHc6MQ#gid=0

It's been popular so only a fraction will be enabled.

ozzee
  • 141
  • 5
0

According to the homepage of your api (http://quercus.caucho.com/) it can use hibernate. Quick googling gave back this for me: GWT and Hibernate - NoClassDefFoundError when using Hibernate

It says hibernate will not work with google app engine. Maybe this is the answer.

Community
  • 1
  • 1
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113
  • 1
    I'm not using hibernate as far as i know, but I guess I should repost this question later with stacktrace. I'm not at my home computer now so can't post it now. – userBG Dec 17 '11 at 15:47