これでいいのかしら。。
01 | public static Key allocateId(AsyncDatastoreService ds, String kind) |
02 | throws NullPointerException { |
04 | throw new NullPointerException( "The ds parameter must not be null." ); |
07 | throw new NullPointerException( |
08 | "The kind parameter must not be null." ); |
10 | String ns = NamespaceManager.get(); |
14 | String cacheKey = "!" +ns+ ":" +kind; |
15 | Iterator<Key> keys = keysCache.get(cacheKey); |
16 | if (keys != null && keys.hasNext()) { |
21 | .getQuietly(allocateIdsAsync(ds, kind, KEY_CACHE_SIZE)) |
23 | keysCache.put(cacheKey, keys); |
[appengine][slim3] DatastoreUtil#allocateIdがNamespaceに対応するように修正 はコメントを受け付けていません
listプロパティにInMemoryInCriterionを適用するとエラーになるので修正。
これでいいのかしら。。
01 | public boolean accept(Object model) { |
02 | Object v = convertValueForDatastore(attributeMeta.getValue(model)); |
03 | for (Object o : value) { |
04 | if (v instanceof Collection<?>) { |
05 | for (Object v2: (Collection<?>)v) { |
06 | if (compareValue(v2, o) == 0 ) { |
11 | if (compareValue(v, o) == 0 ) { |
[appengine][slim3]InMemoryInCriterionがlistプロパティでも動作するように修正 はコメントを受け付けていません
appengineでJSON-RPCサーバーのようなものを作りたいときなど ServletRequest#getInputStream()で取得できるInputStreamを使いたい場合があります。ところがslim3のcontrollerでこれをやろうとするとInputStreamのIllegalStateExceptionが発生します。
Jettyや大概のサーブレットサーバーは getInputStreamとgetParameter(s)を同時には使えないようです。
JSON-RPCならslim3のcontrollerは使う必要ないじゃんといえばそれまでなのですができれば慣れているもので全てやってしまいたいというのも事実。そこで以下のようなworkaroundで回避します。
- StreamFilterを作って、そこでServletRequestをWrapperクラスに置き換える (一番最初にこのFilterが動くようにする)
- RequestWrapperでは getInputStreamをoverrideし、Streamを再利用可能にする
なお、このworkaroundは http://d.hatena.ne.jp/machi_pon/20090120/1232420325 にて紹介されているやり方とほぼ同じです。(ナイスポストありがとうございました!)
01 | public class StreamFilter implements Filter { |
03 | public void destroy() { |
08 | public void doFilter(ServletRequest request, ServletResponse response, |
09 | FilterChain chain) throws IOException, ServletException { |
11 | HttpServletRequest req = (HttpServletRequest)request; |
12 | request = new BufferedServletRequestWrapper( req ); |
13 | chain.doFilter(request, response); |
16 | public void init(FilterConfig arg0) throws ServletException { |
01 | public class BufferedServletRequestWrapper extends HttpServletRequestWrapper { |
03 | private byte [] buffer; |
05 | public BufferedServletRequestWrapper(HttpServletRequest request) throws IOException { |
08 | InputStream is = request.getInputStream(); |
09 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
10 | byte buff[] = new byte [ 1024 ]; |
12 | while ( ( read = is.read( buff ) ) > 0 ) { |
13 | baos.write( buff, 0 , read ); |
16 | this .buffer = baos.toByteArray(); |
20 | public ServletInputStream getInputStream() throws IOException { |
21 | return new BufferedServletInputStream( this .buffer ); |
01 | public class BufferedServletInputStream extends ServletInputStream { |
03 | private ByteArrayInputStream inputStream; |
05 | public BufferedServletInputStream( byte [] buffer) { |
06 | this .inputStream = new ByteArrayInputStream( buffer ); |
10 | public int available() throws IOException { |
11 | return inputStream.available(); |
15 | public int read() throws IOException { |
16 | return inputStream.read(); |
20 | public int read( byte [] b, int off, int len) throws IOException { |
21 | return inputStream.read( b, off, len ); |
slim3のcontrollerでServletInputStreamを使いたいとき はコメントを受け付けていません