package de.saumya.mojo.rubygems;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.sonatype.nexus.ruby.FileType;
import org.sonatype.nexus.ruby.GemArtifactFile;
import org.sonatype.nexus.ruby.RubygemsFile;
import org.sonatype.nexus.ruby.cuba.RubygemsFileSystem;
import org.sonatype.nexus.ruby.layout.Storage;

public class LegacyRubygemsServlet extends RubygemsServlet
{
    private static final long serialVersionUID = 2441264980328145654L;

    @Override
    public void init() throws ServletException {
        super.init();
        
        this.fileSystem = (RubygemsFileSystem) getServletContext().getAttribute( RubygemsFileSystem.class.getName() );
        this.storage = (Storage) getServletContext().getAttribute( Storage.class.getName());
    }
    
    protected void handle( HttpServletRequest req, HttpServletResponse resp, RubygemsFile file ) 
            throws IOException, ServletException
    {
        if ( file.type() == FileType.GEM_ARTIFACT )
        {
            resp.sendRedirect( "https://rubygems.org/gems/" + ((GemArtifactFile) file ).gem( null ).filename() + ".gem" );
        }
        else
        {
            super.handle( req, resp, file );
        }
    }
}
@@ -560,16 +560,128 @@
 5654L;%0A%0A
+    private static final String RUBYGEMS_S3_URL = %22http://s3.amazonaws.com/production.s3.rubygems.org/gems/%22;%0A %0A
     @Ove
@@ -1220,55 +1220,223 @@
     
-resp.sendRedirect( %22https://rubygems.org/gems/%22
+// use a non https url here since IVY can not handle%0A            // redirects from https to http%0A            // https://github.com/torquebox/rubygems-servlets/issues/11%0A            resp.sendRedirect( RUBYGEMS_S3_URL
  + (
@@ -1589,9 +1589,10 @@
 %7D%0A    %7D%0A
-
 %7D
+%0A

add AWS url for gem redirects on legacy repo