コード例 #1
0
ファイル: andsDoi.py プロジェクト: redbox-mint/redbox
 def urlPost(self, url, postBody):
     try:
         client = BasicHttpClient(url)
         post = PostMethod(url)
         #######
         # Which will work?
         #post.setRequestBody(postBody)
         post.addParameter("xml", postBody)
         #######
         sharedSecret = self.doiConfig("sharedSecret")
         if (sharedSecret):
             apiKey = self.doiConfig("apiKey")
             if (apiKey is not None):
                 client.authenticate(apiKey, sharedSecret)
             else:
                 raise EnvironmentError("Cannot have shared secret without an api key")
         code = client.executeMethod(post)
         if str(code) == "302":
             locationHeader = post.getResponseHeader("location")
             if locationHeader is not None:
                 redirectLocation = locationHeader.getValue()
                 self.log.info("302 Redirection was requested: '{}'", redirectLocation)
                 ##return self.urlPost(redirectLocation, postBody)
         body = str(post.getResponseBodyAsString()).strip()
         return (str(code), body)
     except Exception, e:
         self.log.error("Error during HTTP request: ", e)
         return (None, None)
コード例 #2
0
ファイル: CQ5 Loader.py プロジェクト: amancevice/legacy
	def enhancePages( self, project, connector_url, cq_user, cq_password, page_query, page_queryLib ):	
				
		# Validate Parameters
		if not self.validInputs(connector_url,cq_user,cq_password,"asset_drive","asset_filenameAttr","asset_pathAttr",page_query,page_queryLib,"ia_path","ia_cacheCols"): return
		
		# HTTP Connection Details
		client = HttpClient()
		base64EncodedCredentials = Base64.encodeString("%s:%s" % (cq_user,cq_password))
		header = Header("Authorization", "Basic %s" % (base64EncodedCredentials))
		
		# Cycle through contentdescriptors specified by scope query
		query = queryLibrarianService.findQueryByName(page_queryLib, page_query)
		params = HashMap()
		params.put('projectId',project.id)
		res = queryLibrarianService.executeQuery(query, params)
		
		# Get cd
		for r in res:
			cd = r[0]
			post = PostMethod(connector_url)
			post.addRequestHeader(header)
			get = GetMethod(connector_url)
			get.addRequestHeader(header)
			try:
				payload = cd.getContent()[0].getContentData().encode("utf-8")
				[loadStatus, failureReason] = self.sendPayload(client,get,post,payload,cd.url)
				cd.metadata["Load.Status"] = loadStatus
				cd.metadata["Load.Failure Reason"] = failureReason
				if loadStatus != "SUCCESS":
					logger.error("url: %s, reason: %s" % (cd.url, failureReason))
			except:
				cd.metadata["Load.Status"] = "FAILURE"
				cd.metadata["Load.Failure Reason"] = "Null content"
				logger.error("url: %s, reason: %s" % (cd.url, failureReason))
コード例 #3
0
ファイル: CQ5 Loader.py プロジェクト: amancevice/legacy
	def enhanceIA( self, connector_url, cq_user, cq_password, ia_path, ia_cacheCols ):
		
		# Validate Parameters
		if not self.validInputs(connector_url,cq_user,cq_password,"asset_drive","asset_filenameAttr","asset_pathAttr","page_query","page_queryLib",ia_path,ia_cacheCols): return
		
		# HTTP Connection Details
		client = HttpClient()
		base64EncodedCredentials = Base64.encodeString("%s:%s" % (cq_user,cq_password))
		header = Header("Authorization", "Basic %s" % (base64EncodedCredentials))
		
		# IA Build
		cached_IA = self.cacheIA(ia_path,ia_cacheCols)
		for placeholder in cached_IA:
			
			post = PostMethod(connector_url)
			post.addRequestHeader(header)
			get = GetMethod(connector_url)
			get.addRequestHeader(header)
			
			# Prep Payload
			path = placeholder["Path"]
			filename = placeholder["Filename"]
			template_path = placeholder["Template Path"]
			label = placeholder["Label"]
			
			# Send Payload
			payload = '<page path="%s" filename="%s" template_path="%s" label="%s"><node path="jcr:content" type="nt:unstructured"><prop name="jcr:title" type="String">%s</prop></node></page>' % (path,filename,template_path,label,label)
			[loadStatus, failureReason] = self.sendPayload(client,get,post,payload,path+filename)
			if loadStatus != "SUCCESS":
				logger.error("url: %s, reason: %s" % (placeholder["URL"], failureReason))
コード例 #4
0
 def __post(self):
     try:
         post = PostMethod(self.url)
         post.setRequestBody(self.payload)
         statusInt = client.executeMethod(post)
         r = str(statusInt), post.getResponseBodyAsString().strip()
     except Exception, e:
         r = str(e), None
コード例 #5
0
 def __post(self):
     try:
         post = PostMethod(self.url)
         post.setRequestBody(self.payload)
         statusInt = self.client.executeMethod(post)
         r = str(statusInt), post.getResponseBodyAsString().strip()
     except Exception, e:
         r = str(e), None
コード例 #6
0
ファイル: annotation.py プロジェクト: kiranba/the-fascinator
 def __put(self, url, data):
     try:
         client = BasicHttpClient(url)
         put = PostMethod(url)
         put.addParameter("", data)
         statusInt = client.executeMethod(put)
         r = str(statusInt), post.getResponseBodyAsString().strip()
     except Exception, e:
         r = str(e), None
コード例 #7
0
ファイル: CQ5 Loader.py プロジェクト: amancevice/legacy
	def enhance( self, contentDescriptor, content, connector_url, cq_user, cq_password, asset_doWebDAV, asset_skeleton, asset_transformationRules, asset_drive, asset_filenameAttr, asset_pathAttr ):
		
		# Validate Parameters
		if not self.validInputs(connector_url,cq_user,cq_password,asset_drive,asset_filenameAttr,asset_pathAttr,"page_query","page_querylib","ia_path","ia_cacheCols"): return
		
		if asset_doWebDAV:
			# Save Asset to WebDAV Drive
			drive = asset_drive[0]
			path = re.sub("/content/dam/","/var/dam/",contentDescriptor.metadata[asset_pathAttr])
			filename = contentDescriptor.metadata[asset_filenameAttr]
			filepath = "%s:%s/%s" % (drive,path,filename)
			
			if not exists("%s:%s" % (drive,path)): makedirs("%s:%s" % (drive,path))
			file = BufferedOutputStream(FileOutputStream(filepath))
			data = Base64.decode(content.contentData)
			try: 
				file.write(data, 0, len(data))
				file.close()
				contentDescriptor.metadata["Load.Status"] = "SUCCESS"
			except:
				logger.error("! [WebDAV] Could not write %s to file system" % (contentDescriptor.url))
				file.close()
				contentDescriptor.metadata["Load.Status"] = "FAILURE"
				contentDescriptor.metadata["Load.Failure Reason"] = "! [WebDAV] Could not deposit file on file system"
				return
			
		# Build & Send Asset Metadata Payload if required
		if asset_skeleton and asset_transformationRules:
			
			# Build Payload
			payload = self.buildAssetPayload(asset_skeleton,asset_transformationRules,content,contentDescriptor)
			
			# HTTP Connection Details
			client = HttpClient()
			base64EncodedCredentials = Base64.encodeString("%s:%s" % (cq_user,cq_password))
			header = Header("Authorization", "Basic %s" % (base64EncodedCredentials))
			
			# Send Metadata Payload
			post = PostMethod(connector_url)
			post.addRequestHeader(header)
			get = GetMethod(connector_url)
			get.addRequestHeader(header)
			[loadStatus, failureReason] = self.sendPayload(client,get,post,payload,contentDescriptor.url)
			contentDescriptor.metadata["Load.Status"] = loadStatus
			if loadStatus == "SUCCESS":
				contentDescriptor.metadata["Load.Failure Reason"] = ''
			else:
				contentDescriptor.metadata["Load.Failure Reason"] = "Metadata: "+failureReason
				logger.error("! [METADATA] %s" % (failureReason))		
コード例 #8
0
    def enhancePages(self, project, connector_url, cq_user, cq_password,
                     page_query, page_queryLib):

        # Validate Parameters
        if not self.validInputs(connector_url, cq_user, cq_password,
                                "asset_drive", "asset_filenameAttr",
                                "asset_pathAttr", page_query, page_queryLib,
                                "ia_path", "ia_cacheCols"):
            return

        # HTTP Connection Details
        client = HttpClient()
        base64EncodedCredentials = Base64.encodeString("%s:%s" %
                                                       (cq_user, cq_password))
        header = Header("Authorization",
                        "Basic %s" % (base64EncodedCredentials))

        # Cycle through contentdescriptors specified by scope query
        query = queryLibrarianService.findQueryByName(page_queryLib,
                                                      page_query)
        params = HashMap()
        params.put('projectId', project.id)
        res = queryLibrarianService.executeQuery(query, params)

        # Get cd
        for r in res:
            cd = r[0]
            post = PostMethod(connector_url)
            post.addRequestHeader(header)
            get = GetMethod(connector_url)
            get.addRequestHeader(header)
            try:
                payload = cd.getContent()[0].getContentData().encode("utf-8")
                [loadStatus,
                 failureReason] = self.sendPayload(client, get, post, payload,
                                                   cd.url)
                cd.metadata["Load.Status"] = loadStatus
                cd.metadata["Load.Failure Reason"] = failureReason
                if loadStatus != "SUCCESS":
                    logger.error("url: %s, reason: %s" %
                                 (cd.url, failureReason))
            except:
                cd.metadata["Load.Status"] = "FAILURE"
                cd.metadata["Load.Failure Reason"] = "Null content"
                logger.error("url: %s, reason: %s" % (cd.url, failureReason))
コード例 #9
0
    def enhanceIA(self, connector_url, cq_user, cq_password, ia_path,
                  ia_cacheCols):

        # Validate Parameters
        if not self.validInputs(connector_url, cq_user, cq_password,
                                "asset_drive", "asset_filenameAttr",
                                "asset_pathAttr", "page_query",
                                "page_queryLib", ia_path, ia_cacheCols):
            return

        # HTTP Connection Details
        client = HttpClient()
        base64EncodedCredentials = Base64.encodeString("%s:%s" %
                                                       (cq_user, cq_password))
        header = Header("Authorization",
                        "Basic %s" % (base64EncodedCredentials))

        # IA Build
        cached_IA = self.cacheIA(ia_path, ia_cacheCols)
        for placeholder in cached_IA:

            post = PostMethod(connector_url)
            post.addRequestHeader(header)
            get = GetMethod(connector_url)
            get.addRequestHeader(header)

            # Prep Payload
            path = placeholder["Path"]
            filename = placeholder["Filename"]
            template_path = placeholder["Template Path"]
            label = placeholder["Label"]

            # Send Payload
            payload = '<page path="%s" filename="%s" template_path="%s" label="%s"><node path="jcr:content" type="nt:unstructured"><prop name="jcr:title" type="String">%s</prop></node></page>' % (
                path, filename, template_path, label, label)
            [loadStatus,
             failureReason] = self.sendPayload(client, get, post, payload,
                                               path + filename)
            if loadStatus != "SUCCESS":
                logger.error("url: %s, reason: %s" %
                             (placeholder["URL"], failureReason))
コード例 #10
0
ファイル: andsDoi.py プロジェクト: jcu-eresearch-admin/redbox
 def urlPost(self, url, postBody):
     try:
         client = BasicHttpClient(url)
         post = PostMethod(url)
         #######
         # Which will work?
         #post.setRequestBody(postBody)
         post.addParameter("xml", postBody) 
         #######
         code = client.executeMethod(post)
         if str(code) == "302":
             locationHeader = post.getResponseHeader("location");
             if locationHeader is not None:
                 redirectLocation = locationHeader.getValue();
                 self.log.info("302 Redirection was requested: '{}'", redirectLocation)
                 ##return self.urlPost(redirectLocation, postBody)
         body = post.getResponseBodyAsString().strip()
         return (str(code), body)
     except Exception, e:
         self.log.error("Error during HTTP request: ", e)
         return (None, None)
コード例 #11
0
ファイル: andsDoi.py プロジェクト: nishen/redbox
 def urlPost(self, url, postBody):
     try:
         client = BasicHttpClient(url)
         post = PostMethod(url)
         #######
         # Which will work?
         #post.setRequestBody(postBody)
         post.addParameter("xml", postBody)
         #######
         code = client.executeMethod(post)
         if str(code) == "302":
             locationHeader = post.getResponseHeader("location")
             if locationHeader is not None:
                 redirectLocation = locationHeader.getValue()
                 self.log.info("302 Redirection was requested: '{}'",
                               redirectLocation)
                 ##return self.urlPost(redirectLocation, postBody)
         body = post.getResponseBodyAsString().strip()
         return (str(code), body)
     except Exception, e:
         self.log.error("Error during HTTP request: ", e)
         return (None, None)
コード例 #12
0
    def enhance(self, contentDescriptor, content, connector_url, cq_user,
                cq_password, asset_doWebDAV, asset_skeleton,
                asset_transformationRules, asset_drive, asset_filenameAttr,
                asset_pathAttr):

        # Validate Parameters
        if not self.validInputs(connector_url, cq_user, cq_password,
                                asset_drive, asset_filenameAttr,
                                asset_pathAttr, "page_query", "page_querylib",
                                "ia_path", "ia_cacheCols"):
            return

        if asset_doWebDAV:
            # Save Asset to WebDAV Drive
            drive = asset_drive[0]
            path = re.sub("/content/dam/", "/var/dam/",
                          contentDescriptor.metadata[asset_pathAttr])
            filename = contentDescriptor.metadata[asset_filenameAttr]
            filepath = "%s:%s/%s" % (drive, path, filename)

            if not exists("%s:%s" % (drive, path)):
                makedirs("%s:%s" % (drive, path))
            file = BufferedOutputStream(FileOutputStream(filepath))
            data = Base64.decode(content.contentData)
            try:
                file.write(data, 0, len(data))
                file.close()
                contentDescriptor.metadata["Load.Status"] = "SUCCESS"
            except:
                logger.error("! [WebDAV] Could not write %s to file system" %
                             (contentDescriptor.url))
                file.close()
                contentDescriptor.metadata["Load.Status"] = "FAILURE"
                contentDescriptor.metadata[
                    "Load.Failure Reason"] = "! [WebDAV] Could not deposit file on file system"
                return

        # Build & Send Asset Metadata Payload if required
        if asset_skeleton and asset_transformationRules:

            # Build Payload
            payload = self.buildAssetPayload(asset_skeleton,
                                             asset_transformationRules,
                                             content, contentDescriptor)

            # HTTP Connection Details
            client = HttpClient()
            base64EncodedCredentials = Base64.encodeString(
                "%s:%s" % (cq_user, cq_password))
            header = Header("Authorization",
                            "Basic %s" % (base64EncodedCredentials))

            # Send Metadata Payload
            post = PostMethod(connector_url)
            post.addRequestHeader(header)
            get = GetMethod(connector_url)
            get.addRequestHeader(header)
            [loadStatus,
             failureReason] = self.sendPayload(client, get, post, payload,
                                               contentDescriptor.url)
            contentDescriptor.metadata["Load.Status"] = loadStatus
            if loadStatus == "SUCCESS":
                contentDescriptor.metadata["Load.Failure Reason"] = ''
            else:
                contentDescriptor.metadata[
                    "Load.Failure Reason"] = "Metadata: " + failureReason
                logger.error("! [METADATA] %s" % (failureReason))