/* * 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.gump.mvnrepoproxy.restlets; import org.apache.gump.mvnrepoproxy.HostResolver; import org.restlet.Context; import org.restlet.Redirector; import org.restlet.Restlet; import org.restlet.data.Request; import org.restlet.data.Response; import org.restlet.resource.Representation; /** * Proxy that retrieves resources from the "real" mvn repository. * *
This is a very thin layer on top of Redirector.
*/ public class Proxy extends Restlet { private final String template; public Proxy(Context ctx, String template) { super(ctx); this.template = template; } /** * Used when invoked via ArtifactResource */ public Representation serve(Request request, Response response) { Response r = getRedirector(request).handle(request); response.setStatus(r.getStatus()); return r.getEntity(); } /** * Used when invoked as fallback */ @Override public void handle(Request request, Response response) { getRedirector(request).handle(request, response); } private Redirector getRedirector(Request request) { String host = HostResolver.getHostForPath(request.getResourceRef() .getPath()); Redirector redirector = new Redirector(getContext(), host + template, Redirector.MODE_DISPATCHER); return redirector; } }