本文整理汇总了Java中org.wso2.carbon.registry.core.Resource.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getContent方法的具体用法?Java Resource.getContent怎么用?Java Resource.getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.registry.core.Resource
的用法示例。
在下文中一共展示了Resource.getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRatingsPath
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testRatingsPath() throws Exception {
Resource r5 = registry.newResource();
String r5Content = "this is r5 content";
r5.setContent(RegistryUtils.encodeString(r5Content));
r5.setDescription("production ready.");
String r5Path = "/c1/r5";
registry.put(r5Path, r5);
registry.rateResource("/c1/r5", 3);
Resource ratings = registry.get("/c1/r5;ratings");
String[] ratingPaths = (String[]) ratings.getContent();
int rating;
Resource c1 = registry.get(ratingPaths[0]);
Object o = c1.getContent();
if (o instanceof Integer) {
rating = (Integer) o;
} else {
rating = Integer.parseInt(o.toString());
}
assertEquals("Ratings are not retrieved properly as resources.", rating, 3);
}
示例2: buildOMContent
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private static String buildOMContent(Resource resource, StatCollection currentCollection) throws Exception {
String content = null;
String property = resource.getProperty(REGISTRY_LIFECYCLE_HISTORY_ORDER);
int newOrder = 0;
if (property != null) {
newOrder = Integer.parseInt(property) + 1;
}
resource.setProperty(REGISTRY_LIFECYCLE_HISTORY_ORDER, "" + newOrder);
if (resource.getContent() != null) {
if (resource.getContent() instanceof String) {
content = (String) resource.getContent();
} else if (resource.getContent() instanceof byte[]) {
content = RegistryUtils.decodeBytes((byte[]) resource.getContent());
}
}
if (content == null) {
content = buildInitialOMElement().toString();
}
return addNewContentElement(content, currentCollection, newOrder);
}
示例3: put
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void put(RequestContext requestContext) throws RegistryException {
if (!CommonUtil.isUpdateLockAvailable()) {
return;
}
CommonUtil.acquireUpdateLock();
try {
SchemaValidator validator = new SchemaValidator();
Resource resource = requestContext.getResource();
Object resourceContent = resource.getContent();
if (resourceContent instanceof byte[]) {
InputStream in = new ByteArrayInputStream((byte[]) resourceContent);
validator.validate(in, resource);
}
resource.setContentStream(null);
// requestContext.getRegistry().put(resource.getPath() ,resource);
} finally {
CommonUtil.releaseUpdateLock();
}
}
示例4: getWSDLComparison
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
* This method is used to get wsdl difference comparison.
*
* @param WSDLOne wsdl one.
* @param WSDLTwo wsdl two.
* @return Comparison object which includes the difference parameters.
* @throws ComparisonException
* @throws WSDLException
* @throws RegistryException
* @throws UnsupportedEncodingException
*/
private Comparison getWSDLComparison(Resource WSDLOne, Resource WSDLTwo)
throws ComparisonException, WSDLException, RegistryException, UnsupportedEncodingException {
GovernanceDiffGeneratorFactory diffGeneratorFactory = new GovernanceDiffGeneratorFactory();
DiffGenerator flow = diffGeneratorFactory.getDiffGenerator();
if (flow != null) {
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
InputSource inputSourceOne = new InputSource(new ByteArrayInputStream((byte[]) WSDLOne.getContent()));
Definition originalWSDL = wsdlReader.readWSDL(null, inputSourceOne);
InputSource inputSourceTwo = new InputSource(new ByteArrayInputStream((byte[]) WSDLTwo.getContent()));
Definition changedWSDL = wsdlReader.readWSDL(null, inputSourceTwo);
return flow.compare(originalWSDL, changedWSDL, ComparatorConstants.WSDL_MEDIA_TYPE);
} else {
return null;
}
}
示例5: getAccessTokenFromRegistry
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
* Helper method to get current access token resides in the registry.
*
* @return accessToken
* @throws Exception
*/
private String getAccessTokenFromRegistry() throws Exception {
if (SQLDriverDSComponent.getRegistryService() == null) {
String msg = "GSpreadConfig.getFeed(): Registry service is not available, authentication key sharing fails";
throw new SQLException(msg);
}
Registry registry = SQLDriverDSComponent.getRegistryService()
.getGovernanceSystemRegistry(TDriverUtil.getCurrentTenantId());
Resource authTokenRes = this.getAuthTokenResource(registry);
if (authTokenRes != null) {
Object content = authTokenRes.getContent();
if (content != null) {
return new String((byte[]) content, this.charSetType);
}
}
return null;
}
示例6: readPolicy
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
* @param policyId
* @param finder
* @return
* @throws EntitlementException
*/
public synchronized AbstractPolicy readPolicy(String policyId, PolicyFinder finder)
throws EntitlementException {
Resource resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP);
if (resource != null) {
try {
String policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8"));
return PAPPolicyReader.getInstance(null).getPolicy(policy);
} catch (RegistryException e) {
log.error("Error while parsing entitlement policy", e);
throw new EntitlementException("Error while loading entitlement policy");
}
}
return null;
}
示例7: readPolicy
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
* Reads PolicyDTO for given registry resource
*
* @param resource Registry resource
* @return PolicyDTO
* @throws EntitlementException throws, if fails
*/
private PolicyDTO readPolicy(Resource resource) throws EntitlementException {
String policy = null;
AbstractPolicy absPolicy = null;
PolicyDTO dto = null;
try {
if (resource.getContent() == null) {
throw new EntitlementException("Error while loading entitlement policy. Policy content is null");
}
policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8"));
absPolicy = PAPPolicyReader.getInstance(null).getPolicy(policy);
dto = new PolicyDTO();
dto.setPolicyId(absPolicy.getId().toASCIIString());
dto.setPolicy(policy);
String policyOrder = resource.getProperty("order");
if (policyOrder != null) {
dto.setPolicyOrder(Integer.parseInt(policyOrder));
} else {
dto.setPolicyOrder(0);
}
String policyActive = resource.getProperty("active");
if (policyActive != null) {
dto.setActive(Boolean.parseBoolean(policyActive));
}
PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder();
dto.setAttributeDTOs(policyAttributeBuilder.
getPolicyMetaDataFromRegistryProperties(resource.getProperties()));
return dto;
} catch (RegistryException e) {
log.error("Error while loading entitlement policy", e);
throw new EntitlementException("Error while loading entitlement policy", e);
}
}
示例8: getFirstObjectWithPropertyValue
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
* Returns the first object in a registry path with a given property value.
*
* @param path registry path
* @param propName name of the property to be matched
* @param value value of the property to be matched
* @return first objects matching the given property value in the given registry path
* @throws IdentityException if an error occurs while reading the registry
*/
public T getFirstObjectWithPropertyValue(String path, String propName, String value)
throws IdentityException {
Resource resource = null;
Map<String, String> params = null;
Resource result = null;
String[] paths = null;
try {
if (log.isErrorEnabled()) {
log.debug("Retrieving first object from the registry path with property value "
+ path);
}
params = new HashMap<String, String>();
params.put("1", propName);
params.put("2", value);
result = registry.executeQuery(getCustomQuery(), params);
paths = (String[]) result.getContent();
if (paths != null && paths.length > 0) {
resource = registry.get(paths[0]);
}
} catch (RegistryException e) {
String message = "Error while retrieving first object from the registry path with property value";
log.error(message, e);
throw IdentityException.error(message, e);
}
return resourceToObject(resource);
}
示例9: get
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
@Override
public ServiceVersionV1 get(Resource resource, Registry registry) throws MetadataException {
try {
byte[] contentBytes = (byte[]) resource.getContent();
OMElement root = Util.buildOMElement(contentBytes);
Map<String, List<String>> propBag = Util.getPropertyBag(root);
return getFilledBean(root, propBag, registry);
} catch (RegistryException e) {
throw new MetadataException("Error occurred while obtaining resource metadata content uuid = " + resource.getUUID(), e);
}
}
示例10: makeDataHandler
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static DataHandler makeDataHandler(Resource resource, File tempFile) throws IOException, RegistryException{
if ((resource instanceof Collection) || (resource.getContent() == null)) {
return null;
}
InputStream is = null;
OutputStream os = null;
try {
os = new FileOutputStream(tempFile);
if (resource.getContent() instanceof String[]
&& !(resource.getContent() instanceof String)) { // To accommodate collections and ratings
String[] strArray = (String[]) resource.getContent();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(strArray);
} else {
try {
is = resource.getContentStream();
// os = new FileOutputStream(tempFile);
byte[] buffer = new byte[4096];
for (int n; (n = is.read(buffer)) != -1; )
os.write(buffer, 0, n);
os.flush();
} finally {
if (is != null) {
is.close();
}
}
}
} finally {
if (os != null) {
os.close();
}
}
// Base64Binary base64Binary = new Base64Binary();
return new DataHandler(new FileDataSource(tempFile));
}
示例11: get
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
@Override
public Base get(Resource resource, Registry registry) throws MetadataException {
try {
byte[] contentBytes = (byte[]) resource.getContent();
OMElement root = Util.buildOMElement(contentBytes);
Map<String, List<String>> propBag = Util.getPropertyBag(root);
return getFilledBean(root, propBag, registry);
} catch (RegistryException e) {
throw new MetadataException("Error occurred while obtaining resource metadata content uuid = " + resource.getUUID(), e);
}
}
示例12: getByteContent
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static byte[] getByteContent(Resource resource, String sourceURL)
throws RegistryException {
try {
InputStream is = null;
if (sourceURL != null) {
is = new URL(sourceURL).openStream();
} else {
Object content = resource.getContent();
if( null == content) {
//returning an empty array, rather than 'null'.
return new byte[0];
}
is = resource.getContentStream();
if (is == null) {
if (content instanceof byte[]) {
return (byte[]) content;
} else if (content instanceof String) {
return RegistryUtils.encodeString((String) content);
} else {
throw new RegistryException("Unknown type found as content " + content);
}
}
}
return readBytesFromInputSteam(is);
} catch (IOException e) {
throw new RegistryException("Error at indexing", e);
}
}
示例13: convertContentToString
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private static String convertContentToString(Resource resource) throws RegistryException {
if (resource.getContent() instanceof String) {
return RegistryUtils.decodeBytes(((String) resource.getContent()).getBytes());
} else if (resource.getContent() instanceof byte[]) {
return RegistryUtils.decodeBytes((byte[]) resource.getContent());
}
return RegistryUtils.decodeBytes("".getBytes());
}
示例14: retrieve
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private Object retrieve(String resourcePath) {
try {
Resource resource = registryService.get(resourcePath);
return resource.getContent();
} catch (ResourceNotFoundException ignore) {
// this means, we've never persisted info in registry
return null;
} catch (RegistryException e) {
String msg = "Failed to retrieve data from registry.";
log.error(msg, e);
throw new AutoScalerException(msg, e);
}
}
示例15: removeEndpointEntry
import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static void removeEndpointEntry(String oldWSDL, String servicePath, OMElement serviceElement, Registry registry)
throws RegistryException {
List<OMElement> serviceEndpointEntryElements = getOmElements(serviceElement);
if (serviceEndpointEntryElements == null || serviceEndpointEntryElements.size() == 0) {
return;
}
String endpointURL = null;
if (registry.resourceExists(oldWSDL)){
Association[] associations = registry.getAssociations(oldWSDL, CommonConstants.DEPENDS);
for (Association association: associations) {
String targetPath = association.getDestinationPath();
if (registry.resourceExists(targetPath)) {
Resource targetResource = registry.get(targetPath);
if (CommonConstants.ENDPOINT_MEDIA_TYPE.equals(targetResource.getMediaType())) {
byte[] sourceContent = (byte[]) targetResource.getContent();
if (sourceContent == null) {
continue;
}
endpointURL = EndpointUtils.deriveEndpointFromContent(RegistryUtils.decodeBytes(sourceContent));
}
}
}
}
for(OMElement endpointOmElement : serviceEndpointEntryElements){
if(endpointOmElement!=null){
String entryText = endpointOmElement.getText();
if (endpointURL != null && entryText.contains(endpointURL) ){
endpointOmElement.detach();
}
}
}
}