Skip to content

Commit

Permalink
[ 1917655 ] all done other than the lack of a few unit tests :)
Browse files Browse the repository at this point in the history
  • Loading branch information
knaas committed Mar 19, 2008
1 parent c27b809 commit 46366b6
Show file tree
Hide file tree
Showing 38 changed files with 1,547 additions and 645 deletions.
53 changes: 8 additions & 45 deletions symmetric/src/docbook/user-guide/ch04-architecture.xml
Expand Up @@ -77,7 +77,9 @@
As a web application archive, a WAR or EAR file is deployed to an application server,
such as Tomcat, Jetty, or JBoss. The <filename>WEB-INF/web.xml</filename> file
is configured with a <literal>SymmetricEngineContextLoaderListener</literal>
and the required Servlet mappings.
the required SymmetricFilter mapping, and the required SymmetricServlet mapping.
Note that this was changed in version 1.4.0 to make it easier to configure
Symmetric.
</para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
Expand Down Expand Up @@ -112,60 +114,21 @@
</listener>
<servlet>
<servlet-name>push</servlet-name>
<servlet-name>SymmetricServlet</servlet-name>
<servlet-class>
org.jumpmind.symmetric.web.PushServlet
org.jumpmind.symmetric.web.SymmetricServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>pull</servlet-name>
<servlet-class>
org.jumpmind.symmetric.web.PullServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>registration</servlet-name>
<servlet-class>
org.jumpmind.symmetric.web.RegistrationServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>ack</servlet-name>
<servlet-class>
org.jumpmind.symmetric.web.AckServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>push</servlet-name>
<url-pattern>/push/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ack</servlet-name>
<url-pattern>/ack/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>pull</servlet-name>
<url-pattern>/pull/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>registration</servlet-name>
<url-pattern>/registration/*</url-pattern>
<servlet-name>SymmetricServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>]]></programlisting>
<para>
This example starts all the SymmetricDS Servlets with filters to compress the
This example starts all the SymmetricDS Servlets with Filters to compress the
stream, authenticate nodes, and reject nodes when the server is too busy.
</para>
</section>
Expand Down
Expand Up @@ -21,23 +21,23 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.web.AckServlet;
import org.jumpmind.symmetric.web.PullServlet;
import org.jumpmind.symmetric.web.PushServlet;
import org.jumpmind.symmetric.web.RegistrationServlet;
import org.jumpmind.symmetric.web.SymmetricFilter;
import org.jumpmind.symmetric.web.SymmetricServlet;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;

/**
* Start up SymmetricDS through an embedded Jetty instance.
*
* @see SymmetricLauncher#main(String[])
*/
public class SymmetricWebServer {

protected static final Log logger = LogFactory.getLog(SymmetricWebServer.class);

protected static final Log logger = LogFactory
.getLog(SymmetricWebServer.class);

public void start(int port) throws Exception {

Expand All @@ -52,13 +52,9 @@ public void start(int port) throws Exception {

webContext.addFilter(SymmetricFilter.class, "/*", 0);

webContext.addServlet(PullServlet.class, "/pull/*");

webContext.addServlet(PushServlet.class, "/push/*");

webContext.addServlet(AckServlet.class, "/ack/*");

webContext.addServlet(RegistrationServlet.class, "/registration/*");
ServletHolder servletHolder = new ServletHolder(SymmetricServlet.class);
servletHolder.setInitOrder(0);
webContext.addServlet(servletHolder, "/*");

server.addHandler(webContext);

Expand Down
@@ -0,0 +1,52 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>,
* Eric Long <erilong@users.sourceforge.net>,
* Keith Naas <knaas@users.sourceforge.net>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/

package org.jumpmind.symmetric.transport;

import java.io.IOException;
import java.io.OutputStream;

import org.jumpmind.symmetric.transport.internal.InternalOutgoingTransport;

/**
* In order to better support other transports, the logic associated with
* transport resources, e.g., pull, push, ack, and registration is isolated away
* from the HttpServletRequest and HttpServletResponse.
*
* Filters should probably eventually be done this way as well.
*
* This should also probably be springified so that they can be injected into
* all the right places.
*
* @author Keith Naas <knaas@users.sourceforge.net>
*
*/
public abstract class AbstractTransportResourceHandler implements
ITransportResourceHandler {

protected IOutgoingTransport createOutgoingTransport(
OutputStream outputStream) throws IOException {
return new InternalOutgoingTransport(outputStream);
}

}
Expand Up @@ -21,23 +21,22 @@
* <http://www.gnu.org/licenses/>.
*/

package org.jumpmind.symmetric.web;
package org.jumpmind.symmetric.transport;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.jumpmind.symmetric.model.BatchInfo;
import org.springframework.context.ApplicationContext;
import org.jumpmind.symmetric.service.IAcknowledgeService;

public class AckResourceHandler extends ResourceHandler {
public AckResourceHandler(ApplicationContext context,
InputStream inputStream, OutputStream outputStream) {
super(context, inputStream, outputStream);
}
public class AckResourceHandler extends AbstractTransportResourceHandler {
private IAcknowledgeService acknowledgeService;

public void ack(List<BatchInfo> batches) throws IOException {
getAcknowledgeService().ack(batches);
acknowledgeService.ack(batches);
}

public void setAcknowledgeService(IAcknowledgeService acknowledgeService) {
this.acknowledgeService = acknowledgeService;
}
}
@@ -0,0 +1,130 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>,
* Eric Long <erilong@users.sourceforge.net>,
* Keith Naas <knaas@users.sourceforge.net>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/

package org.jumpmind.symmetric.transport;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.time.FastDateFormat;
import org.jumpmind.symmetric.model.IncomingBatch;
import org.jumpmind.symmetric.model.OutgoingBatch;
import org.jumpmind.symmetric.service.IIncomingBatchService;
import org.jumpmind.symmetric.service.IOutgoingBatchService;

import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedOutput;

public class AlertResourceHandler extends AbstractTransportResourceHandler {
private static final int MAX_ERRORS = 1000;

private static final FastDateFormat formatter = FastDateFormat
.getInstance("yyyy-MM-dd HH:mm:ss");

private IIncomingBatchService incomingBatchService;

private IOutgoingBatchService outgoingBatchService;

public void write(CharSequence feedURL, Writer outputWriter)
throws IOException, FeedException {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("SymmetricDS Alerts");
feed.setDescription("Problems synchronizing data");
feed.setLink(feedURL.toString());

List<SyndEntry> entries = new ArrayList<SyndEntry>();

for (IncomingBatch batch : findIncomingBatchErrors()) {
String title = "Incoming Batch " + batch.getNodeBatchId();
String value = "Node " + batch.getNodeId() + " incoming batch "
+ batch.getBatchId() + " is in error at "
+ formatDate(batch.getCreateTime());
entries.add(createEntry(title, value));
}

for (OutgoingBatch batch : findOutgoingBatchErrors()) {
String title = "Outgoing Batch " + batch.getNodeBatchId();
String value = "Node " + batch.getNodeId() + " outgoing batch "
+ batch.getBatchId() + " is in error at "
+ formatDate(batch.getCreateTime());
entries.add(createEntry(title, value));
}

feed.setEntries(entries);

SyndFeedOutput out = new SyndFeedOutput();
out.output(feed, outputWriter);
}

private SyndEntry createEntry(String title, String value) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(title);
SyndContent content = new SyndContentImpl();
content.setType("text/html");
content.setValue(value);
entry.setDescription(content);
return entry;
}

private String formatDate(Date date) {
return formatter.format(date);
}

private List<IncomingBatch> findIncomingBatchErrors() {
return getIncomingBatchService().findIncomingBatchErrors(MAX_ERRORS);
}

private List<OutgoingBatch> findOutgoingBatchErrors() {

return getOutgoingBatchService().getOutgoingBatcheErrors(MAX_ERRORS);
}

private IIncomingBatchService getIncomingBatchService() {
return incomingBatchService;
}

public void setIncomingBatchService(
IIncomingBatchService incomingBatchService) {
this.incomingBatchService = incomingBatchService;
}

private IOutgoingBatchService getOutgoingBatchService() {
return outgoingBatchService;
}

public void setOutgoingBatchService(
IOutgoingBatchService outgoingBatchService) {
this.outgoingBatchService = outgoingBatchService;
}

}
@@ -0,0 +1,56 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Keith Naas <knaas@users.sourceforge.net>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/
package org.jumpmind.symmetric.transport;

import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.IRegistrationService;

public class AuthenticationResourceHandler extends
AbstractTransportResourceHandler {

public enum AuthenticationStatus {
REGISTRATION_REQUIRED, FORBIDDEN, ACCEPTED;
};

private INodeService nodeService;
private IRegistrationService registrationService;

public AuthenticationStatus status(String nodeId, String securityToken) {
AuthenticationStatus retVal = AuthenticationStatus.ACCEPTED;

if (!nodeService.isNodeAuthorized(nodeId, securityToken)) {
if (registrationService.isAutoRegistration()) {
retVal = AuthenticationStatus.REGISTRATION_REQUIRED;
} else {
retVal = AuthenticationStatus.FORBIDDEN;
}
}
return retVal;
}

public void setNodeService(INodeService nodeService) {
this.nodeService = nodeService;
}

public void setRegistrationService(IRegistrationService registrationService) {
this.registrationService = registrationService;
}
}

0 comments on commit 46366b6

Please sign in to comment.