From: Sanjay Dalal Date: Sat, 13 Feb 2010 01:36:15 +0000 (+0000) Subject: CSPACE-597 added setProxy method to VocabClient to pick up httpclient with props... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ae04735b34610b765886cb760541eef856e7d6d6;p=tmp%2Fjakarta-migration.git CSPACE-597 added setProxy method to VocabClient to pick up httpclient with props set for authentication. Properties required to pass to run in auth mode are -Dcspace.auth=true -Dcspace.user=test -Dcspace.password=test (see services/trunk/services/client/src/main/resources/collectionspace-client.properties) 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 --- diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java index 1a0a66b45..8befd392b 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java @@ -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 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 readItem(String vcsid, String csid) { return vocabularyProxy.readItem(vcsid, csid); } diff --git a/services/vocabulary/import/pom.xml b/services/vocabulary/import/pom.xml index e3c9f704d..3f4ac7202 100644 --- a/services/vocabulary/import/pom.xml +++ b/services/vocabulary/import/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> org.collectionspace.services @@ -14,9 +14,17 @@ org.collectionspace.services.vocabulary.importer 1.0 services.vocabulary.importer - + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + org.collectionspace.services org.collectionspace.services.vocabulary.jaxb @@ -32,24 +40,14 @@ org.collectionspace.services.vocabulary.client ${cspace.services.client.version} - - - - org.slf4j - slf4j-api - 1.5.2 - - + --> org.jboss.resteasy resteasy-jaxrs @@ -78,32 +76,32 @@ 3.1 - + collectionspace-services-vocabulary-importer - - org.apache.maven.plugins - maven-assembly-plugin - - - - attached - - package - - - jar-with-dependencies - - - - org.collectionspace.services.vocabulary.importer.VocabularyBaseImport - - - - - - + + org.apache.maven.plugins + maven-assembly-plugin + + + + attached + + package + + + jar-with-dependencies + + + + org.collectionspace.services.vocabulary.importer.VocabularyBaseImport + + + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java index c5ee6e83d..4ae3de0cc 100644 --- a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java +++ b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java @@ -20,28 +20,20 @@ * 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 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 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 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 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 itemInfo = new HashMap(); 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 acquisitionMethodsEnumValues = + Arrays.asList("Gift", "Purchase", "Exchange", "Transfer", "Treasure"); + List entryMethodsEnumValues = + Arrays.asList("In person", "Post", "Found on doorstep"); + List entryReasonsEnumValues = + Arrays.asList("Enquiry", "Commission", "Loan"); + List 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 acquisitionMethodsEnumValues = - Arrays.asList("Gift","Purchase","Exchange","Transfer","Treasure"); - List entryMethodsEnumValues = - Arrays.asList("In person","Post","Found on doorstep"); - List entryReasonsEnumValues = - Arrays.asList("Enquiry","Commission","Loan"); - List 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 index 000000000..5d288d87d --- /dev/null +++ b/services/vocabulary/import/src/main/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=WARN