]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-597 added setProxy method to VocabClient to pick up httpclient with props...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Sat, 13 Feb 2010 01:36:15 +0000 (01:36 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Sat, 13 Feb 2010 01:36:15 +0000 (01:36 +0000)
Added log4j.properties. Removed programmatic configuration of log4j.
test: import, vocab client

M    vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java
A    vocabulary/import/src/main/resources/log4j.properties
M    vocabulary/import/pom.xml
M    vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java

services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java
services/vocabulary/import/pom.xml
services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java
services/vocabulary/import/src/main/resources/log4j.properties [new file with mode: 0644]

index 1a0a66b457fe33f29099a3baf3edbf360bebe75e..8befd392b2b51da8c0a94be67b801abb10a51413 100644 (file)
@@ -20,18 +20,17 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  */
 public class VocabularyClient extends AbstractServiceClientImpl {
 
-       /* (non-Javadoc)
-        * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
-        */
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+     */
     @Override
-       public String getServicePathComponent() {
-               return "vocabularies";
-       }
-       
-       public String getItemCommonPartName() {
-               return getCommonPartName("vocabularyitems");
-       }
+    public String getServicePathComponent() {
+        return "vocabularies";
+    }
 
+    public String getItemCommonPartName() {
+        return getCommonPartName("vocabularyitems");
+    }
     /**
      *
      */
@@ -49,7 +48,18 @@ public class VocabularyClient extends AbstractServiceClientImpl {
     public VocabularyClient() {
         ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
         RegisterBuiltin.register(factory);
-        vocabularyProxy = ProxyFactory.create(VocabularyProxy.class, getBaseURL());
+        setProxy();
+    }
+
+    /**
+     * allow to reset proxy as per security needs
+     */
+    public void setProxy() {
+        if (useAuth()) {
+            vocabularyProxy = ProxyFactory.create(VocabularyProxy.class, getBaseURL(), getHttpClient());
+        } else {
+            vocabularyProxy = ProxyFactory.create(VocabularyProxy.class, getBaseURL());
+        }
     }
 
     /**
@@ -74,7 +84,6 @@ public class VocabularyClient extends AbstractServiceClientImpl {
      * @return
      * @see org.collectionspace.services.client.VocabularyProxy#read(java.lang.String)
      */
-
     public ClientResponse<MultipartInput> read(String csid) {
         return vocabularyProxy.read(csid);
     }
@@ -121,7 +130,6 @@ public class VocabularyClient extends AbstractServiceClientImpl {
      * @return
      * @see org.collectionspace.services.client.VocabularyProxy#read(java.lang.String)
      */
-
     public ClientResponse<MultipartInput> readItem(String vcsid, String csid) {
         return vocabularyProxy.readItem(vcsid, csid);
     }
index e3c9f704d968543bae223dce7839911dafe6ec82..3f4ac7202e9529b8b1d46f531acf46892d5e137d 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <project xmlns="http://maven.apache.org/POM/4.0.0"\r
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
 \r
     <parent>\r
         <groupId>org.collectionspace.services</groupId>\r
     <artifactId>org.collectionspace.services.vocabulary.importer</artifactId>\r
     <version>1.0</version>\r
     <name>services.vocabulary.importer</name>\r
-    \r
+\r
     <dependencies>\r
         <!-- keep slf4j dependencies on the top -->\r
+        <dependency>\r
+            <groupId>org.slf4j</groupId>\r
+            <artifactId>slf4j-api</artifactId>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.slf4j</groupId>\r
+            <artifactId>slf4j-log4j12</artifactId>\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.vocabulary.jaxb</artifactId>\r
             <artifactId>org.collectionspace.services.vocabulary.client</artifactId>\r
             <version>${cspace.services.client.version}</version>\r
         </dependency>\r
-        \r
-<!--         \r
+\r
+        <!--\r
         <dependency>\r
             <groupId>org.testng</groupId>\r
             <artifactId>testng</artifactId>\r
             <version>5.6</version>\r
         </dependency>\r
- -->        \r
-        <dependency>\r
-            <groupId>org.slf4j</groupId>\r
-            <artifactId>slf4j-api</artifactId>\r
-            <version>1.5.2</version>\r
-        </dependency>\r
-<!--          <dependency>\r
-            <groupId>org.slf4j</groupId>\r
-            <artifactId>slf4j-log4j12</artifactId>\r
-            <version>1.5.2</version>\r
-        </dependency> -->\r
+ -->\r
         <dependency>\r
             <groupId>org.jboss.resteasy</groupId>\r
             <artifactId>resteasy-jaxrs</artifactId>\r
             <version>3.1</version>\r
         </dependency>\r
     </dependencies>\r
-    \r
+\r
     <build>\r
         <finalName>collectionspace-services-vocabulary-importer</finalName>\r
         <plugins>\r
-                       <plugin>\r
-                         <groupId>org.apache.maven.plugins</groupId>\r
-                         <artifactId>maven-assembly-plugin</artifactId>\r
-                           <executions>\r
-                             <execution>\r
-                                <goals>\r
-                                  <goal>attached</goal>\r
-                                </goals>\r
-                                <phase>package</phase>\r
-                                <configuration>\r
-                                  <descriptorRefs>\r
-                                    <descriptorRef>jar-with-dependencies</descriptorRef>\r
-                                 </descriptorRefs>\r
-                                 <archive>\r
-                                   <manifest>\r
-                                     <mainClass>org.collectionspace.services.vocabulary.importer.VocabularyBaseImport</mainClass>\r
-                                   </manifest>\r
-                                 </archive>\r
-                               </configuration>\r
-                            </execution>\r
-                         </executions>\r
-                       </plugin>        \r
+            <plugin>\r
+                <groupId>org.apache.maven.plugins</groupId>\r
+                <artifactId>maven-assembly-plugin</artifactId>\r
+                <executions>\r
+                    <execution>\r
+                        <goals>\r
+                            <goal>attached</goal>\r
+                        </goals>\r
+                        <phase>package</phase>\r
+                        <configuration>\r
+                            <descriptorRefs>\r
+                                <descriptorRef>jar-with-dependencies</descriptorRef>\r
+                            </descriptorRefs>\r
+                            <archive>\r
+                                <manifest>\r
+                                    <mainClass>org.collectionspace.services.vocabulary.importer.VocabularyBaseImport</mainClass>\r
+                                </manifest>\r
+                            </archive>\r
+                        </configuration>\r
+                    </execution>\r
+                </executions>\r
+            </plugin>\r
             <plugin>\r
                 <groupId>org.apache.maven.plugins</groupId>\r
                 <artifactId>maven-surefire-plugin</artifactId>\r
index c5ee6e83d54fbed4456c0daae9beae28fdd5b608..4ae3de0cc9a7b2f30653f893968f609ba300a8df 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.collectionspace.services.vocabulary.importer;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
-import org.apache.log4j.BasicConfigurator;
 import org.collectionspace.services.VocabularyItemJAXBSchema;
 import org.collectionspace.services.client.VocabularyClient;
 import org.collectionspace.services.client.VocabularyClientUtils;
 import org.collectionspace.services.client.test.ServiceRequestType;
-import org.collectionspace.services.vocabulary.VocabulariesCommon;
-import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,84 +45,83 @@ import org.slf4j.LoggerFactory;
  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
  */
 public class VocabularyBaseImport {
-    private static final Logger logger =
-        LoggerFactory.getLogger(VocabularyBaseImport.class);
 
+    private static final Logger logger =
+            LoggerFactory.getLogger(VocabularyBaseImport.class);
     // Instance variables specific to this test.
     private VocabularyClient client = new VocabularyClient();
     final String SERVICE_PATH_COMPONENT = "vocabularies";
     final String ITEM_SERVICE_PATH_COMPONENT = "items";
 
-    public void createEnumeration(String vocabName, List<String> enumValues ) {
-
-       // Expected status code: 201 Created
-       int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
-       // Type of service request being tested
-       ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
-
-       if(logger.isDebugEnabled()){
-               logger.debug("Import: Create vocabulary: \"" + vocabName +"\"");
-       }
-       String baseVocabRefName = VocabularyClientUtils.createVocabularyRefName(vocabName, false);
-       String fullVocabRefName = baseVocabRefName+"'"+vocabName+"'";
-       MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
-                       vocabName, fullVocabRefName, client.getCommonPartName());
-       ClientResponse<Response> res = client.create(multipart);
-
-       int statusCode = res.getStatus();
-
-       if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
-               throw new RuntimeException("Could not create enumeration: \""+vocabName
-                               +"\" "+ VocabularyClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-       }
-       if(statusCode != EXPECTED_STATUS_CODE) {
-               throw new RuntimeException("Unexpected Status when creating enumeration: \""
-                               +vocabName +"\", Status:"+ statusCode);
-       }
-
-       // Store the ID returned from this create operation
-       // for additional tests below.
-       String newVocabId = VocabularyClientUtils.extractId(res);
-       if(logger.isDebugEnabled()){
-               logger.debug("Import: Created vocabulary: \"" + vocabName +"\" ID:"
-                               +newVocabId );
-       }
-       for(String itemName : enumValues){
+    public void createEnumeration(String vocabName, List<String> enumValues) {
+
+        // Expected status code: 201 Created
+        int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+        // Type of service request being tested
+        ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Import: Create vocabulary: \"" + vocabName + "\"");
+        }
+        String baseVocabRefName = VocabularyClientUtils.createVocabularyRefName(vocabName, false);
+        String fullVocabRefName = baseVocabRefName + "'" + vocabName + "'";
+        MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
+                vocabName, fullVocabRefName, client.getCommonPartName());
+        ClientResponse<Response> res = client.create(multipart);
+
+        int statusCode = res.getStatus();
+
+        if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+            throw new RuntimeException("Could not create enumeration: \"" + vocabName
+                    + "\" " + VocabularyClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        }
+        if (statusCode != EXPECTED_STATUS_CODE) {
+            throw new RuntimeException("Unexpected Status when creating enumeration: \""
+                    + vocabName + "\", Status:" + statusCode);
+        }
+
+        // Store the ID returned from this create operation
+        // for additional tests below.
+        String newVocabId = VocabularyClientUtils.extractId(res);
+        if (logger.isDebugEnabled()) {
+            logger.debug("Import: Created vocabulary: \"" + vocabName + "\" ID:"
+                    + newVocabId);
+        }
+        for (String itemName : enumValues) {
             HashMap<String, String> itemInfo = new HashMap<String, String>();
             itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, itemName);
-               VocabularyClientUtils.createItemInVocabulary(newVocabId, 
-                               baseVocabRefName, itemInfo, client);
-       }
+            VocabularyClientUtils.createItemInVocabulary(newVocabId,
+                    baseVocabRefName, itemInfo, client);
+        }
+    }
+
+    public static void main(String[] args) {
+
+        logger.info("VocabularyBaseImport starting...");
+
+        VocabularyBaseImport vbi = new VocabularyBaseImport();
+        final String acquisitionMethodsVocabName = "Acquisition Methods";
+        final String entryMethodsVocabName = "Entry Methods";
+        final String entryReasonsVocabName = "Entry Reasons";
+        final String responsibleDeptsVocabName = "Responsible Departments";
+
+        List<String> acquisitionMethodsEnumValues =
+                Arrays.asList("Gift", "Purchase", "Exchange", "Transfer", "Treasure");
+        List<String> entryMethodsEnumValues =
+                Arrays.asList("In person", "Post", "Found on doorstep");
+        List<String> entryReasonsEnumValues =
+                Arrays.asList("Enquiry", "Commission", "Loan");
+        List<String> respDeptNamesEnumValues =
+                Arrays.asList("Antiquities", "Architecture and Design", "Decorative Arts",
+                "Ethnography", "Herpetology", "Media and Performance Art",
+                "Paintings and Sculpture", "Paleobotany", "Photographs",
+                "Prints and Drawings");
+
+        vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues);
+        vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues);
+        vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues);
+        vbi.createEnumeration(responsibleDeptsVocabName, respDeptNamesEnumValues);
+
+        logger.info("VocabularyBaseImport complete.");
     }
-    
-       public static void main(String[] args) {
-               
-               BasicConfigurator.configure();
-               logger.info("VocabularyBaseImport starting...");
-
-               VocabularyBaseImport vbi = new VocabularyBaseImport();
-               final String acquisitionMethodsVocabName = "Acquisition Methods";
-               final String entryMethodsVocabName = "Entry Methods";
-               final String entryReasonsVocabName = "Entry Reasons";
-               final String responsibleDeptsVocabName = "Responsible Departments";
-
-               List<String> acquisitionMethodsEnumValues = 
-                       Arrays.asList("Gift","Purchase","Exchange","Transfer","Treasure");
-               List<String> entryMethodsEnumValues = 
-                       Arrays.asList("In person","Post","Found on doorstep");
-               List<String> entryReasonsEnumValues = 
-                       Arrays.asList("Enquiry","Commission","Loan");
-               List<String> respDeptNamesEnumValues = 
-                       Arrays.asList("Antiquities","Architecture and Design","Decorative Arts",
-                                                                       "Ethnography","Herpetology","Media and Performance Art",
-                                                                       "Paintings and Sculpture","Paleobotany","Photographs",
-                                                                       "Prints and Drawings");
-
-               vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues);
-               vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues);
-               vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues);
-               vbi.createEnumeration(responsibleDeptsVocabName, respDeptNamesEnumValues);
-
-               logger.info("VocabularyBaseImport complete.");
-       }
 }
diff --git a/services/vocabulary/import/src/main/resources/log4j.properties b/services/vocabulary/import/src/main/resources/log4j.properties
new file mode 100644 (file)
index 0000000..5d288d8
--- /dev/null
@@ -0,0 +1,23 @@
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=WARN\r