org.apache.shindig.protocol.ApiServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shindig-common Show documentation
Show all versions of shindig-common Show documentation
Common java code for Shindig
The newest version!
/*
* 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.shindig.protocol;
import org.apache.shindig.auth.AuthInfoUtil;
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.common.logging.i18n.MessageKeys;
import org.apache.shindig.common.servlet.InjectedServlet;
import org.apache.shindig.config.ContainerConfig;
import org.apache.shindig.protocol.conversion.BeanConverter;
import org.apache.shindig.protocol.conversion.BeanJsonConverter;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
/**
* Common base class for API servlets.
*/
public abstract class ApiServlet extends InjectedServlet {
private static final String classname = ApiServlet.class.getName();
private static final Logger LOG = Logger.getLogger(classname, MessageKeys.MESSAGES);
protected static final String FORMAT_PARAM = "format";
protected static final String JSON_FORMAT = "json";
protected static final String ATOM_FORMAT = "atom";
protected static final String XML_FORMAT = "xml";
protected static final String DEFAULT_ENCODING = "UTF-8";
/** ServletConfig parameter set to provide an explicit named binding for handlers */
public static final String HANDLERS_PARAM = "handlers";
/** The default key used to look up handlers if the servlet config parameter is not available */
public static final Key> DEFAULT_HANDLER_KEY =
Key.get(new TypeLiteral>(){}, Names.named("org.apache.shindig.protocol.handlers"));
protected HandlerRegistry dispatcher;
protected BeanJsonConverter jsonConverter;
protected BeanConverter xmlConverter;
protected BeanConverter atomConverter;
protected ContainerConfig containerConfig;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Lookup the set of handlers to bind to this api endpoint and
// populate the registry with them
String handlers = config.getInitParameter(HANDLERS_PARAM);
Key> handlerKey;
if (handlers == null || "".equals(handlers)) {
handlerKey = DEFAULT_HANDLER_KEY;
} else {
handlerKey = Key.get(new TypeLiteral>(){}, Names.named(handlers));
}
this.dispatcher.addHandlers(injector.getInstance(handlerKey));
this.dispatcher.addHandlers(Collections.
© 2015 - 2024 Weber Informatics LLC | Privacy Policy