Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-added the meteredoutputstream and turned auth on for push, pull an…
…d ack.
- Loading branch information
Showing
5 changed files
with
142 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
symmetric/src/main/java/org/jumpmind/symmetric/web/AbstractServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.jumpmind.symmetric.web; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.jumpmind.symmetric.common.Constants; | ||
import org.jumpmind.symmetric.service.IDataExtractorService; | ||
import org.jumpmind.symmetric.service.IDataLoaderService; | ||
import org.jumpmind.symmetric.service.INodeService; | ||
import org.jumpmind.symmetric.transport.IOutgoingTransport; | ||
import org.jumpmind.symmetric.transport.internal.InternalOutgoingTransport; | ||
import org.jumpmind.symmetric.transport.metered.MeteredOutputStreamOutgoingTransport; | ||
import org.jumpmind.symmetric.util.MeteredOutputStream; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.web.context.support.WebApplicationContextUtils; | ||
|
||
abstract public class AbstractServlet extends HttpServlet { | ||
|
||
protected int getDownloadRate() { | ||
return (Integer) getContext().getBean(Constants.DOWNLOAD_RATE); | ||
} | ||
|
||
protected abstract Log getLogger(); | ||
|
||
protected IOutgoingTransport createOutgoingTransport( | ||
HttpServletResponse resp) throws IOException { | ||
int downloadRate = getDownloadRate(); | ||
if (downloadRate > 0) { | ||
return new MeteredOutputStreamOutgoingTransport(resp | ||
.getOutputStream(), downloadRate*MeteredOutputStream.KB); | ||
} else { | ||
return new InternalOutgoingTransport(resp.getOutputStream()); | ||
} | ||
} | ||
|
||
protected OutputStream createOutputStream(HttpServletResponse resp) | ||
throws IOException { | ||
int downloadRate = getDownloadRate(); | ||
if (downloadRate > 0) { | ||
return new MeteredOutputStream(resp.getOutputStream(), downloadRate*MeteredOutputStream.KB); | ||
} else { | ||
return resp.getOutputStream(); | ||
} | ||
} | ||
|
||
protected InputStream createInputStream(HttpServletRequest req) | ||
throws IOException { | ||
InputStream is = null; | ||
|
||
if (getLogger().isDebugEnabled()) { | ||
StringBuilder b = new StringBuilder(); | ||
BufferedReader reader = req.getReader(); | ||
String line = null; | ||
do { | ||
line = reader.readLine(); | ||
if (line != null) { | ||
b.append(line); | ||
b.append("\n"); | ||
} | ||
} while (line != null); | ||
|
||
getLogger().debug("Received: \n" + b); | ||
is = new ByteArrayInputStream(b.toString().getBytes()); | ||
} else { | ||
is = req.getInputStream(); | ||
} | ||
|
||
return is; | ||
} | ||
|
||
protected ApplicationContext getContext() { | ||
return WebApplicationContextUtils | ||
.getWebApplicationContext(getServletContext()); | ||
} | ||
|
||
protected IDataLoaderService getDataLoaderService() { | ||
return (IDataLoaderService) getContext().getBean( | ||
Constants.DATALOADER_SERVICE); | ||
} | ||
|
||
protected INodeService getNodeService() { | ||
return (INodeService) getContext().getBean(Constants.NODE_SERVICE); | ||
} | ||
|
||
protected IDataExtractorService getDataExtractorService() { | ||
return (IDataExtractorService) getContext().getBean( | ||
Constants.DATAEXTRACTOR_SERVICE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters