http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/build.xml ---------------------------------------------------------------------- diff --git a/src/contrib/rest/build.xml b/src/contrib/rest/build.xml deleted file mode 100644 index fb628bc..0000000 --- a/src/contrib/rest/build.xml +++ /dev/null @@ -1,183 +0,0 @@ -<?xml version="1.0"?> - -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<project name="rest" default="jar"> - <import file="../build-contrib.xml"/> - - <property name="test.build.dir" value="${build.test}" /> - <property name="test.src.dir" value="src/test"/> - <property name="test.log.dir" value="${test.build.dir}/logs" /> - <property name="test.data.dir" value="${test.build.dir}/data" /> - <property name="test.data.upgrade.dir" value="${test.data.dir}/upgrade" /> - <property name="test.tmp.dir" value="${test.build.dir}/tmp" /> - <property name="test.output" value="no" /> - <property name="test.timeout" value="900000" /> - <property name="test.junit.output.format" value="plain" /> - <property name="test.junit.fork.mode" value="perTest" /> - <property name="test.junit.printsummary" value="yes" /> - <property name="test.junit.haltonfailure" value="no" /> - <property name="test.junit.maxmem" value="512m" /> - - <!-- ====================================================== --> - <!-- Macro definitions --> - <!-- ====================================================== --> - <macrodef name="macro_tar" description="Worker Macro for tar"> - <attribute name="param.destfile"/> - <element name="param.listofitems"/> - <sequential> - <tar compression="gzip" longfile="gnu" - destfile="@{param.destfile}"> - <param.listofitems/> - </tar> - </sequential> - </macrodef> - - <target name="package" depends="jar" unless="skip.contrib"> - <echo message="contrib: ${name}"/> - <mkdir dir="${dist.dir}${package.share}/contrib/${name}"/> - <copy todir="${dist.dir}${package.share}/contrib/${name}"> - <fileset dir="${build.dir}"> - <include name="zookeeper-${version}-${name}.jar" /> - </fileset> - </copy> - <copy todir="${dist.dir}${package.share}/contrib/${name}/lib"> - <fileset dir="${build.dir}/lib" /> - </copy> - <copy todir="${dist.dir}${package.share}/contrib/${name}/conf"> - <fileset dir="conf" /> - </copy> - </target> - - <target name="setjarname"> - <property name="jarname" - value="${build.dir}/zookeeper-${version}-${name}.jar"/> - </target> - - <target name="compile" depends="ivy-retrieve,zookeeperbuildcontrib.compile"/> - - <target name="test" - depends="compile-test,test-init,test-category,test-start,junit.run,test-stop" /> - - <target name="compile-test" depends="ivy-retrieve-test,compile"> - <property name="target.jdk" value="${ant.java.version}" /> - <property name="src.test.local" location="${basedir}/src/test" /> - <mkdir dir="${build.test}"/> - <javac srcdir="${src.test.local}" - destdir="${build.test}" - target="${target.jdk}" - debug="on" > - <classpath refid="classpath" /> - </javac> - </target> - - <target name="test-init" depends="jar,compile-test"> - <delete dir="${test.log.dir}" /> - <delete dir="${test.tmp.dir}" /> - <delete dir="${test.data.dir}" /> - <mkdir dir="${test.log.dir}" /> - <mkdir dir="${test.tmp.dir}" /> - <mkdir dir="${test.data.dir}" /> - </target> - - <target name="test-start"> - <exec executable="${test.src.dir}/zkServer.sh"> - <arg value="startClean"/> - </exec> - </target> - - <target name="test-stop"> - <exec executable="${test.src.dir}/zkServer.sh"> - <arg value="stop"/> - </exec> - </target> - - <target name="test-category"> - <property name="test.category" value=""/> - </target> - - <target name="junit.run"> - <echo message="${test.src.dir}" /> - <junit showoutput="${test.output}" - printsummary="${test.junit.printsummary}" - haltonfailure="${test.junit.haltonfailure}" - fork="yes" - forkmode="${test.junit.fork.mode}" - maxmemory="${test.junit.maxmem}" - dir="${basedir}" timeout="${test.timeout}" - errorProperty="tests.failed" failureProperty="tests.failed"> - <sysproperty key="build.test.dir" value="${test.tmp.dir}" /> - <sysproperty key="test.data.dir" value="${test.data.dir}" /> - <sysproperty key="log4j.configuration" - value="file:${basedir}/conf/log4j.properties" /> - <classpath refid="classpath"/> - <classpath> - <pathelement path="${build.test}" /> - </classpath> - <formatter type="${test.junit.output.format}" /> - <batchtest todir="${test.log.dir}" unless="testcase"> - <fileset dir="${test.src.dir}" - includes="**/*${test.category}Test.java"/> - </batchtest> - <batchtest todir="${test.log.dir}" if="testcase"> - <fileset dir="${test.src.dir}" includes="**/${testcase}.java"/> - </batchtest> - </junit> - <fail if="tests.failed">Tests failed!</fail> - </target> - - <target name="jar" depends="checkMainCompiled, setjarname, compile"> - <echo message="contrib: ${name}"/> - <jar jarfile="${jarname}"> - <fileset file="${zk.root}/LICENSE.txt" /> - <fileset dir="${build.classes}"/> - <fileset dir="${build.test}"/> - </jar> - </target> - - <target name="run" depends="jar"> - <echo message="contrib: ${name}"/> - <java classname="org.apache.zookeeper.server.jersey.RestMain" fork="true"> - <classpath> - <pathelement path="${jarname}" /> - <fileset dir="${build.dir}/lib" includes="*.jar"/> - <fileset dir="${zk.root}/build" includes="zookeeper-*.jar"/> - <pathelement path="${zk.root}/src/contrib/${name}/conf" /> - <fileset dir="${zk.root}/src/java/lib"> - <include name="**/*.jar" /> - </fileset> - </classpath> - </java> - </target> - - <target name="tar" depends="clean, jar"> - <echo message="building tar.gz: ${name}" /> - <macro_tar param.destfile="${build.dir}/zookeeper-${version}-${name}.tar.gz"> - <param.listofitems> - <tarfileset dir="${build.dir}/lib" prefix="lib" includes="**/*.jar" /> - <tarfileset file="${build.dir}/zookeeper-*-rest.jar" /> - <tarfileset dir="${zk.root}/build" includes="zookeeper-*.jar" prefix="lib" /> - <tarfileset dir="${zk.root}/src/contrib/${name}/conf" prefix="conf" /> - <tarfileset dir="${zk.root}/src/java/lib" prefix="lib" includes="**/*.jar" /> - <tarfileset file="${zk.root}/src/contrib/${name}/rest.sh" /> - </param.listofitems> - </macro_tar> - </target> - -</project> -
http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/conf/keys/README ---------------------------------------------------------------------- diff --git a/src/contrib/rest/conf/keys/README b/src/contrib/rest/conf/keys/README deleted file mode 100644 index 085810a..0000000 --- a/src/contrib/rest/conf/keys/README +++ /dev/null @@ -1,8 +0,0 @@ - -In order to generate .jks (java keystore files) you need to use keytool. - -The password for the existing .jks is "123456" (without quotes). - -Some tutorials: - - http://www.mobilefish.com/tutorials/java/java_quickguide_keytool.html - http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/conf/keys/rest.cer ---------------------------------------------------------------------- diff --git a/src/contrib/rest/conf/keys/rest.cer b/src/contrib/rest/conf/keys/rest.cer deleted file mode 100644 index 13e5aab..0000000 Binary files a/src/contrib/rest/conf/keys/rest.cer and /dev/null differ http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/conf/keys/rest.jks ---------------------------------------------------------------------- diff --git a/src/contrib/rest/conf/keys/rest.jks b/src/contrib/rest/conf/keys/rest.jks deleted file mode 100644 index 539e8be..0000000 Binary files a/src/contrib/rest/conf/keys/rest.jks and /dev/null differ http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/conf/log4j.properties ---------------------------------------------------------------------- diff --git a/src/contrib/rest/conf/log4j.properties b/src/contrib/rest/conf/log4j.properties deleted file mode 100644 index 21ba7e4..0000000 --- a/src/contrib/rest/conf/log4j.properties +++ /dev/null @@ -1,68 +0,0 @@ -# -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# - -# -# ZooKeeper Logging Configuration -# - -# Format is "<default threshold> (, <appender>)+ - -# DEFAULT: console appender only -log4j.rootLogger=INFO, CONSOLE - -# Example with rolling log file -#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE - -# Example with rolling log file and tracing -#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE - -# -# Log INFO level and above messages to the console -# -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.Threshold=INFO -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n - -# -# Add ROLLINGFILE to rootLogger to get log file output -# Log DEBUG level and above messages to a log file -log4j.appender.ROLLINGFILE=org.apache.log4j.ConsoleAppender -log4j.appender.ROLLINGFILE.Threshold=DEBUG -log4j.appender.ROLLINGFILE.File=bookkeeper.log -log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout -log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p - [%t:%C{1}@%L] - %m%n - -# Max log file size of 10MB -log4j.appender.ROLLINGFILE.MaxFileSize=10MB -# uncomment the next line to limit number of backup files -#log4j.appender.ROLLINGFILE.MaxBackupIndex=10 - -# -# Add TRACEFILE to rootLogger to get log file output -# Log DEBUG level and above messages to a log file -log4j.appender.TRACEFILE=org.apache.log4j.FileAppender -log4j.appender.TRACEFILE.Threshold=TRACE -log4j.appender.TRACEFILE.File=bookkeeper_trace.log - -log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout -### Notice we are including log4j's NDC here (%x) -log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L][%x] - %m%n http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/conf/rest.properties ---------------------------------------------------------------------- diff --git a/src/contrib/rest/conf/rest.properties b/src/contrib/rest/conf/rest.properties deleted file mode 100644 index f0abb45..0000000 --- a/src/contrib/rest/conf/rest.properties +++ /dev/null @@ -1,70 +0,0 @@ -# -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -# - -# -# ZooKeeper REST Gateway Configuration file -# - -rest.port = 9998 - -# -# Endpoint definition -# - -# plain configuration <context-path>;<host-port> -rest.endpoint.1 = /;localhost:2181,localhost:2182 - -# ... or chrooted to /zookeeper -# rest.endpoint.1 = /;localhost:2181,localhost:2182/zookeeper - -# HTTP Basic authentication for this endpoint -# rest.endpoint.1.http.auth = root:root1 - -# create -e /a data digest:'demo:ojnHEyje6F33LLzGVzg+yatf4Fc=':cdrwa -# any session on this endpoint will use authentication -# rest.endpoint.1.zk.digest = demo:test - -# you can easily generate the ACL using Python: -# import sha; sha.sha('demo:test').digest().encode('base64').strip() - -# -# ... you can define as many endpoints as you wish -# - -# rest.endpoint.2 = /restricted;localhost:2181 -# rest.endpoint.2.http.auth = admin:pass - -# rest.endpoint.3 = /cluster1;localhost:2181,localhost:2182 -# ** you should configure one end-point for each ZooKeeper cluster -# etc. - -# Global HTTP Basic Authentication -# You should also enable HTTPS-only access -# The authentication credentials are sent as plain text - -# rest.http.auth = guest:guest1 - -# Uncomment the lines bellow to allow https-only access - -# rest.ssl = true -# rest.ssl.jks = keys/rest.jks -# rest.ssl.jks.pass = 123456 - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/ivy.xml ---------------------------------------------------------------------- diff --git a/src/contrib/rest/ivy.xml b/src/contrib/rest/ivy.xml deleted file mode 100644 index 903d390..0000000 --- a/src/contrib/rest/ivy.xml +++ /dev/null @@ -1,48 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<ivy-module version="2.0" - xmlns:e="http://ant.apache.org/ivy/extra"> - - <info organisation="org.apache.zookeeper" - module="${name}" revision="${version}"> - <license name="Apache 2.0"/> - <ivyauthor name="Apache ZooKeeper" url="http://zookeeper.apache.org"/> - <description>ZooKeeper REST</description> - </info> - - <configurations defaultconfmapping="default"> - <conf name="default"/> - <conf name="test"/> - </configurations> - - <dependencies> - <dependency org="org.slf4j" name="slf4j-api" rev="1.6.1"/> - <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.1" transitive="false"/> - - <!-- transitive false turns off dependency checking, log4j deps seem borked --> - <dependency org="log4j" name="log4j" rev="1.2.15" transitive="false"/> - <dependency org="asm" name="asm" rev="3.1" /> - <dependency org="com.sun.grizzly" name="grizzly-servlet-webserver" rev="1.9.8" /> - <dependency org="com.sun.jersey" name="jersey-server" rev="1.1.5.1" /> - <dependency org="com.sun.jersey" name="jersey-json" rev="1.1.5.1" /> - - <dependency org="junit" name="junit" rev="4.8.1" conf="test->default"/> - <dependency org="com.sun.jersey" name="jersey-client" rev="1.1.5.1" conf="test->default"/> - </dependencies> - -</ivy-module> http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/rest.sh ---------------------------------------------------------------------- diff --git a/src/contrib/rest/rest.sh b/src/contrib/rest/rest.sh deleted file mode 100644 index daa8198..0000000 --- a/src/contrib/rest/rest.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/sh - -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -# If this scripted is run out of /usr/bin or some other system bin directory -# it should be linked to and not copied. Things like java jar files are found -# relative to the canonical path of this script. -# - -# Only follow symlinks if readlink supports it -if readlink -f "$0" > /dev/null 2>&1 -then - ZKREST=`readlink -f "$0"` -else - ZKREST="$0" -fi -ZKREST_HOME=`dirname "$ZKREST"` - -if $cygwin -then - # cygwin has a "kill" in the shell itself, gets confused - KILL=/bin/kill -else - KILL=kill -fi - -if [ -z $ZKREST_PIDFILE ] - then ZKREST_PIDFILE=$ZKREST_HOME/server.pid -fi - -ZKREST_MAIN=org.apache.zookeeper.server.jersey.RestMain - -ZKREST_CONF=$ZKREST_HOME/conf -ZKREST_LOG=$ZKREST_HOME/zkrest.log - -CLASSPATH="$ZKREST_CONF:$CLASSPATH" - -for i in "$ZKREST_HOME"/lib/*.jar -do - CLASSPATH="$i:$CLASSPATH" -done - -for i in "$ZKREST_HOME"/zookeeper-*.jar -do - CLASSPATH="$i:$CLASSPATH" -done - -case $1 in -start) - echo "Starting ZooKeeper REST Gateway ... " - java -cp "$CLASSPATH" $JVMFLAGS $ZKREST_MAIN >$ZKREST_LOG 2>&1 & - /bin/echo -n $! > "$ZKREST_PIDFILE" - echo STARTED - ;; -stop) - echo "Stopping ZooKeeper REST Gateway ... " - if [ ! -f "$ZKREST_PIDFILE" ] - then - echo "error: could not find file $ZKREST_PIDFILE" - exit 1 - else - $KILL -9 $(cat "$ZKREST_PIDFILE") - rm "$ZKREST_PIDFILE" - echo STOPPED - fi - ;; -restart) - shift - "$0" stop ${@} - sleep 3 - "$0" start ${@} - ;; -*) - echo "Usage: $0 {start|stop|restart}" >&2 - -esac http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java deleted file mode 100644 index 954ad04..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/RestMain.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.server.jersey.cfg.Credentials; -import org.apache.zookeeper.server.jersey.cfg.Endpoint; -import org.apache.zookeeper.server.jersey.cfg.RestCfg; -import org.apache.zookeeper.server.jersey.filters.HTTPBasicAuth; - -import com.sun.grizzly.SSLConfig; -import com.sun.grizzly.http.embed.GrizzlyWebServer; -import com.sun.grizzly.http.servlet.ServletAdapter; -import com.sun.jersey.spi.container.servlet.ServletContainer; - -/** - * Demonstration of how to run the REST service using Grizzly - */ -public class RestMain { - - private static Logger LOG = LoggerFactory.getLogger(RestMain.class); - - private GrizzlyWebServer gws; - private RestCfg cfg; - - public RestMain(RestCfg cfg) { - this.cfg = cfg; - } - - public void start() throws IOException { - System.out.println("Starting grizzly ..."); - - boolean useSSL = cfg.useSSL(); - gws = new GrizzlyWebServer(cfg.getPort(), "/tmp/23cxv45345/2131xc2/", useSSL); - // BUG: Grizzly needs a doc root if you are going to register multiple adapters - - for (Endpoint e : cfg.getEndpoints()) { - ZooKeeperService.mapContext(e.getContext(), e); - gws.addGrizzlyAdapter(createJerseyAdapter(e), new String[] { e - .getContext() }); - } - - if (useSSL) { - System.out.println("Starting SSL ..."); - String jks = cfg.getJKS("keys/rest.jks"); - String jksPassword = cfg.getJKSPassword(); - - SSLConfig sslConfig = new SSLConfig(); - URL resource = getClass().getClassLoader().getResource(jks); - if (resource == null) { - LOG.error("Unable to find the keystore file: " + jks); - System.exit(2); - } - try { - sslConfig.setKeyStoreFile(new File(resource.toURI()) - .getAbsolutePath()); - } catch (URISyntaxException e1) { - LOG.error("Unable to load keystore: " + jks, e1); - System.exit(2); - } - sslConfig.setKeyStorePass(jksPassword); - gws.setSSLConfig(sslConfig); - } - - gws.start(); - } - - public void stop() { - gws.stop(); - ZooKeeperService.closeAll(); - } - - private ServletAdapter createJerseyAdapter(Endpoint e) { - ServletAdapter jersey = new ServletAdapter(); - - jersey.setServletInstance(new ServletContainer()); - jersey.addInitParameter("com.sun.jersey.config.property.packages", - "org.apache.zookeeper.server.jersey.resources"); - jersey.setContextPath(e.getContext()); - - Credentials c = Credentials.join(e.getCredentials(), cfg - .getCredentials()); - if (!c.isEmpty()) { - jersey.addFilter(new HTTPBasicAuth(c), e.getContext() - + "-basic-auth", null); - } - - return jersey; - } - - /** - * The entry point for starting the server - * - */ - public static void main(String[] args) throws Exception { - RestCfg cfg = new RestCfg("rest.properties"); - - final RestMain main = new RestMain(cfg); - main.start(); - - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - main.stop(); - System.out.println("Got exit request. Bye."); - } - }); - - printEndpoints(cfg); - System.out.println("Server started."); - } - - private static void printEndpoints(RestCfg cfg) { - int port = cfg.getPort(); - - for (Endpoint e : cfg.getEndpoints()) { - - String context = e.getContext(); - if (context.charAt(context.length() - 1) != '/') { - context += "/"; - } - - System.out.println(String.format( - "Started %s - WADL: http://localhost:%d%sapplication.wadl", - context, port, context)); - } - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java deleted file mode 100644 index 21d27a9..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/ZooKeeperService.java +++ /dev/null @@ -1,242 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import java.util.TreeSet; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.apache.zookeeper.server.jersey.cfg.Endpoint; - -/** - * Singleton which provides JAX-RS resources access to the ZooKeeper client. - * There's a single session for each base uri (so usually just one). - */ -public class ZooKeeperService { - - private static Logger LOG = LoggerFactory.getLogger(ZooKeeperService.class); - - /** Map base uri to ZooKeeper host:port parameters */ - private static Map<String, Endpoint> contextMap = new HashMap<String, Endpoint>(); - - /** Map base uri to ZooKeeper session */ - private static Map<String, ZooKeeper> zkMap = new HashMap<String, ZooKeeper>(); - - /** Session timers */ - private static Map<String, SessionTimerTask> zkSessionTimers = new HashMap<String, SessionTimerTask>(); - private static Timer timer = new Timer(); - - /** Track the status of the ZooKeeper session */ - private static class MyWatcher implements Watcher { - final String contextPath; - - /** Separate watcher for each base uri */ - public MyWatcher(String contextPath) { - this.contextPath = contextPath; - } - - /** - * Track state - in particular watch for expiration. if it happens for - * re-creation of the ZK client session - */ - synchronized public void process(WatchedEvent event) { - if (event.getState() == KeeperState.Expired) { - close(contextPath); - } - } - } - - /** ZooKeeper session timer */ - private static class SessionTimerTask extends TimerTask { - - private int delay; - private String contextPath, session; - private Timer timer; - - public SessionTimerTask(int delayInSeconds, String session, - String contextPath, Timer timer) { - delay = delayInSeconds * 1000; // convert to milliseconds - this.contextPath = contextPath; - this.session = session; - this.timer = timer; - reset(); - } - - public SessionTimerTask(SessionTimerTask t) { - this(t.delay / 1000, t.session, t.contextPath, t.timer); - } - - @Override - public void run() { - if (LOG.isInfoEnabled()) { - LOG.info(String.format("Session '%s' expired after " - + "'%d' milliseconds.", session, delay)); - } - ZooKeeperService.close(contextPath, session); - } - - public void reset() { - timer.schedule(this, delay); - } - - } - - /** - * Specify ZooKeeper host:port for a particular context path. The host:port - * string is passed to the ZK client, so this can be formatted with more - * than a single host:port pair. - */ - synchronized public static void mapContext(String contextPath, Endpoint e) { - contextMap.put(contextPath, e); - } - - /** - * Reset timer for a session - */ - synchronized public static void resetTimer(String contextPath, - String session) { - if (session != null) { - String uri = concat(contextPath, session); - - SessionTimerTask t = zkSessionTimers.remove(uri); - t.cancel(); - - zkSessionTimers.put(uri, new SessionTimerTask(t)); - } - } - - /** - * Close the ZooKeeper session and remove it from the internal maps - */ - public static void close(String contextPath) { - close(contextPath, null); - } - - /** - * Close the ZooKeeper session and remove it - */ - synchronized public static void close(String contextPath, String session) { - String uri = concat(contextPath, session); - - TimerTask t = zkSessionTimers.remove(uri); - if (t != null) { - t.cancel(); - } - - ZooKeeper zk = zkMap.remove(uri); - if (zk == null) { - return; - } - try { - zk.close(); - } catch (InterruptedException e) { - LOG.error("Interrupted while closing ZooKeeper connection.", e); - } - } - - /** - * Close all the ZooKeeper sessions and remove them from the internal maps - */ - synchronized public static void closeAll() { - Set<String> sessions = new TreeSet<String>(zkMap.keySet()); - for (String key : sessions) { - close(key); - } - } - - /** - * Is there an active connection for this session? - */ - synchronized public static boolean isConnected(String contextPath, - String session) { - return zkMap.containsKey(concat(contextPath, session)); - } - - /** - * Return a ZooKeeper client not tied to a specific session. - */ - public static ZooKeeper getClient(String contextPath) throws IOException { - return getClient(contextPath, null); - } - - /** - * Return a ZooKeeper client for a session with a default expire time - * - * @throws IOException - */ - public static ZooKeeper getClient(String contextPath, String session) - throws IOException { - return getClient(contextPath, session, 5); - } - - /** - * Return a ZooKeeper client which may or may not be connected, but it will - * not be expired. This method can be called multiple times, the same object - * will be returned except in the case where the session expires (at which - * point a new session will be returned) - */ - synchronized public static ZooKeeper getClient(String contextPath, - String session, int expireTime) throws IOException { - final String connectionId = concat(contextPath, session); - - ZooKeeper zk = zkMap.get(connectionId); - if (zk == null) { - - if (LOG.isInfoEnabled()) { - LOG.info(String.format("creating new " - + "connection for : '%s'", connectionId)); - } - Endpoint e = contextMap.get(contextPath); - zk = new ZooKeeper(e.getHostPort(), 30000, new MyWatcher( - connectionId)); - - for (Map.Entry<String, String> p : e.getZooKeeperAuthInfo().entrySet()) { - zk.addAuthInfo("digest", String.format("%s:%s", p.getKey(), - p.getValue()).getBytes()); - } - - zkMap.put(connectionId, zk); - - // a session should automatically expire after an amount of time - if (session != null) { - zkSessionTimers.put(connectionId, new SessionTimerTask( - expireTime, session, contextPath, timer)); - } - } - return zk; - } - - private static String concat(String contextPath, String session) { - if (session != null) { - return String.format("%s@%s", contextPath, session); - } - return contextPath; - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java deleted file mode 100644 index 0730be5..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Credentials.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.cfg; - -import java.util.HashMap; - -public class Credentials extends HashMap<String, String> { - - public static Credentials join(Credentials a, Credentials b) { - Credentials result = new Credentials(); - result.putAll(a); - result.putAll(b); - return result; - } - - public Credentials() { - super(); - } - - public Credentials(String credentials) { - super(); - - if (!credentials.trim().equals("")) { - String[] parts = credentials.split(","); - for(String p : parts) { - String[] userPass = p.split(":"); - put(userPass[0], userPass[1]); - } - } - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java deleted file mode 100644 index 2a62782..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/Endpoint.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.cfg; - -public class Endpoint { - - private String context; - private HostPortSet hostPort; - private Credentials credentials; - private Credentials zookeeperAuth; - - public Endpoint(String context, String hostPortList) { - this.context = context; - this.hostPort = new HostPortSet(hostPortList); - } - - public String getContext() { - return context; - } - - public String getHostPort() { - return hostPort.toString(); - } - - public Credentials getCredentials() { - return credentials; - } - - public void setCredentials(String c) { - this.credentials = new Credentials(c); - } - - public void setZooKeeperAuthInfo(String digest) { - zookeeperAuth = new Credentials(digest); - } - - public final Credentials getZooKeeperAuthInfo() { - return zookeeperAuth; - } - - @Override - public boolean equals(Object o) { - Endpoint e = (Endpoint) o; - return context.equals(e.context); - } - - @Override - public int hashCode() { - return context.hashCode(); - } - - @Override - public String toString() { - return String.format("<Endpoint %s %s>", context, hostPort.toString()); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java deleted file mode 100644 index 51a1bdd..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPort.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.cfg; - -public class HostPort { - - private String host; - private int port; - - public HostPort(String hostPort) { - String[] parts = hostPort.split(":"); - host = parts[0]; - port = Integer.parseInt(parts[1]); - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - @Override - public boolean equals(Object o) { - HostPort p = (HostPort) o; - return host.equals(p.host) && port == p.port; - } - - @Override - public int hashCode() { - return String.format("%s:%d", host, port).hashCode(); - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java deleted file mode 100644 index 301a565..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/HostPortSet.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.cfg; - -import java.util.HashSet; -import java.util.Set; - -public class HostPortSet { - - private Set<HostPort> hostPortSet = new HashSet<HostPort>(); - private String original; - - public HostPortSet(String hostPortList) { - original = hostPortList; - - int chrootStart = hostPortList.indexOf('/'); - String hostPortPairs; - if (chrootStart != -1) { - hostPortPairs = hostPortList.substring(0, chrootStart); - } else { - hostPortPairs = hostPortList; - } - - String[] parts = hostPortPairs.split(","); - for(String p : parts) { - hostPortSet.add(new HostPort(p)); - } - } - - @Override - public String toString() { - return original; - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java deleted file mode 100644 index 93dd632..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.cfg; - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; - -public class RestCfg { - - private Properties cfg = new Properties(); - - private Set<Endpoint> endpoints = new HashSet<Endpoint>(); - private Credentials credentials = new Credentials(); - - public RestCfg(String resource) throws IOException { - this(RestCfg.class.getClassLoader().getResourceAsStream(resource)); - } - - public RestCfg(InputStream io) throws IOException { - try { - cfg.load(io); - extractEndpoints(); - extractCredentials(); - } finally { - io.close(); - } - } - - private void extractCredentials() { - if (cfg.containsKey("rest.http.auth")) { - credentials = new Credentials(cfg.getProperty("rest.http.auth", "")); - } - } - - private void extractEndpoints() { - int count = 1; - while (true) { - String e = cfg.getProperty( - String.format("rest.endpoint.%d", count), null); - if (e == null) { - break; - } - - String[] parts = e.split(";"); - if (parts.length != 2) { - count++; - continue; - } - Endpoint point = new Endpoint(parts[0], parts[1]); - - String c = cfg.getProperty(String.format( - "rest.endpoint.%d.http.auth", count), ""); - point.setCredentials(c); - - String digest = cfg.getProperty(String.format( - "rest.endpoint.%d.zk.digest", count), ""); - point.setZooKeeperAuthInfo(digest); - - endpoints.add(point); - count++; - } - } - - public int getPort() { - return Integer.parseInt(cfg.getProperty("rest.port", "9998")); - } - - public boolean useSSL() { - return Boolean.valueOf(cfg.getProperty("rest.ssl", "false")); - } - - public final Set<Endpoint> getEndpoints() { - return endpoints; - } - - public final Credentials getCredentials() { - return credentials; - } - - public String getJKS() { - return cfg.getProperty("rest.ssl.jks"); - } - - public String getJKS(String def) { - return cfg.getProperty("rest.ssl.jks", def); - } - - public String getJKSPassword() { - return cfg.getProperty("rest.ssl.jks.pass"); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java deleted file mode 100644 index 49640b5..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/filters/HTTPBasicAuth.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.filters; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.zookeeper.server.jersey.cfg.Credentials; - -import com.sun.jersey.core.util.Base64; - -public class HTTPBasicAuth implements Filter { - - private Credentials credentials; - - public HTTPBasicAuth(Credentials c) { - credentials = c; - } - - @Override - public void doFilter(ServletRequest req0, ServletResponse resp0, - FilterChain chain) throws IOException, ServletException { - - HttpServletRequest request = (HttpServletRequest) req0; - HttpServletResponse response = (HttpServletResponse) resp0; - - String authorization = request.getHeader("Authorization"); - if (authorization != null) { - String c[] = parseAuthorization(authorization); - if (c != null && credentials.containsKey(c[0]) - && credentials.get(c[0]).equals(c[1])) { - chain.doFilter(request, response); - return; - } - } - - response.setHeader("WWW-Authenticate", "Basic realm=\"Restricted\""); - response.sendError(401); - } - - private String[] parseAuthorization(String authorization) { - String parts[] = authorization.split(" "); - if (parts.length == 2 && parts[0].equalsIgnoreCase("Basic")) { - String userPass = Base64.base64Decode(parts[1]); - - int p = userPass.indexOf(":"); - if (p != -1) { - return new String[] { userPass.substring(0, p), - userPass.substring(p + 1) }; - } - } - return null; - } - - @Override - public void init(FilterConfig arg0) throws ServletException { - } - - @Override - public void destroy() { - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java deleted file mode 100644 index b3fad55..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildren.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.jaxb; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; - - -/** - * Represents the CHILD using JAXB. - * Special JSON version is required to get proper formatting in both - * JSON and XML output. See details in ZNodeResource. - */ -@XmlRootElement(name="child") -public class ZChildren { - public String path; - public String uri; - - public String child_uri_template; - @XmlElementWrapper(name="children") - @XmlElement(name="child") - public List<String> children; - - public ZChildren() { - // needed by jersey - children = new ArrayList<String>(); - } - - public ZChildren(String path, String uri, String child_uri_template, - List<String> children) - { - this.path = path; - this.uri = uri; - this.child_uri_template = child_uri_template; - if (children != null) { - this.children = children; - } else { - this.children = new ArrayList<String>(); - } - } - - @Override - public int hashCode() { - return path.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ZChildren)) { - return false; - } - ZChildren o = (ZChildren) obj; - return path.equals(o.path) && children.equals(o.children); - } - - @Override - public String toString() { - return "ZChildren(" + path + "," + children + ")"; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java deleted file mode 100644 index 0dcece0..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZChildrenJSON.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.jaxb; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlRootElement; - - -/** - * Represents the CHILD using JAXB. - * Special JSON version is required to get proper formatting in both - * JSON and XML output. See details in ZNodeResource. - */ -@XmlRootElement(name="child") -public class ZChildrenJSON { - public String path; - public String uri; - - public String child_uri_template; - public List<String> children; - - public ZChildrenJSON() { - // needed by jersey - children = new ArrayList<String>(); - } - - public ZChildrenJSON(String path, String uri, String child_uri_template, - List<String> children) - { - this.path = path; - this.uri = uri; - this.child_uri_template = child_uri_template; - if (children != null) { - this.children = children; - } else { - this.children = new ArrayList<String>(); - } - } - - @Override - public int hashCode() { - return path.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ZChildrenJSON)) { - return false; - } - ZChildrenJSON o = (ZChildrenJSON) obj; - return path.equals(o.path) && children.equals(o.children); - } - - @Override - public String toString() { - return "ZChildrenJSON(" + path + "," + children + ")"; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java deleted file mode 100644 index e976ee0..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZError.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.jaxb; - -import javax.xml.bind.annotation.XmlRootElement; - - -/** - * Represents an ERROR using JAXB. - */ -@XmlRootElement(name="error") -public class ZError { - public String request; - public String message; - - public ZError(){ - // needed by jersey - } - - public ZError(String request, String message) { - this.request = request; - this.message = message; - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java deleted file mode 100644 index 4d83717..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZPath.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.jaxb; - -import javax.xml.bind.annotation.XmlRootElement; - - -/** - * Represents a PATH using JAXB. - */ -@XmlRootElement(name="path") -public class ZPath { - public String path; - public String uri; - - public ZPath(){ - // needed by jersey - } - - public ZPath(String path) { - this(path, null); - } - - public ZPath(String path, String uri) { - this.path = path; - this.uri = uri; - } - - @Override - public int hashCode() { - return path.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ZPath)) { - return false; - } - ZPath o = (ZPath) obj; - return path.equals(o.path); - } - - @Override - public String toString() { - return "ZPath(" + path + ")"; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java deleted file mode 100644 index 06ca9e5..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZSession.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.jaxb; - -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name="session") -public class ZSession { - public String id; - public String uri; - - public ZSession() { - // needed by jersey - } - - public ZSession(String id, String uri) { - this.id = id; - this.uri = uri; - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof ZSession)) { - return false; - } - ZSession s = (ZSession) obj; - return id.equals(s.id); - } - - @Override - public String toString() { - return "ZSession(" + id +")"; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java deleted file mode 100644 index af70d18..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/jaxb/ZStat.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.jaxb; - -import javax.xml.bind.annotation.XmlRootElement; - - -/** - * Represents a STAT using JAXB. - */ -@XmlRootElement(name="stat") -public class ZStat { - public String path; - public String uri; - public byte[] data64; - public String dataUtf8; - - public long czxid; - public long mzxid; - public long ctime; - public long mtime; - public int version; - public int cversion; - public int aversion; - public long ephemeralOwner; - public int dataLength; - public int numChildren; - public long pzxid; - - - public ZStat(){ - // needed by jersey - } - - public ZStat(String path, byte[] data64, String dataUtf8) - { - this.path = path; - this.data64 = data64; - this.dataUtf8 = dataUtf8; - } - - public ZStat(String path, String uri, byte[] data64, String dataUtf8, - long czxid, long mzxid, long ctime, long mtime, int version, - int cversion, int aversion, long ephemeralOwner, int dataLength, - int numChildren, long pzxid) - { - this.path = path; - this.uri = uri; - this.data64 = data64; - this.dataUtf8 = dataUtf8; - - this.czxid = czxid; - this.mzxid = mzxid; - this.ctime = ctime; - this.mtime = mtime; - this.version = version; - this.cversion = cversion; - this.aversion = aversion; - this.ephemeralOwner = ephemeralOwner; - this.dataLength = dataLength; - this.numChildren = numChildren; - this.pzxid = pzxid; - } - - @Override - public int hashCode() { - return path.hashCode(); - } - - /** - * This method considers two ZStats equal if their path, encoding, and - * data match. It does not compare the ZooKeeper - * org.apache.zookeeper.data.Stat class fields. - */ - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ZStat)) { - return false; - } - ZStat o = (ZStat) obj; - return toString().equals(o.toString()); - } - - @Override - public String toString() { - return "ZStat(" + path + "," + "b64[" - + (data64 == null ? null : new String(data64)) + "]," - + dataUtf8 + ")"; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java deleted file mode 100644 index 0893586..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/JAXBContextResolver.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.resources; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.JAXBContext; - -import org.apache.zookeeper.server.jersey.jaxb.ZChildrenJSON; -import org.apache.zookeeper.server.jersey.jaxb.ZPath; -import org.apache.zookeeper.server.jersey.jaxb.ZStat; - -import com.sun.jersey.api.json.JSONConfiguration; -import com.sun.jersey.api.json.JSONJAXBContext; - -/** - * Tell Jersey how to resolve JSON formatting. Specifically detail the - * fields which are arrays and which are numbers (not strings). - */ -@Provider -@SuppressWarnings("unchecked") -public final class JAXBContextResolver implements ContextResolver<JAXBContext> { - private final JAXBContext context; - - private final Set<Class> typesSet; - - public JAXBContextResolver() throws Exception { - Class[] typesArr = - new Class[]{ZPath.class, ZStat.class, ZChildrenJSON.class}; - typesSet = new HashSet<Class>(Arrays.asList(typesArr)); - context = new JSONJAXBContext( - JSONConfiguration.mapped() - .arrays("children") - .nonStrings("czxid") - .nonStrings("mzxid") - .nonStrings("ctime") - .nonStrings("mtime") - .nonStrings("version") - .nonStrings("cversion") - .nonStrings("aversion") - .nonStrings("ephemeralOwner") - .nonStrings("dataLength") - .nonStrings("numChildren") - .nonStrings("pzxid") - .build(), - typesArr); - } - - public JAXBContext getContext(Class<?> objectType) { - return (typesSet.contains(objectType)) ? context : null; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java deleted file mode 100644 index fdfc27b..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/KeeperExceptionMapper.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.resources; - -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.server.jersey.jaxb.ZError; - - -/** - * Map KeeperException to HTTP status codes - */ -@Provider -public class KeeperExceptionMapper implements ExceptionMapper<KeeperException> { - private UriInfo ui; - - public KeeperExceptionMapper(@Context UriInfo ui) { - this.ui = ui; - } - - public Response toResponse(KeeperException e) { - Response.Status status; - String message; - - String path = e.getPath(); - - switch(e.code()) { - case AUTHFAILED: - status = Response.Status.UNAUTHORIZED; - message = path + " not authorized"; - break; - case BADARGUMENTS: - status = Response.Status.BAD_REQUEST; - message = path + " bad arguments"; - break; - case BADVERSION: - status = Response.Status.PRECONDITION_FAILED; - message = path + " bad version"; - break; - case INVALIDACL: - status = Response.Status.BAD_REQUEST; - message = path + " invalid acl"; - break; - case NODEEXISTS: - status = Response.Status.CONFLICT; - message = path + " already exists"; - break; - case NONODE: - status = Response.Status.NOT_FOUND; - message = path + " not found"; - break; - case NOTEMPTY: - status = Response.Status.CONFLICT; - message = path + " not empty"; - break; - default: - status = Response.Status.fromStatusCode(502); // bad gateway - message = "Error processing request for " + path - + " : " + e.getMessage(); - } - - return Response.status(status).entity( - new ZError(ui.getRequestUri().toString(), message)).build(); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java deleted file mode 100644 index 46f33bb..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.resources; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -import org.apache.zookeeper.server.jersey.jaxb.ZError; - -/** - * Map RuntimeException to HTTP status codes - */ -@Provider -public class RuntimeExceptionMapper - implements ExceptionMapper<RuntimeException> -{ - private UriInfo ui; - - public RuntimeExceptionMapper(@Context UriInfo ui) { - this.ui = ui; - } - - public Response toResponse(RuntimeException e) { - // don't try to handle jersey exceptions ourselves - if (e instanceof WebApplicationException) { - WebApplicationException ie =(WebApplicationException) e; - return ie.getResponse(); - } - - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( - new ZError(ui.getRequestUri().toString(), - "Error processing request due to " + e - )).build(); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java deleted file mode 100644 index 0744604..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/SessionsResource.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.resources; - -import java.io.IOException; -import java.net.URI; -import java.util.UUID; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.zookeeper.server.jersey.ZooKeeperService; -import org.apache.zookeeper.server.jersey.jaxb.ZError; -import org.apache.zookeeper.server.jersey.jaxb.ZSession; - -import com.sun.jersey.api.json.JSONWithPadding; - -@Path("sessions/v1/{session: .*}") -public class SessionsResource { - - private static Logger LOG = LoggerFactory.getLogger(SessionsResource.class); - - private String contextPath; - - public SessionsResource(@Context HttpServletRequest request) { - contextPath = request.getContextPath(); - if (contextPath.equals("")) { - contextPath = "/"; - } - } - - @PUT - @Produces( { MediaType.APPLICATION_JSON, "application/javascript", - MediaType.APPLICATION_XML }) - @Consumes(MediaType.APPLICATION_OCTET_STREAM) - public Response keepAliveSession(@PathParam("session") String session, - @Context UriInfo ui, byte[] data) { - - if (!ZooKeeperService.isConnected(contextPath, session)) { - throwNotFound(session, ui); - } - - ZooKeeperService.resetTimer(contextPath, session); - return Response.status(Response.Status.OK).build(); - } - - @POST - @Produces( { MediaType.APPLICATION_JSON, "application/javascript", - MediaType.APPLICATION_XML }) - public Response createSession(@QueryParam("op") String op, - @DefaultValue("5") @QueryParam("expire") String expire, - @Context UriInfo ui) { - if (!op.equals("create")) { - throw new WebApplicationException(Response.status( - Response.Status.BAD_REQUEST).entity( - new ZError(ui.getRequestUri().toString(), "")).build()); - } - - int expireInSeconds; - try { - expireInSeconds = Integer.parseInt(expire); - } catch (NumberFormatException e) { - throw new WebApplicationException(Response.status( - Response.Status.BAD_REQUEST).build()); - } - - String uuid = UUID.randomUUID().toString(); - while (ZooKeeperService.isConnected(contextPath, uuid)) { - uuid = UUID.randomUUID().toString(); - } - - // establish the connection to the ZooKeeper cluster - try { - ZooKeeperService.getClient(contextPath, uuid, expireInSeconds); - } catch (IOException e) { - LOG.error("Failed while trying to create a new session", e); - - throw new WebApplicationException(Response.status( - Response.Status.INTERNAL_SERVER_ERROR).build()); - } - - URI uri = ui.getAbsolutePathBuilder().path(uuid).build(); - return Response.created(uri).entity( - new JSONWithPadding(new ZSession(uuid, uri.toString()))) - .build(); - } - - @DELETE - @Produces( { MediaType.APPLICATION_JSON, "application/javascript", - MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM }) - public void deleteSession(@PathParam("session") String session, - @Context UriInfo ui) { - ZooKeeperService.close(contextPath, session); - } - - private static void throwNotFound(String session, UriInfo ui) - throws WebApplicationException { - throw new WebApplicationException(Response.status( - Response.Status.NOT_FOUND).entity( - new ZError(ui.getRequestUri().toString(), session - + " not found")).build()); - } - -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/63aaf0a1/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java ---------------------------------------------------------------------- diff --git a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java b/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java deleted file mode 100644 index 706ab89..0000000 --- a/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZErrorWriter.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server.jersey.resources; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyWriter; -import javax.ws.rs.ext.Provider; - -import org.apache.zookeeper.server.jersey.jaxb.ZError; - -/** - * Tell Jersey how to format an octet response error message. - */ -@Produces(MediaType.APPLICATION_OCTET_STREAM) -@Provider -public class ZErrorWriter implements MessageBodyWriter<ZError> { - - public long getSize(ZError t, Class<?> type, Type genericType, - Annotation[] annotations, MediaType mediaType) { - return -1; - } - - public boolean isWriteable(Class<?> type, Type genericType, - Annotation[] annotations, MediaType mediaType) { - return ZError.class.isAssignableFrom(type); - } - - public void writeTo(ZError t, Class<?> type, Type genericType, - Annotation[] annotations, MediaType mediaType, - MultivaluedMap<String, Object> httpHeaders, - OutputStream os) - throws IOException, WebApplicationException - { - PrintStream p = new PrintStream(os); - p.print("Request " + t.request + " failed due to " + t.message); - p.flush(); - } -}
