本文整理汇总了Java中org.jets3t.service.Constants类的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Constants类属于org.jets3t.service包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetMetadataFile
import org.jets3t.service.Constants; //导入依赖的package包/类
@Test
public void testGetMetadataFile() throws Exception {
final S3Session session = new S3Session(
new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
new Credentials(
System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
)));
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.volume));
final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new S3TouchFeature(session).touch(test, new TransferStatus().withMime("text/plain"));
final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(test);
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertFalse(metadata.isEmpty());
assertTrue(metadata.containsKey("Content-Type"));
assertEquals("text/plain", metadata.get("Content-Type"));
assertFalse(metadata.containsKey(Constants.KEY_FOR_USER_METADATA));
assertFalse(metadata.containsKey(Constants.KEY_FOR_SERVICE_METADATA));
assertFalse(metadata.containsKey(Constants.KEY_FOR_COMPLETE_METADATA));
session.close();
}
示例2: toXMLBuilder
import org.jets3t.service.Constants; //导入依赖的package包/类
public XMLBuilder toXMLBuilder() throws ServiceException, ParserConfigurationException,
FactoryConfigurationError, TransformerException
{
if (owner == null) {
throw new ServiceException("Invalid AccessControlList: missing an owner");
}
XMLBuilder builder = XMLBuilder.create("AccessControlPolicy")
.attr("xmlns", Constants.XML_NAMESPACE)
.elem("Owner")
.elem("ID").text(owner.getId()).up()
.elem("DisplayName").text(owner.getDisplayName()).up()
.up();
XMLBuilder accessControlList = builder.elem("AccessControlList");
for (GrantAndPermission gap: grants) {
GranteeInterface grantee = gap.getGrantee();
Permission permission = gap.getPermission();
accessControlList
.elem("Grant")
.importXMLBuilder(grantee.toXMLBuilder())
.elem("Permission").text(permission.toString());
}
return builder;
}
示例3: AWSRoleSessionCredentials
import org.jets3t.service.Constants; //导入依赖的package包/类
public AWSRoleSessionCredentials(String iamAccessKey, String iamSecretKey, String roleToBeAssumed, String externalId,
String friendlyName, Jets3tProperties jets3tProperties){
if(roleToBeAssumed == null){
throw new IllegalArgumentException("roleToBeAssumed needs to be present.");
}
this.iamAccessKey = iamAccessKey;
this.iamSecretKey = iamSecretKey;
this.roleToBeAssumed = roleToBeAssumed;
this.externalId = externalId;
this.friendlyName = friendlyName;
if(jets3tProperties == null){
this.jets3tProperties = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME);
}else {
this.jets3tProperties = jets3tProperties;
}
assumeRoleAndGetCredentials();
}
示例4: getUserAgentDescription
import org.jets3t.service.Constants; //导入依赖的package包/类
/**
* Returns a user agent string describing the jets3t library, and optionally the application
* using it, to server-side services.
*
* @param applicationDescription
* a description of the application using the jets3t toolkit, included at the end of the
* user agent string. This value may be null.
* @return
* a string built with the following components (some elements may not be available):
* <tt>JetS3t/</tt><i>{@link Constants#JETS3T_VERSION}</i>
* (<i>os.name</i>/<i>os.version</i>; <i>os.arch</i>; <i>user.region</i>;
* <i>user.region</i>; <i>user.language</i>) <i>applicationDescription</i></tt>
*
*/
public static String getUserAgentDescription(String applicationDescription) {
return
"JetS3t/" + Constants.JETS3T_VERSION + " ("
+ System.getProperty("os.name") + "/"
+ System.getProperty("os.version") + ";"
+ " " + System.getProperty("os.arch")
+ (System.getProperty("user.region") != null
? "; " + System.getProperty("user.region")
: "")
+ (System.getProperty("user.language") != null
? "; " + System.getProperty("user.language")
: "")
+ (System.getProperty("java.version") != null
? "; JVM " + System.getProperty("java.version")
: "")
+ ")"
+ (applicationDescription != null
? " " + applicationDescription
: "");
}
示例5: load
import org.jets3t.service.Constants; //导入依赖的package包/类
/**
* Loads the products listed in the {@link java.util.Properties}.
* Specifically, any properties ending in {@link Constants#DEVPAY_PRODUCT_NAME_PROP_SUFFIX}
* (the product's name)
* have that ending removed and replaced with {@link Constants#DEVPAY_PRODUCT_NAME_PROP_SUFFIX}
* (to form name of the property for the product's token).
* If the token exists, then a <code>AWSDevPayProduct</code> is constructed
* with that name and token, and then is added to the Vector. For example,
* (with the current constants) "foo.name" would become "foo.token";
* if both properties exist, then a product is constructed with the values of
* the "foo.name" and "foo.token" properties (e.g. "Foo" and "{ProductToken}AAA...").
*
* @param prodProps the properties
*
* @return the Vector of <code>AWSDevPayProduct</code>s, sorted by name
*/
public static Vector load(Properties prodProps) {
Vector ret = new Vector();
Enumeration propEnum = prodProps.propertyNames();
while (propEnum.hasMoreElements()) {
String propName = (String) propEnum.nextElement();
if (propName.endsWith(Constants.DEVPAY_PRODUCT_NAME_PROP_SUFFIX)) {
String tokenPropName = propName.substring(0,
propName.length()-Constants.DEVPAY_PRODUCT_NAME_PROP_SUFFIX.length()) +
Constants.DEVPAY_PRODUCT_TOKEN_PROP_SUFFIX;
String prodName = prodProps.getProperty(propName);
String prodToken = prodProps.getProperty(tokenPropName);
if (prodToken != null) {
ret.add(new AWSDevPayProduct(prodToken, prodName));
}
}
}
Collections.sort(ret);
return ret;
}
示例6: toXMLBuilder
import org.jets3t.service.Constants; //导入依赖的package包/类
public XMLBuilder toXMLBuilder() throws ParserConfigurationException,
FactoryConfigurationError, TransformerException
{
XMLBuilder builder = XMLBuilder.create("BucketLoggingStatus")
.attr("xmlns", Constants.XML_NAMESPACE);
if (isLoggingEnabled()) {
XMLBuilder enabledBuilder = builder.elem("LoggingEnabled")
.elem("TargetBucket").text(getTargetBucketName()).up()
.elem("TargetPrefix").text(getLogfilePrefix()).up();
if (targetGrantsList.size() > 0) {
Iterator<GrantAndPermission> targetGrantsIter = targetGrantsList.iterator();
XMLBuilder grantsBuilder = enabledBuilder.elem("TargetGrants");
while (targetGrantsIter.hasNext()) {
GrantAndPermission gap = targetGrantsIter.next();
grantsBuilder.elem("Grant")
.importXMLBuilder(gap.getGrantee().toXMLBuilder())
.elem("Permission").text(gap.getPermission().toString());
}
}
}
return builder;
}
示例7: setBucketPolicyImpl
import org.jets3t.service.Constants; //导入依赖的package包/类
@Override
protected void setBucketPolicyImpl(String bucketName, String policyDocument)
throws S3ServiceException
{
Map<String, String> requestParameters = new HashMap<String, String>();
requestParameters.put("policy", "");
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("Content-Type", "text/plain");
try {
performRestPut(bucketName, null, metadata, requestParameters,
new StringEntity(policyDocument, "text/plain", Constants.DEFAULT_ENCODING),
true);
} catch (ServiceException se) {
throw new S3ServiceException(se);
} catch (UnsupportedEncodingException e) {
throw new S3ServiceException("Unable to encode LoggingStatus XML document", e);
}
}
示例8: performRestPutWithXmlBuilder
import org.jets3t.service.Constants; //导入依赖的package包/类
protected HttpResponseAndByteCount performRestPutWithXmlBuilder(String bucketName,
String objectKey, Map<String, Object> metadata, Map<String, String> requestParameters,
XMLBuilder builder) throws ServiceException
{
try {
if (metadata == null) {
metadata = new HashMap<String, Object>();
}
if (!metadata.containsKey("content-type")) {
metadata.put("Content-Type", "text/plain");
}
String xml = builder.asString(null);
return performRestPut(bucketName, objectKey, metadata, requestParameters,
new StringEntity(xml, "text/plain", Constants.DEFAULT_ENCODING), true);
} catch (Exception e) {
if (e instanceof ServiceException) {
throw (ServiceException) e;
} else {
throw new ServiceException("Failed to PUT request containing an XML document", e);
}
}
}
示例9: performRestPostWithXmlBuilder
import org.jets3t.service.Constants; //导入依赖的package包/类
protected HttpResponse performRestPostWithXmlBuilder(String bucketName,
String objectKey, Map<String, Object> metadata, Map<String, String> requestParameters,
XMLBuilder builder) throws ServiceException
{
try {
if (metadata == null) {
metadata = new HashMap<String, Object>();
}
if (!metadata.containsKey("content-type")) {
metadata.put("Content-Type", "text/plain");
}
String xml = builder.asString(null);
return performRestPost(bucketName, objectKey, metadata, requestParameters,
new StringEntity(xml, "text/plain", Constants.DEFAULT_ENCODING), false);
} catch (Exception e) {
if (e instanceof ServiceException) {
throw (ServiceException) e;
} else {
throw new ServiceException("Failed to POST request containing an XML document", e);
}
}
}
示例10: putAclImpl
import org.jets3t.service.Constants; //导入依赖的package包/类
protected void putAclImpl(String bucketName, String objectKey, AccessControlList acl,
String versionId) throws ServiceException
{
if (log.isDebugEnabled()) {
log.debug("Setting Access Control List for bucketName=" + bucketName + ", objectKey=" + objectKey);
}
Map<String, String> requestParameters = new HashMap<String, String>();
requestParameters.put("acl","");
if (versionId != null) {
requestParameters.put("versionId", versionId);
}
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("Content-Type", "text/plain");
try {
String aclAsXml = acl.toXml();
metadata.put("Content-Length", String.valueOf(aclAsXml.length()));
performRestPut(bucketName, objectKey, metadata, requestParameters,
new StringEntity(aclAsXml, "text/plain", Constants.DEFAULT_ENCODING),
true);
} catch (UnsupportedEncodingException e) {
throw new ServiceException("Unable to encode ACL XML document", e);
}
}
示例11: putObjectAclWithSignedUrl
import org.jets3t.service.Constants; //导入依赖的package包/类
/**
* Sets an object's ACL details using a pre-signed PUT URL generated for that object.
* This method is an implementation of the interface {@link org.jets3t.service.utils.signedurl.SignedUrlHandler}.
*
* @param signedAclUrl
* a signed URL generated with {@link org.jets3t.service.S3Service#createSignedUrl(String, String, String, String, java.util.Map, org.jets3t.service.security.ProviderCredentials, long, boolean)}.
* @param acl
* the ACL settings to apply to the object represented by the signed URL.
*
* @throws org.jets3t.service.ServiceException
*/
public void putObjectAclWithSignedUrl(String signedAclUrl, AccessControlList acl) throws ServiceException {
HttpPut putMethod = new HttpPut(signedAclUrl);
if (acl != null) {
String restHeaderAclValue = acl.getValueForRESTHeaderACL();
if (restHeaderAclValue != null) {
putMethod.addHeader(this.getRestHeaderPrefix() + "acl", restHeaderAclValue);
} else {
try {
String aclAsXml = acl.toXml();
putMethod.setEntity(new StringEntity(
aclAsXml, "text/xml", Constants.DEFAULT_ENCODING));
} catch (UnsupportedEncodingException e) {
throw new ServiceException("Unable to encode ACL XML document", e);
}
}
}
HttpResponse httpResponse = performRequest(putMethod, new int[] {200});
// Consume response data and release connection.
releaseConnection(httpResponse);
}
示例12: parseXmlInputStream
import org.jets3t.service.Constants; //导入依赖的package包/类
/**
* Parses an XML document from an input stream using a document handler.
* @param handler
* the handler for the XML document
* @param inputStream
* an input stream containing the XML document to parse
* @throws S3ServiceException
* any parsing, IO or other exceptions are wrapped in an S3ServiceException.
*/
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream)
throws CloudFrontServiceException
{
try {
if (log.isDebugEnabled()) {
log.debug("Parsing XML response document with handler: " + handler.getClass());
}
BufferedReader breader = new BufferedReader(new InputStreamReader(inputStream,
Constants.DEFAULT_ENCODING));
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
xr.parse(new InputSource(breader));
} catch (Throwable t) {
try {
inputStream.close();
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("Unable to close response InputStream up after XML parse failure", e);
}
}
throw new CloudFrontServiceException("Failed to parse XML document with handler "
+ handler.getClass(), t);
}
}
示例13: parseXmlInputStream
import org.jets3t.service.Constants; //导入依赖的package包/类
/**
* Parses an XML document from an input stream using a document handler.
* @param handler
* the handler for the XML document
* @param inputStream
* an input stream containing the XML document to parse
* @throws ServiceException
* any parsing, IO or other exceptions are wrapped in an ServiceException.
*/
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream)
throws ServiceException
{
try {
if (log.isDebugEnabled()) {
log.debug("Parsing XML response document with handler: " + handler.getClass());
}
BufferedReader breader = new BufferedReader(
new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
xr.parse(new InputSource(breader));
inputStream.close();
} catch (Throwable t) {
try {
inputStream.close();
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("Unable to close response InputStream up after XML parse failure", e);
}
}
throw new ServiceException("Failed to parse XML document with handler "
+ handler.getClass(), t);
}
}
示例14: getRestS3Service
import org.jets3t.service.Constants; //导入依赖的package包/类
protected RestS3Service getRestS3Service(ProviderCredentials credentials)
throws S3ServiceException
{
if (!this.isTargetS3) {
// Override endpoint property in JetS3t properties
originalTargetEndpoint = cockpitProperties.getStringProperty(
"s3service.s3-endpoint", Constants.S3_DEFAULT_HOSTNAME);
cockpitProperties.setProperty(
"s3service.s3-endpoint", Constants.GS_DEFAULT_HOSTNAME);
} else if (originalTargetEndpoint != null) {
cockpitProperties.setProperty(
"s3service.s3-endpoint", originalTargetEndpoint);
}
return new RestS3Service(credentials, APPLICATION_DESCRIPTION,
this, cockpitProperties);
}
示例15: main
import org.jets3t.service.Constants; //导入依赖的package包/类
/**
* Creates stand-alone dialog box for testing only.
*
* @param args
* @throws Exception
*/
public static void main(String args[]) throws Exception {
JFrame f = new JFrame();
HyperlinkActivatedListener listener = new HyperlinkActivatedListener() {
private static final long serialVersionUID = -225585129296632961L;
public void followHyperlink(URL url, String target) {
BareBonesBrowserLaunch.openURL(url.toString());
}
};
StartupDialog startupDialog = new StartupDialog(f,
Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME), listener);
startupDialog.setVisible(true);
ProviderCredentials credentials = startupDialog.getProviderCredentials();
startupDialog.dispose();
if (credentials != null) {
System.out.println("Credentials: " + credentials.getLogString());
} else {
System.out.println("Credentials: null");
}
f.dispose();
}