Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Help Arthur find his restricted class" or "how can i make google app engine happy"

somewhere in here I'm using java.rmi.server.UID which is upsetting GAE. After :only'ing my dependencies to the bone I'm at an impasse.

(ns helloworld.core
  (:use ;[hiccup.core]
        [hiccup.page-helpers :only (html5 include-css)]
        [clojure.contrib.string :only (split)]
        [compojure.core :only (defroutes GET)]
        [hiccup.middleware :only (wrap-base-url)])
  (:require [appengine-magic.core :as ae]
            [compojure.route :as route
              :only (resources not-found) ]
            [compojure.handler :as handler :only (site)])
  (:gen-class :extends javax.servlet.http.HttpServlet))

 (defn index-page
  ([name]
     (html5
      [:head
       [:title (str "Hello " name)]
       (include-css "/css/style.css")]
      [:body
       [:h1 (str "Hello " name)]]))
  ([] (index-page "World")))

(def match-opperator
  { "add"      +
    "subtract" -
    "multiply" *
    "divide"   /})

(defroutes hello-routes
  (GET "/:f/*" [f & x]
       (index-page (apply (match-opperator f)
                          (map #(Integer/parseInt %)
                               (split #" " (:* x))))))
  (GET "/" [] (index-page))
  (route/resources "/")
  (route/not-found "Page not found"))

(def app
     (-> (handler/site hello-routes)
         (wrap-base-url)))

(ae/def-appengine-app helloworld-app #'app)

I can load it up in jetty and it works fine, after loading it into the dev-appserver i get this:

HTTP ERROR 500

Problem accessing /multiply/1%202%204%208. Reason:

    java.rmi.server.UID is a restricted class. Please see the Google  App Engine developer's guide for more details.

Caused by:

java.lang.NoClassDefFoundError: java.rmi.server.UID is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
    at org.apache.commons.fileupload.disk.DiskFileItem.(DiskFileItem.java:103)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at ring.middleware.multipart_params$loading__4414__auto__.invoke(multipart_params.clj:1)
    at ring.middleware.multipart_params__init.load(Unknown Source)
    at ring.middleware.multipart_params__init.(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at clojure.lang.RT.loadClassForName(RT.java:1578)
    at clojure.lang.RT.load(RT.java:399)
    at clojure.lang.RT.load(RT.java:381)
    at clojure.core$load$fn__4519.invoke(core.clj:4915)

ps: here is my project.clj incase this helps:

(defproject helloworld "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [compojure "0.6.2"]
                 [hiccup "0.3.4"]]

  :dev-dependencies [[appengine-magic "0.4.1"]
                     [swank-clojure "1.2.1"]])
like image 340
Arthur Ulfeldt Avatar asked May 31 '11 03:05

Arthur Ulfeldt


1 Answers

FWIW I don't think :only will make a bit of difference to GAE. It's probably watching what classes you load, and refusing to refer to a function doesn't stop its code from being loaded.

With no domain-specific experience other than looking at the stacktrace, I think the handler that's causing the issue is probably compojure.handler/site, which includes wrap-multipart-params. I doubt you need that feature for your application, so see if you can make do with compojure.handler/api. Then if there are particular wrappers from site that you do need, wrap them in manually.

Then again, given my earlier point about loading classes, I guess the code for multipart-params is getting loaded as soon as you require the compojure.handler namespace, so what you do after that might not matter. I suppose you might even have to just do all the wrapping from api and site manually; it's not very complicated. Then you should be able to avoid ever requireing the multipart-params namespace.

like image 84
amalloy Avatar answered Sep 28 '22 03:09

amalloy