Skip to content

Commit

Permalink
0001211: Backwards compatibility change. Use the client's Charset-Acc…
Browse files Browse the repository at this point in the history
…ept http header to decide what encoding to use.
  • Loading branch information
chenson42 committed May 14, 2013
1 parent 02e34ef commit 11b69ec
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
Expand Up @@ -106,7 +106,7 @@ protected int sendMessage(URL url, String data) throws IOException {
public static HttpURLConnection openConnection(URL url, String username, String password)
throws IOException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty(WebConstants.HEADER_ACCEPT_CHARSET, IoConstants.ENCODING);
setBasicAuthIfNeeded(conn, username, password);
return conn;
}
Expand Down
Expand Up @@ -23,9 +23,9 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import org.apache.commons.io.IOUtils;
import org.jumpmind.symmetric.io.IoConstants;
import org.jumpmind.symmetric.model.ChannelMap;
import org.jumpmind.symmetric.service.IConfigurationService;
import org.jumpmind.symmetric.transport.IOutgoingTransport;
Expand All @@ -40,13 +40,13 @@ public class InternalOutgoingTransport implements IOutgoingTransport {

boolean open = true;

public InternalOutgoingTransport(OutputStream os) throws UnsupportedEncodingException {
this(os, new ChannelMap());
public InternalOutgoingTransport(OutputStream os, String encoding) throws UnsupportedEncodingException {
this(os, new ChannelMap(), encoding);
}

public InternalOutgoingTransport(OutputStream os, ChannelMap map) throws UnsupportedEncodingException {
public InternalOutgoingTransport(OutputStream os, ChannelMap map, String encoding) throws UnsupportedEncodingException {
this.os = os;
this.writer = new BufferedWriter(new OutputStreamWriter(os, IoConstants.ENCODING));
this.writer = new BufferedWriter(new OutputStreamWriter(os, encoding == null ? Charset.defaultCharset().name() : encoding));
this.map = map;
}

Expand Down
Expand Up @@ -103,7 +103,7 @@ public IIncomingTransport getPullTransport(Node remote, final Node local, String
public void run(ISymmetricEngine engine, InputStream is, OutputStream os)
throws Exception {
IOutgoingTransport transport = new InternalOutgoingTransport(respOs,
suspendIgnoreChannels);
suspendIgnoreChannels, IoConstants.ENCODING);
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(
new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), local
.getNodeId(), ProcessType.PULL_HANDLER));
Expand Down
Expand Up @@ -23,6 +23,8 @@
* Constants that are related to the HTTP transport
*/
public class WebConstants {

public static final String HEADER_ACCEPT_CHARSET = "Accept-Charset";

public static final String METHOD_GET = "GET";

Expand Down
Expand Up @@ -70,12 +70,12 @@ public List<IInterceptor> getInterceptors() {
return interceptors;
}

protected IOutgoingTransport createOutgoingTransport(OutputStream outputStream, ChannelMap map) throws IOException {
return new InternalOutgoingTransport(outputStream, map);
protected IOutgoingTransport createOutgoingTransport(OutputStream outputStream, String encoding, ChannelMap map) throws IOException {
return new InternalOutgoingTransport(outputStream, map, encoding);
}

protected IOutgoingTransport createOutgoingTransport(OutputStream outputStream) throws IOException {
return new InternalOutgoingTransport(outputStream, new ChannelMap());
protected IOutgoingTransport createOutgoingTransport(OutputStream outputStream, String encoding) throws IOException {
return new InternalOutgoingTransport(outputStream, new ChannelMap(), encoding);
}

public void setEnabled(boolean enabled) {
Expand Down
Expand Up @@ -55,7 +55,8 @@ public void handle(HttpServletRequest req, HttpServletResponse res) throws IOExc
log.debug("File sync pull request received from {}", nodeId);
}

IOutgoingTransport outgoingTransport = createOutgoingTransport(res.getOutputStream(),
IOutgoingTransport outgoingTransport = createOutgoingTransport(res.getOutputStream(),
req.getHeader(WebConstants.HEADER_ACCEPT_CHARSET),
engine.getConfigurationService().getSuspendIgnoreChannelLists(nodeId));
ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(
new ProcessInfoKey(engine.getNodeService().findIdentityNodeId(), nodeId,
Expand Down
Expand Up @@ -27,6 +27,7 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.symmetric.io.IoConstants;
import org.jumpmind.symmetric.model.ChannelMap;
import org.jumpmind.symmetric.model.NodeSecurity;
import org.jumpmind.symmetric.model.ProcessInfo;
Expand Down Expand Up @@ -85,14 +86,14 @@ public void handleWithCompression(HttpServletRequest req, HttpServletResponse re
map.addIgnoreChannels(req.getHeader(WebConstants.IGNORED_CHANNELS));

// pull out headers and pass to pull() method
pull(nodeId, req.getRemoteHost(), req.getRemoteAddr(), res.getOutputStream(), map);
pull(nodeId, req.getRemoteHost(), req.getRemoteAddr(), res.getOutputStream(), req.getHeader(WebConstants.HEADER_ACCEPT_CHARSET), map);

log.debug("Done with Pull request from {}", nodeId);

}

public void pull(String nodeId, String remoteHost, String remoteAddress,
OutputStream outputStream, ChannelMap map) throws IOException {
OutputStream outputStream, String encoding, ChannelMap map) throws IOException {
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
long ts = System.currentTimeMillis();
try {
Expand All @@ -108,7 +109,7 @@ public void pull(String nodeId, String remoteHost, String remoteAddress,
registrationService.registerNode(nodeService.findNode(nodeId), remoteHost,
remoteAddress, outputStream, false);
} else {
IOutgoingTransport outgoingTransport = createOutgoingTransport(outputStream,
IOutgoingTransport outgoingTransport = createOutgoingTransport(outputStream, encoding,
map);
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(
nodeService.findIdentityNodeId(), nodeId, ProcessType.PULL_HANDLER));
Expand Down

0 comments on commit 11b69ec

Please sign in to comment.