From 9c26a1e131a31f58e90d7a7cab549e1ec22f111d Mon Sep 17 00:00:00 2001 From: Brian Rosenberger Date: Sun, 26 Aug 2012 14:41:46 +0000 Subject: [PATCH] Progress on CVSInfo restful service git-svn-id: https://brutex.net/svn/xservices/trunk@94 e7e49efb-446e-492e-b9ec-fcafc1997a86 --- src/java/cache.ccf | 10 + src/java/log4j.properties | 7 +- .../brutex/xservices/security/Identity.java | 28 +++ .../xservices/security/SecurityManager.java | 25 ++ .../security/StandardSecurityManager.java | 13 + .../xservices/security/UserIdentity.java | 12 + .../brutex/xservices/types/scm/FileType.java | 160 +++++++++++++ .../xservices/types/scm/ModuleType.java | 123 ++++++++++ .../brutex/xservices/types/scm/Revision.java | 78 ++++++ .../net/brutex/xservices/types/scm/Tag.java | 75 ++++++ .../xservices/util/BasicCVSListener.java | 104 ++++++++ .../net/brutex/xservices/util/CVSClient.java | 94 ++++++++ .../net/brutex/xservices/util/CVSRoot.java | 67 ++++++ .../brutex/xservices/util/CvsPassword.java | 125 ++++++++++ .../util/cache/CacheExecutorService.java | 56 +++++ .../xservices/util/cache/CacheServlet.java | 122 ++++++++++ .../util/cache/DaemonThreadFactory.java | 52 ++++ .../xservices/ws/impl/FileServiceImpl.java | 2 + .../xservices/ws/impl/StringServiceImpl.java | 6 +- .../net/brutex/xservices/ws/rs/CVSInfo.java | 69 ++++++ .../brutex/xservices/ws/rs/CVSInfoImpl.java | 225 ++++++++++++++++++ .../brutex/xservices/ws/rs/FileInfoImpl.java | 12 + test/DateService-soapui-project.xml | 48 ++-- test/FileRest-soapui-project.xml | 2 +- test/FileService-soapui-project.xml | 2 +- test/FileServiceMTOM-soapui-project.xml | 2 +- test/JobServices-soapui-project.xml | 2 +- test/MailService-soapui-project.xml | 2 +- test/MiscService-soapui-project.xml | 22 +- test/StoreService-soapui-project.xml | 2 +- test/StringService-soapui-project.xml | 2 +- web/WEB-INF/cxf-beans.xml | 26 +- web/WEB-INF/web.xml | 142 ++++++----- 33 files changed, 1610 insertions(+), 107 deletions(-) create mode 100644 src/java/net/brutex/xservices/security/Identity.java create mode 100644 src/java/net/brutex/xservices/security/SecurityManager.java create mode 100644 src/java/net/brutex/xservices/security/StandardSecurityManager.java create mode 100644 src/java/net/brutex/xservices/security/UserIdentity.java create mode 100644 src/java/net/brutex/xservices/types/scm/FileType.java create mode 100644 src/java/net/brutex/xservices/types/scm/ModuleType.java create mode 100644 src/java/net/brutex/xservices/types/scm/Revision.java create mode 100644 src/java/net/brutex/xservices/types/scm/Tag.java create mode 100644 src/java/net/brutex/xservices/util/BasicCVSListener.java create mode 100644 src/java/net/brutex/xservices/util/CVSClient.java create mode 100644 src/java/net/brutex/xservices/util/CVSRoot.java create mode 100644 src/java/net/brutex/xservices/util/CvsPassword.java create mode 100644 src/java/net/brutex/xservices/util/cache/CacheExecutorService.java create mode 100644 src/java/net/brutex/xservices/util/cache/CacheServlet.java create mode 100644 src/java/net/brutex/xservices/util/cache/DaemonThreadFactory.java create mode 100644 src/java/net/brutex/xservices/ws/rs/CVSInfo.java create mode 100644 src/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java diff --git a/src/java/cache.ccf b/src/java/cache.ccf index 9e3cf98..3ba1130 100644 --- a/src/java/cache.ccf +++ b/src/java/cache.ccf @@ -26,6 +26,16 @@ jcs.region.FileCache.cacheattributes.MaxSpoolPerRun=500 jcs.region.FileCache.elementattributes=org.apache.jcs.engine.ElementAttributes jcs.region.FileCache.elementattributes.IsEternal=false +jcs.region.CVSCache=DC +jcs.region.CVSCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes +jcs.region.CVSCache.cacheattributes.MaxObjects=50 +jcs.region.CVSCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache +jcs.region.CVSCache.cacheattributes.UseMemoryShrinker=true +jcs.region.CVSCache.cacheattributes.MaxMemoryIdleTimeSeconds=3600 +jcs.region.CVSCache.cacheattributes.ShrinkerIntervalSeconds=60 +jcs.region.CVSCache.cacheattributes.MaxSpoolPerRun=5 +jcs.region.CVSCache.elementattributes=org.apache.jcs.engine.ElementAttributes +jcs.region.CVSCache.elementattributes.IsEternal=false # AVAILABLE AUXILIARY CACHES jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory diff --git a/src/java/log4j.properties b/src/java/log4j.properties index 5d834a8..204f98b 100644 --- a/src/java/log4j.properties +++ b/src/java/log4j.properties @@ -8,5 +8,10 @@ log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c{2} - %m%n # Print only messages of level WARN or above in the package com.foo. log4j.logger.net.brutex.xservices=DEBUG +log4j.logger.net.brutex.xservices.ws.rs=DEBUG -log4j.logger.org.springframework=INFO \ No newline at end of file +log4j.logger.org.springframework=INFO + +log4j.logger.org.apache.jcs=DEBUG + +log4j.logger.org.apache.commons=INFO diff --git a/src/java/net/brutex/xservices/security/Identity.java b/src/java/net/brutex/xservices/security/Identity.java new file mode 100644 index 0000000..2afa558 --- /dev/null +++ b/src/java/net/brutex/xservices/security/Identity.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.security; + +import java.util.UUID; + + + +public interface Identity { + + public UUID getUUID(); + + +} diff --git a/src/java/net/brutex/xservices/security/SecurityManager.java b/src/java/net/brutex/xservices/security/SecurityManager.java new file mode 100644 index 0000000..ae67369 --- /dev/null +++ b/src/java/net/brutex/xservices/security/SecurityManager.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.security; + +import java.lang.reflect.Method; + +public interface SecurityManager { + + public boolean canExecute(String method, Identity identity); + +} diff --git a/src/java/net/brutex/xservices/security/StandardSecurityManager.java b/src/java/net/brutex/xservices/security/StandardSecurityManager.java new file mode 100644 index 0000000..b52c911 --- /dev/null +++ b/src/java/net/brutex/xservices/security/StandardSecurityManager.java @@ -0,0 +1,13 @@ +package net.brutex.xservices.security; + +import java.lang.reflect.Method; + +public class StandardSecurityManager implements SecurityManager { + + @Override + public boolean canExecute(String method, Identity identity) { + System.out.println("User '"+identity.getUUID()+"' accesses '"+method+"'"); + return true; + } + +} diff --git a/src/java/net/brutex/xservices/security/UserIdentity.java b/src/java/net/brutex/xservices/security/UserIdentity.java new file mode 100644 index 0000000..742768c --- /dev/null +++ b/src/java/net/brutex/xservices/security/UserIdentity.java @@ -0,0 +1,12 @@ +package net.brutex.xservices.security; + +import java.util.UUID; + +public class UserIdentity implements Identity { + + @Override + public UUID getUUID() { + return UUID.randomUUID(); + } + +} diff --git a/src/java/net/brutex/xservices/types/scm/FileType.java b/src/java/net/brutex/xservices/types/scm/FileType.java new file mode 100644 index 0000000..98cd073 --- /dev/null +++ b/src/java/net/brutex/xservices/types/scm/FileType.java @@ -0,0 +1,160 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.types.scm; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * @author Brian Rosenberger, bru(at)brutex.de + * @since 0.5.0-20120817 + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(propOrder={"localFilename", "repositoryFilename", "description", "headRevision", "branch", "totalRevisions", "revisions"}) +@XmlRootElement +public class FileType { + + String localFilename; + String repositoryFilename; + String description; + String headRevision; + String branch; + String totalRevisions; + final List revisions = new ArrayList(); + + /** + * @return the revisions + */ + public List getRevisions() { + return revisions; + } + + public void addRevision(Revision revision) { + this.revisions.add(revision); + } + + /** + * @return the totalRevisions + */ + public String getTotalRevisions() { + return totalRevisions; + } + + /** + * @param totalRevisions the totalRevisions to set + */ + public void setTotalRevisions(String totalRevisions) { + this.totalRevisions = totalRevisions; + } + + public FileType() { + } + + public FileType(File file, String repositoryname, String description) { + if(file!= null ) { + this.localFilename = file.toURI().toString(); + } else { + localFilename = ""; + } + + this.repositoryFilename = repositoryname; + this.description = description; + } + + /** + * @return the localFilename + */ + public String getLocalFilename() { + return localFilename; + } + + /** + * @param localFilename the localFilename to set + */ + public void setLocalFilename(String localFilename) { + this.localFilename = localFilename; + } + + /** + * @return the repositoryFilename + */ + public String getRepositoryFilename() { + return repositoryFilename; + } + + /** + * @param repositoryFilename the repositoryFilename to set + */ + public void setRepositoryFilename(String repositoryFilename) { + this.repositoryFilename = repositoryFilename; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the headRevision + */ + public String getHeadRevision() { + return headRevision; + } + + /** + * @param headRevision the headRevision to set + */ + public void setHeadRevision(String headRevision) { + this.headRevision = headRevision; + } + + /** + * @return the branch + */ + public String getBranch() { + return branch; + } + + /** + * @param branch the branch to set + */ + public void setBranch(String branch) { + this.branch = branch; + } + + public void clearRevisionList() { + this.revisions.clear(); + } + + +} diff --git a/src/java/net/brutex/xservices/types/scm/ModuleType.java b/src/java/net/brutex/xservices/types/scm/ModuleType.java new file mode 100644 index 0000000..c433bea --- /dev/null +++ b/src/java/net/brutex/xservices/types/scm/ModuleType.java @@ -0,0 +1,123 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.types.scm; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +@XmlType(propOrder={"name", "status", "description", "path", "type", "revision"}) +@XmlRootElement +public class ModuleType { + String name; + String revision; + String status; + String description; + String path; + String type; + + public ModuleType(String name, String status, String path, String type) { + this.name = name; + this.status = status; + this.description = ""; + this.revision = ""; + this.path = "/" + path; + this.type = type; + } + + public ModuleType() { + //JAXB + } + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the revision + */ + public String getRevision() { + return revision; + } + /** + * @param revision the revision to set + */ + public void setRevision(String revision) { + this.revision = revision; + } + /** + * @return the status + */ + public String getStatus() { + return status; + } + /** + * @param status the status to set + */ + public void setStatus(String status) { + this.status = status; + } + /** + * @return the description + */ + public String getDescription() { + return description; + } + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the path + */ + public String getPath() { + return path; + } + + /** + * @param path the path to set + */ + public void setPath(String path) { + this.path = path; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + +} diff --git a/src/java/net/brutex/xservices/types/scm/Revision.java b/src/java/net/brutex/xservices/types/scm/Revision.java new file mode 100644 index 0000000..cc5545c --- /dev/null +++ b/src/java/net/brutex/xservices/types/scm/Revision.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.types.scm; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + * @author Brian Rosenberger, bru(at)brutex.de + * @since 0.5.0-20120817 + * + */ +@XmlType(name="RevisionType", propOrder={"revision", "comment"}) +@XmlRootElement +public class Revision { + + private String revision; + private String comment; + + public Revision() { + } + + public Revision(String revision, String comment) { + super(); + this.revision = revision; + this.comment = comment; + } + + + + /* (non-Javadoc) + * @see net.brutex.xservices.types.scm.SCRevision#getRevision() + */ + @XmlElement(required=true, nillable=false) + public String getRevision() { + return revision; + } + + /* (non-Javadoc) + * @see net.brutex.xservices.types.scm.SCRevision#getComment() + */ + @XmlElement(required=false, nillable=true) + public String getComment() { + return comment; + } + + /** + * @param revision the revision to set + */ + public void setRevision(String revision) { + this.revision = revision; + } + + /** + * @param comment the comment to set + */ + public void setComment(String comment) { + this.comment = comment; + } + + + +} diff --git a/src/java/net/brutex/xservices/types/scm/Tag.java b/src/java/net/brutex/xservices/types/scm/Tag.java new file mode 100644 index 0000000..1b656b8 --- /dev/null +++ b/src/java/net/brutex/xservices/types/scm/Tag.java @@ -0,0 +1,75 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.types.scm; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + * @author Brian Rosenberger, bru(at)brutex.de + * @since 0.5.0-20120817 + * + */ +@XmlType(name="TagType", propOrder={"name", "comment"}) +@XmlRootElement +public class Tag { + + private String name; + private String comment; + + public Tag() { + } + /** + * @param name + * @param comment + */ + public Tag(String name, String comment) { + super(); + this.name = name; + this.comment = comment; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @param comment the comment to set + */ + public void setComment(String comment) { + this.comment = comment; + } + + /* (non-Javadoc) + * @see net.brutex.xservices.types.scm.SCTag#getName() + */ + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see net.brutex.xservices.types.scm.SCTag#getComment() + */ + + public String getComment() { + return comment; + } + +} diff --git a/src/java/net/brutex/xservices/util/BasicCVSListener.java b/src/java/net/brutex/xservices/util/BasicCVSListener.java new file mode 100644 index 0000000..cdd7ba2 --- /dev/null +++ b/src/java/net/brutex/xservices/util/BasicCVSListener.java @@ -0,0 +1,104 @@ +package net.brutex.xservices.util; + +import java.io.PrintStream; + +import org.netbeans.lib.cvsclient.command.FileInfoContainer; +import org.netbeans.lib.cvsclient.command.log.LogInformation; +import org.netbeans.lib.cvsclient.event.BinaryMessageEvent; +import org.netbeans.lib.cvsclient.event.CVSAdapter; +import org.netbeans.lib.cvsclient.event.CVSListener; +import org.netbeans.lib.cvsclient.event.FileAddedEvent; +import org.netbeans.lib.cvsclient.event.FileInfoEvent; +import org.netbeans.lib.cvsclient.event.FileRemovedEvent; +import org.netbeans.lib.cvsclient.event.FileToRemoveEvent; +import org.netbeans.lib.cvsclient.event.FileUpdatedEvent; +import org.netbeans.lib.cvsclient.event.MessageEvent; +import org.netbeans.lib.cvsclient.event.ModuleExpansionEvent; +import org.netbeans.lib.cvsclient.event.TerminationEvent; + +public abstract class BasicCVSListener implements CVSListener +{ + /** + * Stores a tagged line + */ + private final StringBuffer taggedLine = new StringBuffer(); + + /** + * Called when the server wants to send a message to be displayed to + * the user. The message is only for information purposes and clients + * can choose to ignore these messages if they wish. + * @param e the event + */ + public void messageSent(MessageEvent e) + { + String line = e.getMessage(); + PrintStream stream = e.isError() ? System.err + : System.out; + + if (e.isTagged()) + { + String message = e.parseTaggedMessage(taggedLine, line); + // if we get back a non-null line, we have something + // to output. Otherwise, there is more to come and we + // should do nothing yet. + if (message != null) + { + //stream.println("Message: " + message); + } + } + else + { + //stream.println("Message: " + line); + } + } + + @Override + public void commandTerminated(TerminationEvent arg0) { + + } + + @Override + public void fileAdded(FileAddedEvent arg0) { + + + } + + @Override + public void fileInfoGenerated(FileInfoEvent arg0) { + FileInfoContainer info = arg0.getInfoContainer(); + LogInformation info2 = (LogInformation) info; + System.out.println(info2.getRepositoryFilename()); + System.out.println(info2.getDescription()); + + } + + @Override + public void fileRemoved(FileRemovedEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void fileToRemove(FileToRemoveEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void fileUpdated(FileUpdatedEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void messageSent(BinaryMessageEvent arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void moduleExpanded(ModuleExpansionEvent arg0) { + // TODO Auto-generated method stub + + } +} diff --git a/src/java/net/brutex/xservices/util/CVSClient.java b/src/java/net/brutex/xservices/util/CVSClient.java new file mode 100644 index 0000000..ed3f15d --- /dev/null +++ b/src/java/net/brutex/xservices/util/CVSClient.java @@ -0,0 +1,94 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.util; + +import java.io.File; + + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.netbeans.lib.cvsclient.Client; +import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; +import org.netbeans.lib.cvsclient.command.CommandAbortedException; +import org.netbeans.lib.cvsclient.command.GlobalOptions; +import org.netbeans.lib.cvsclient.connection.AuthenticationException; +import org.netbeans.lib.cvsclient.connection.PServerConnection; + +public class CVSClient { + private final File configfile; + private final PServerConnection connection; + private final CVSRoot root; + private final GlobalOptions globalOptions; + + public final Client client; + + public CVSClient(File config) throws CommandAbortedException, AuthenticationException, ConfigurationException { + + if (config == null || !config.exists() || config.isDirectory()) + throw new ConfigurationException("Config file not found"); + + this.configfile = config; + Configuration configuration = new PropertiesConfiguration(configfile); + + String cvsroot = configuration.getString("CVSROOT"); + String workdir = configuration.getString("WORKDIR"); + String password = configuration.getString("PASSWORD"); + + this.root = new CVSRoot(cvsroot); + this.globalOptions = new GlobalOptions(); + globalOptions.setCVSRoot(cvsroot); + + this.connection = new PServerConnection(); + connection.setUserName(root.user); + if (password != null) { + connection.setEncodedPassword(CvsPassword.encode(password)); + } else { + connection.setEncodedPassword(password); + } + + connection.setHostName(root.host); + connection.setRepository(root.repository); + connection.open(); + + this.client = new Client(connection, new StandardAdminHandler()); + client.setLocalPath(workdir); +} + /** + * @return + */ + public File getConfigFile() { + return this.configfile; + } + + public GlobalOptions getGlobalOptions() { + return this.globalOptions; + } + /** + * @return the connection + */ + public PServerConnection getConnection() { + return connection; + } + /** + * @return the root + */ + public CVSRoot getRoot() { + return root; + } + +} \ No newline at end of file diff --git a/src/java/net/brutex/xservices/util/CVSRoot.java b/src/java/net/brutex/xservices/util/CVSRoot.java new file mode 100644 index 0000000..9244202 --- /dev/null +++ b/src/java/net/brutex/xservices/util/CVSRoot.java @@ -0,0 +1,67 @@ +package net.brutex.xservices.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +/** + * A struct containing the various bits of information in a CVS root string, + * allowing easy retrieval of individual items of information + */ +public class CVSRoot { + public String connectionType; + public String user; + public String host; + public String repository; + + public CVSRoot(String root) throws IllegalArgumentException { + if (!root.startsWith(":")) + throw new IllegalArgumentException(); + + int oldColonPosition = 0; + int colonPosition = root.indexOf(':', 1); + if (colonPosition == -1) + throw new IllegalArgumentException(); + connectionType = root.substring(oldColonPosition + 1, colonPosition); + oldColonPosition = colonPosition; + colonPosition = root.indexOf('@', colonPosition + 1); + if (colonPosition == -1) + throw new IllegalArgumentException(); + user = root.substring(oldColonPosition + 1, colonPosition); + oldColonPosition = colonPosition; + colonPosition = root.indexOf(':', colonPosition + 1); + if (colonPosition == -1) + throw new IllegalArgumentException(); + host = root.substring(oldColonPosition + 1, colonPosition); + repository = root.substring(colonPosition + 1); + if (connectionType == null || user == null || host == null + || repository == null) + throw new IllegalArgumentException(); + } + + public String getCVSRoot(File directory) { + String root = null; + BufferedReader r = null; + try { + File rootFile = new File(directory, "CVS/Root"); + if (rootFile.exists()) { + r = new BufferedReader(new FileReader(rootFile)); + root = r.readLine(); + } + } catch (IOException e) { + // ignore + } finally { + try { + if (r != null) + r.close(); + } catch (IOException e) { + System.err.println("Warning: could not close CVS/Root file!"); + } + } + if (root == null) { + root = System.getProperty("cvs.root"); + } + return root; + } +} \ No newline at end of file diff --git a/src/java/net/brutex/xservices/util/CvsPassword.java b/src/java/net/brutex/xservices/util/CvsPassword.java new file mode 100644 index 0000000..3a71031 --- /dev/null +++ b/src/java/net/brutex/xservices/util/CvsPassword.java @@ -0,0 +1,125 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.util; +/* + * Copyright 2010 Andrew Kroh + * + * Licensed 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. + */ + + + +/** + * A simple class for encoding and decoding passwords for CVS pserver protocol. + * Can be used to recover forgotten passwords. + * + *

+ * Adapted from: http://blog.zmeeagain.com/2005/01/recover-cvs-pserver-passwords.html + */ +public class CvsPassword +{ + private static final char[] LOOKUP_TABLE = + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 120, 53, + 79, 0, 109, 72, 108, 70, 64, 76, 67, 116, 74, 68, 87, 111, 52, 75, + 119, 49, 34, 82, 81, 95, 65, 112, 86, 118, 110, 122, 105, 41, 57, + 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, 91, 35, 125, 55, + 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, 0, + 121, 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, + 58, 113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85}; + + /** + * Encodes a CVS password to be used in .cvspass file. Throws an exception + * if clearText is null, if a character is found outside the 0 - 126 range, or + * if within the range, one of the non-allowed characters. + * + * @param clearText + * the password in clear to be encoded + * + * @return the encoded cvs password + */ + public static String encode(String clearText) + { + // First character of encoded version is A: + char[] encoded = new char[clearText.length() + 1]; + encoded[0] = 'A'; + + // Skip the first character: + int counter = 1; + for (char c : clearText.toCharArray()) + { + if (c == '`' || c == '$' || c < 32) + { + throw new IllegalArgumentException( + "Illegal character was found in clear password."); + } + + encoded[counter++] = LOOKUP_TABLE[c]; + } + + return String.valueOf(encoded); + } + + /** + * Recovers an encoded via pserver protocol CVS password. + * + * @param encodedPassword + * the encoded password to be decoded + * + * @return the decoded password or null if the input was + * null or empty + */ + public static String decode(String encodedPassword) + { + String rtn = null; + + if (encodedPassword != null && encodedPassword.length() > 0) + { + if (encodedPassword.startsWith("A")) + { + rtn = encode(encodedPassword.substring(1)).substring(1); + } + else + { + rtn = encode(encodedPassword).substring(1); + } + } + + return rtn; + } + + public static void main(String[] sArgs) + { + final String TEST_WORD = "i07w91"; + String encoded = CvsPassword.encode(TEST_WORD); + System.out.println("Encoded: <" + encoded + ">"); + String decoded = CvsPassword.decode(encoded); + System.out.println("Decoded: <" + decoded + ">"); + System.out.println(decoded.equals(TEST_WORD) ? "Test Passed" : "Test Failed"); + } +} + diff --git a/src/java/net/brutex/xservices/util/cache/CacheExecutorService.java b/src/java/net/brutex/xservices/util/cache/CacheExecutorService.java new file mode 100644 index 0000000..eb185ef --- /dev/null +++ b/src/java/net/brutex/xservices/util/cache/CacheExecutorService.java @@ -0,0 +1,56 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.util.cache; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +/** + * @author Brian Rosenberger, bru(at)brutex.de + * @since 0.5.0-20120825 + */ +public class CacheExecutorService implements ServletContextListener { + static final String EXECUTOR_NAME = "CACHE_EXECUTOR"; + private ExecutorService executor; + + public void contextInitialized(ServletContextEvent arg0) { + ServletContext context = arg0.getServletContext(); + int nr_executors = 1; + ThreadFactory daemonFactory = new DaemonThreadFactory(); + try { + nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count")); + } catch (NumberFormatException ignore ) {} + + if(nr_executors <= 1) { + executor = Executors.newSingleThreadExecutor(daemonFactory); + } else { + executor = Executors.newFixedThreadPool(nr_executors,daemonFactory); + } + context.setAttribute(EXECUTOR_NAME, executor); + } + + public void contextDestroyed(ServletContextEvent arg0) { + ServletContext context = arg0.getServletContext(); + executor.shutdownNow(); // or process/wait until all pending jobs are done + } + +} diff --git a/src/java/net/brutex/xservices/util/cache/CacheServlet.java b/src/java/net/brutex/xservices/util/cache/CacheServlet.java new file mode 100644 index 0000000..1778888 --- /dev/null +++ b/src/java/net/brutex/xservices/util/cache/CacheServlet.java @@ -0,0 +1,122 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.util.cache; + +import java.io.File; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.concurrent.ExecutorService; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.Response; + +import org.apache.log4j.Logger; + +import net.brutex.xservices.types.scm.ModuleType; +import net.brutex.xservices.ws.rs.CVSInfoImpl; + +/** + * Perform Caching actions on the CVS Info actions + * + * @author Brian Rosenberger, bru(at)brutex.de + * @since 0.5.0-200120825 + * + */ +public class CacheServlet extends HttpServlet { + + private final Logger logger = Logger.getLogger(CacheServlet.class); + List configfiles = new ArrayList();; + int cacheinterval; + + /* + * (non-Javadoc) + * + * @see javax.servlet.GenericServlet#init() + */ + @Override + public void init() throws ServletException { + super.init(); + ExecutorService executor = (ExecutorService) getServletContext() + .getAttribute(CacheExecutorService.EXECUTOR_NAME); + + Enumeration attributes = getServletContext() + .getInitParameterNames(); + while (attributes.hasMoreElements()) { + String name = attributes.nextElement(); + if (name.startsWith("cvs-config-")) { + String configfile = (String) getServletContext() + .getInitParameter(name); + logger.info("CVS configuration file: " + configfile); + this.configfiles.add(new File(configfile)); + } + } + cacheinterval = 15; + try { + cacheinterval = Integer.parseInt((String) getServletContext() + .getInitParameter("cvs-cache-interval")); + } catch (NumberFormatException e) { + logger.debug("Could not read parameter 'cvs-cache-interval' from web.xml. Using default value '"+cacheinterval+"' minutes"); + } + logger.info("CacheServlet set to " + cacheinterval + " minutes interval."); + + executor.submit(new Runnable() { + boolean isInterrupted = false; + + @Override + public void run() { + while (!isInterrupted) { + for (File configfile : configfiles) { + CVSInfoImpl instance = new CVSInfoImpl(); + logger.info("Caching modules from " + configfile.toURI().toString()); + Response response = instance.getModules(null, + configfile, true); + List list = (List) ((GenericEntity) response + .getEntity()).getEntity(); + if (list.size() == 0) + list.add(new ModuleType("", "", "", "")); + for (ModuleType t : list) { + try { + //Extra sleep + Thread.currentThread().sleep(5000); + } catch (InterruptedException e) { + isInterrupted = true; + break; + } + logger.info("Caching module '" + t.getName()+"'"); + instance.getRepositoryFiles(null, configfile, t.getName(), true, true); + + } + } + try { + logger.debug("Now sleeping for '"+cacheinterval+"' minutes"); + Thread.currentThread().sleep(cacheinterval * 60000); + logger.debug("Waking up after '"+cacheinterval+"' minutes of sleep"); + } catch (InterruptedException e) { + isInterrupted = true; + break; + } + } + + } + }); + + } + +} diff --git a/src/java/net/brutex/xservices/util/cache/DaemonThreadFactory.java b/src/java/net/brutex/xservices/util/cache/DaemonThreadFactory.java new file mode 100644 index 0000000..59d0c0e --- /dev/null +++ b/src/java/net/brutex/xservices/util/cache/DaemonThreadFactory.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.util.cache; + +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +public class DaemonThreadFactory implements ThreadFactory { + + private final ThreadFactory factory; + + /** + * Construct a ThreadFactory with setDeamon(true) using + * Executors.defaultThreadFactory() + */ + public DaemonThreadFactory() { + this(Executors.defaultThreadFactory()); + } + + /** + * Construct a ThreadFactory with setDeamon(true) wrapping the given factory + * + * @param thread + * factory to wrap + */ + public DaemonThreadFactory(ThreadFactory factory) { + if (factory == null) + throw new NullPointerException("factory cannot be null"); + this.factory = factory; + } + + public Thread newThread(Runnable r) { + final Thread t = factory.newThread(r); + t.setDaemon(true); + return t; + } + } + diff --git a/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java index 15cf470..f33113f 100644 --- a/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + package net.brutex.xservices.ws.impl; import java.io.ByteArrayOutputStream; diff --git a/src/java/net/brutex/xservices/ws/impl/StringServiceImpl.java b/src/java/net/brutex/xservices/ws/impl/StringServiceImpl.java index 5da580a..ff10c6c 100644 --- a/src/java/net/brutex/xservices/ws/impl/StringServiceImpl.java +++ b/src/java/net/brutex/xservices/ws/impl/StringServiceImpl.java @@ -65,8 +65,10 @@ public class StringServiceImpl implements StringService { Pattern pattern = Pattern.compile(search, allflags); Matcher matcher = pattern.matcher(res); StringMatchType rm = new StringMatchType(); - while (matcher.find()) { - rm.addStringMatch(matcher.start(), matcher.end(), matcher.group()); + while (matcher.find()) { + for(int i=0; i<=matcher.groupCount();i++){ + rm.addStringMatch(matcher.start(), matcher.end(), matcher.group(i)); + } } return rm; } diff --git a/src/java/net/brutex/xservices/ws/rs/CVSInfo.java b/src/java/net/brutex/xservices/ws/rs/CVSInfo.java new file mode 100644 index 0000000..94acac8 --- /dev/null +++ b/src/java/net/brutex/xservices/ws/rs/CVSInfo.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012 Brian Rosenberger (Brutex Network) + * + * Licensed 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 net.brutex.xservices.ws.rs; + +import java.io.File; +import java.util.List; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import net.brutex.xservices.types.FileInfoType; + + + +@Path("/CVSService/") +@Produces ({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) +public interface CVSInfo { + +/** + * @param module + * @param withDir + * @param withFiles + * @param depth + * @param search + * @param count + * @param page + * @return List of File + */ +@GET +@Path("getRepositoryFiles/") +public Response getRepositoryFiles(@Context HttpHeaders h, + @QueryParam("config") File f, + @QueryParam("modules") @DefaultValue("") String modules, + @QueryParam("showRevisions") @DefaultValue("false") boolean showRevisions, + @QueryParam("forceNoCache") @DefaultValue("false") boolean forceNoCache + ); + +@GET +@Path("getModules") +public Response getModules(@Context HttpHeaders h, + @QueryParam("config") File f, + @QueryParam("forceNoCache") @DefaultValue("false") boolean forceNoCache); + +} + + + diff --git a/src/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java b/src/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java new file mode 100644 index 0000000..b062d2c --- /dev/null +++ b/src/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java @@ -0,0 +1,225 @@ +package net.brutex.xservices.ws.rs; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.jcs.JCS; +import org.apache.jcs.access.exception.CacheException; +import org.apache.log4j.Logger; +import org.netbeans.lib.cvsclient.Client; +import org.netbeans.lib.cvsclient.command.CommandAbortedException; +import org.netbeans.lib.cvsclient.command.CommandException; +import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand; +import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation; +import org.netbeans.lib.cvsclient.command.log.LogInformation; +import org.netbeans.lib.cvsclient.command.log.RlogCommand; +import org.netbeans.lib.cvsclient.connection.AuthenticationException; +import org.netbeans.lib.cvsclient.event.FileInfoEvent; + +import net.brutex.xservices.types.scm.ModuleType; +import net.brutex.xservices.types.scm.FileType; +import net.brutex.xservices.types.scm.Revision; +import net.brutex.xservices.util.BasicCVSListener; +import net.brutex.xservices.util.CVSClient; + +/** + * @author Brian Rosenberger + * @since 0.5.0-20120824 + * + */ +public class CVSInfoImpl implements CVSInfo { + + final Logger logger = Logger.getLogger(CVSInfoImpl.class); + + public Response getRepositoryFiles(HttpHeaders h, File f, String modules, + boolean showRevisions, + boolean forceNoCache) { + + final List list = new ArrayList(); + + String cachekey = "getFiles" + f.toURI().toString(); + logger.debug("forceNoCache="+forceNoCache); + List cacheresult = (List) getCacheInstance().get( + cachekey); + + if (!forceNoCache && cacheresult != null) { + // Cache hit + list.addAll(cacheresult); + } else { + // Cache miss + try { + CVSClient cvsclient = new CVSClient(f); + Client client = cvsclient.client; + + client.getEventManager().addCVSListener(new BasicCVSListener() { + @Override + public void fileInfoGenerated(FileInfoEvent arg0) { + LogInformation info = (LogInformation) arg0 + .getInfoContainer(); + FileType cvsfile = new FileType(info.getFile(), info + .getRepositoryFilename(), info.getDescription()); + cvsfile.setHeadRevision(info.getHeadRevision()); + cvsfile.setBranch(info.getBranch()); + cvsfile.setTotalRevisions(info.getTotalRevisions()); + for (LogInformation.Revision r : info.getRevisionList()) { + cvsfile.addRevision(new Revision(r.getNumber(), r + .getMessage())); + } + list.add(cvsfile); + } + }); + + RlogCommand rlog = new RlogCommand(); + StringTokenizer tk = new StringTokenizer(modules, ","); + while (tk.hasMoreTokens()) { + rlog.setModule(tk.nextToken()); + } + if (rlog.getModules().length == 0) + rlog.setModule(""); + + rlog.setDefaultBranch(true); // -b Print information about the + // revisions on the default + // branch, + // normally the highest branch + // on + // the trunk. + rlog.setNoTags(true); // -N Do not print the list of tags for + // this + // file. This option can be very useful + // when + // your site uses a lot of tags, so + // rather + // than "more"'ing over 3 pages of tag + // information, the log information is + // presented without tags at all. + rlog.setHeaderAndDescOnly(false); // -t Print only the name of + // the + // rcs file, name of the + // file in + // the working directory, + // head, + // default branch, access + // list, + // locks, symbolic names, + // and + // suffix. + description + // rlog.setRevisionFilter("1.1."); + // rlog.setSuppressHeader(true); // -S Supress log output when + // no + // revisions are selected within a file. + client.executeCommand(rlog, cvsclient.getGlobalOptions()); + logger.info("Execute CVS command '" + rlog.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'"); + //need to put a new list into cache as we will filter the result + //afterwards + getCacheInstance().put(cachekey, new ArrayList(list)); + + + } catch (ConfigurationException e) { + logger.error("CVS Configuration File '" + + f.getAbsolutePath() + f.getName() + "'not found.", e); + + } catch (CommandAbortedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AuthenticationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CommandException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CacheException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + + // prepare output after everything is cached + if (!showRevisions) { + for (FileType t : list) { + t.clearRevisionList(); + } + } + + GenericEntity entity = new GenericEntity>(list) {}; + return Response.ok(entity).build(); + } + + @Override + public Response getModules(HttpHeaders h, File f, boolean forceNoCache) { + + // Try to deliver from Cache + String cachekey = "Modules" + f.toURI().toString(); + logger.debug("forceNoCache="+forceNoCache); + List response = (List) getCacheInstance().get( + cachekey); + if (!forceNoCache && response != null) { + GenericEntity entity = new GenericEntity>(response) { + }; + return Response.ok(entity).build(); + } + // ------------------------- + + try { + CVSClient cvsclient = new CVSClient(f); + Client client = cvsclient.client; + + final List list = new ArrayList(); + + client.getEventManager().addCVSListener(new BasicCVSListener() { + public void fileInfoGenerated(FileInfoEvent e) { + ModuleListInformation info = (ModuleListInformation) e + .getInfoContainer(); + + list.add(new ModuleType(info.getModuleName(), info + .getModuleStatus(), info.getPaths(), info.getType())); + } + }); + + CheckoutCommand co = new CheckoutCommand(); + co.setShowModulesWithStatus(true); + + client.executeCommand(co, cvsclient.getGlobalOptions()); + logger.info("Execute CVS command '" + co.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'"); + if(list.size()==0) { + logger.warn("Repository '" + cvsclient.getRoot().repository + "' does not have modules"); + list.add(new ModuleType("","","","")); + } + + GenericEntity entity = new GenericEntity>(list) { + }; + getCacheInstance().put(cachekey, list); + return Response.ok(entity).build(); + } catch (Exception e) { + e.printStackTrace(); + } + return Response.serverError().build(); + } + + /** + * Get the caching manager for CVS objects + * + * @return The CVSCaching JCS region + */ + public JCS getCacheInstance() { + JCS jcs = null; + final String cacheinstance = "CVSCache"; + try { + logger.debug("Getting cache instance named '"+cacheinstance+"'" ); + jcs = JCS.getInstance(cacheinstance); + } catch (CacheException e) { + logger.error("Failed to get cache instance", e); + e.printStackTrace(); + } + return jcs; + } + +} diff --git a/src/java/net/brutex/xservices/ws/rs/FileInfoImpl.java b/src/java/net/brutex/xservices/ws/rs/FileInfoImpl.java index 07cda73..18079f9 100644 --- a/src/java/net/brutex/xservices/ws/rs/FileInfoImpl.java +++ b/src/java/net/brutex/xservices/ws/rs/FileInfoImpl.java @@ -2,6 +2,7 @@ package net.brutex.xservices.ws.rs; import java.io.File; import java.io.FileFilter; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -12,6 +13,8 @@ import javax.ws.rs.core.Response; import org.apache.jcs.JCS; import org.apache.jcs.access.exception.CacheException; +import net.brutex.xservices.security.StandardSecurityManager; +import net.brutex.xservices.security.UserIdentity; import net.brutex.xservices.types.FileInfoType; /** @@ -23,6 +26,15 @@ public class FileInfoImpl implements FileInfo { public Response getFiles(HttpHeaders h, String dir, boolean withDir, boolean withFiles, int level, String search, int count, int page) { + StandardSecurityManager sec = new StandardSecurityManager(); + UserIdentity id = new UserIdentity(); + + + if( ! sec.canExecute(Thread.currentThread().getStackTrace()[1].getMethodName(), id)) { + return null; + } + + System.out.println("Listing directory: " + dir); if(level <= 0) level = 1; if(level > 3) level = 3; diff --git a/test/DateService-soapui-project.xml b/test/DateService-soapui-project.xml index 55b91ff..67e35a9 100644 --- a/test/DateService-soapui-project.xml +++ b/test/DateService-soapui-project.xml @@ -1,5 +1,5 @@ - + @@ -693,27 +693,27 @@ -]]>DateServiceSoapBindinggetDateExtended<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindinggetDateExtended<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService -]]>DateServiceSoapBindinggetTimestamp<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindinggetTimestamp<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService -]]>DateServiceSoapBindinggetTimezones<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindinggetTimezones<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService -]]>50DateServiceSoapBindinggetTimestamp2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>50Global HTTP SettingsDateServiceSoapBindinggetTimestamp2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService -]]>false50250truetrue-160TIMESimple100true500Loops0DateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP Settingsfalse50250truetrue-160TIMESimple100true500Loops0DateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -721,7 +721,7 @@ ISO 8601 -]]>DateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -729,7 +729,7 @@ RFC 822 -]]>DateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -737,7 +737,7 @@ DateOnly-dashed -]]>DateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -745,7 +745,7 @@ DateOnly-dotted -]]>DateServiceSoapBindingformatDateAdvanced<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingformatDateAdvanced<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -754,7 +754,7 @@ 'Year:' yyyy 'Week:' WW 'in Month:' MMMM -]]>DateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingformatDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -762,7 +762,7 @@ DateOnly-slashed -]]>DateServiceSoapBindingparseDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingparseDate<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -772,7 +772,7 @@ Europe/Helsinki -]]>DateServiceSoapBindingparseDateAdvanced<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingparseDateAdvanced<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -782,7 +782,7 @@ Europe/Berlin -]]>DateServiceSoapBindingparseDateAdvanced<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingparseDateAdvanced<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -792,7 +792,7 @@ Europe/Berlin -]]>false200250truetrue-1180TIMEVariance600000.5100true500DateServiceSoapBindingdateTimeDiff<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP Settingsfalse200250truetrue-1180TIMEVariance600000.5100true500DateServiceSoapBindingdateTimeDiff<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -800,7 +800,7 @@ 2012-06-06T08:45:00+01:00 -]]>DateServiceSoapBindingdateTimeDiff<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -808,7 +808,7 @@ 2012-01-23 -]]>DateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -818,7 +818,7 @@ days -]]>DateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -828,7 +828,7 @@ years -]]>DateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -838,7 +838,7 @@ minutes -]]>DateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -848,7 +848,7 @@ milliseconds -]]>DateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -858,7 +858,7 @@ seconds -]]>DateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateTimeDiff2<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -868,7 +868,7 @@ milliseconds -]]>DateServiceSoapBindingdateAdd<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService +]]>Global HTTP SettingsDateServiceSoapBindingdateAdd<xml-fragment/>UTF-8http://localhost:8080/XServices/DateService @@ -877,4 +877,4 @@ seconds -]]>false300250truetrue-1180TIMEBurst6000010000100true500 \ No newline at end of file +]]>Global HTTP Settingsfalse300250truetrue-1180TIMEBurst6000010000100true500 \ No newline at end of file diff --git a/test/FileRest-soapui-project.xml b/test/FileRest-soapui-project.xml index 802cd6a..6ff6601 100644 --- a/test/FileRest-soapui-project.xml +++ b/test/FileRest-soapui-project.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/FileService-soapui-project.xml b/test/FileService-soapui-project.xml index 082b1e6..92ec686 100644 --- a/test/FileService-soapui-project.xml +++ b/test/FileService-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/FileService?wsdl +http://localhost:8080/XServices/FileService?wsdl /* * Copyright 2010 Brian Rosenberger (Brutex Network) * diff --git a/test/FileServiceMTOM-soapui-project.xml b/test/FileServiceMTOM-soapui-project.xml index 40b9d22..67eb7ce 100644 --- a/test/FileServiceMTOM-soapui-project.xml +++ b/test/FileServiceMTOM-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/FileServiceMTOM?wsdl +http://localhost:8080/XServices/FileServiceMTOM?wsdl diff --git a/test/JobServices-soapui-project.xml b/test/JobServices-soapui-project.xml index 82fcb95..1b72106 100644 --- a/test/JobServices-soapui-project.xml +++ b/test/JobServices-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/JobServices?wsdl +http://localhost:8080/XServices/JobServices?wsdl diff --git a/test/MailService-soapui-project.xml b/test/MailService-soapui-project.xml index 9d68523..b4b4d96 100644 --- a/test/MailService-soapui-project.xml +++ b/test/MailService-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/MailService?wsdl +http://localhost:8080/XServices/MailService?wsdl diff --git a/test/MiscService-soapui-project.xml b/test/MiscService-soapui-project.xml index afbebb6..d3f3797 100644 --- a/test/MiscService-soapui-project.xml +++ b/test/MiscService-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/MiscService?WSDL +http://localhost:8080/XServices/MiscService?WSDL @@ -214,7 +214,7 @@ localhost -]]>MiscServiceSoapBindinggetHostinfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>Global HTTP SettingsMiscServiceSoapBindinggetHostinfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService @@ -222,7 +222,7 @@ google.de -]]>5000MiscServiceSoapBindinggetHostinfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>5000Global HTTP SettingsMiscServiceSoapBindinggetHostinfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService @@ -230,7 +230,7 @@ heise.de -]]>5000MiscServiceSoapBindinggetHostinfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>5000Global HTTP SettingsMiscServiceSoapBindinggetHostinfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService @@ -238,12 +238,12 @@ 173.194.69.94 -]]>5000MiscServiceSoapBindinggenerateUUID<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>5000Global HTTP SettingsMiscServiceSoapBindinggenerateUUID<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService -]]>MiscServiceSoapBindingsleep<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>Global HTTP SettingsMiscServiceSoapBindingsleep<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService @@ -251,12 +251,12 @@ 4 -]]>4100MiscServiceSoapBindinggetInfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>4100Global HTTP SettingsMiscServiceSoapBindinggetInfo<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService -]]>MiscServiceSoapBindingsleep<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>Global HTTP SettingsMiscServiceSoapBindingsleep<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService @@ -264,7 +264,7 @@ 0 -]]>120200MiscServiceSoapBindingsleep<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>120200Global HTTP SettingsMiscServiceSoapBindingsleep<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService @@ -272,9 +272,9 @@ 32 -]]>MiscServiceSoapBindinggetMemory<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService +]]>Global HTTP SettingsMiscServiceSoapBindinggetMemory<xml-fragment/>UTF-8http://localhost:8080/XServices/MiscService -]]> \ No newline at end of file +]]>Global HTTP Settings \ No newline at end of file diff --git a/test/StoreService-soapui-project.xml b/test/StoreService-soapui-project.xml index 9796c54..065c6b6 100644 --- a/test/StoreService-soapui-project.xml +++ b/test/StoreService-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/StorageServices?wsdl +http://localhost:8080/XServices/StorageServices?wsdl diff --git a/test/StringService-soapui-project.xml b/test/StringService-soapui-project.xml index 7147979..4f1c482 100644 --- a/test/StringService-soapui-project.xml +++ b/test/StringService-soapui-project.xml @@ -1,5 +1,5 @@ -http://localhost:8080/XServices/StringService?wsdl +http://localhost:8080/XServices/StringService?wsdl diff --git a/web/WEB-INF/cxf-beans.xml b/web/WEB-INF/cxf-beans.xml index 1c884ea..c3aca93 100644 --- a/web/WEB-INF/cxf-beans.xml +++ b/web/WEB-INF/cxf-beans.xml @@ -50,7 +50,7 @@ - + @@ -58,7 +58,7 @@ - + @@ -71,12 +71,20 @@ - - - - - - - + + + + + + + + + + + + + + + diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 7c3c143..80b600c 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -1,55 +1,91 @@ - - - contextConfigLocation - /WEB-INF/cxf-beans.xml - - - quartz:config-file - quartz.properties - - - quartz:shutdown-on-unload - true - - - quartz:wait-on-shutdown - false - - - quartz:start-scheduler-on-load - true - - - org.springframework.web.context.ContextLoaderListener - - - - org.quartz.ee.servlet.QuartzInitializerListener - - - - XServices - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - QuartzInitializer - org.quartz.ee.servlet.QuartzInitializerServlet - - shutdown-on-unload - true - - 2 - - - XServices - /* - - - 30 - - - index.html - + + + contextConfigLocation + /WEB-INF/cxf-beans.xml + + + quartz:config-file + quartz.properties + + + quartz:shutdown-on-unload + true + + + quartz:wait-on-shutdown + false + + + quartz:start-scheduler-on-load + true + + + cache:thread-count + 3 + + + cvs-config-01 + c:/temp/test.txt + + + cvs-config-02 + c:/temp/test2.txt + + + cvs-config-03 + c:/temp/test3.txt + + + cvs-cache-interval + 15 + + + + + + org.springframework.web.context.ContextLoaderListener + + + org.quartz.ee.servlet.QuartzInitializerListener + + + net.brutex.xservices.util.cache.CacheExecutorService + + + + + XServices + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + QuartzInitializer + org.quartz.ee.servlet.QuartzInitializerServlet + + shutdown-on-unload + true + + 2 + + + CacheServlet + net.brutex.xservices.util.cache.CacheServlet + 3 + + + + + XServices + /* + + + 30 + + + index.html + \ No newline at end of file