Mar 30, 2012 - Amazon 3S Upload 시에 443 이 아니라 80 port로 Upload 하는 방법

참고주소 : http://www.cozyroc.com/ssis/amazon-s3-connection

1. Host
Specify the name or IP address of the Amazon S3 service.
2. Secure connection
Specify to establish secure HTTPS connection with Amazon S3 service on port 443.
3. Regular calling
Specify to connect to Amazon S3 service, using regular calling format. Un-check this option when connecting to EU Amazon S3 service.
4. Access Key
Specify access key for Amazon S3 service.
5. Secret Key
Specify secret key for Amazon S3 service.
6. Time-out (secs)
Specify the number of seconds before timing out session connect. The default value of this property is 100.
7. Test Connection
Confirm connection manager configuration by clicking Test Connection.  

Amazon 3S Upload 시에 443 이 아니라 80 port로 Upload 하는 방법

S3 Upload : org.jets3t.service.impl.rest.httpclient.RestStorageService Class

Amazon S3 Upload 시에 setupConnection 에서 ‘isHttpsOnly()’ 에 값을 가져와, https 로 셋팅할 것인지 http 로 셋팅할것인지를 결정합니다.

protected HttpMethodBase setupConnection(HTTP_METHOD method, String bucketName, String objectKey, Map<String, String> requestParameters) throws ServiceException

isHttpsOnly() 라는 메소드는 org.jets3t.service.StorageService Class 에서 가져옵니다.

private boolean isHttpsOnly = true;

문제는 이 변수가 항상 true로 되어있습니다. 그래서 항상 SSL 방식으로 업로드가 되게 됩니다.

그런데 특정 서버의 경우 443 port 가 막혀 80 port 로만 업로드해야할 경우가 있습니다. 그로인해 isHttpOnly 를 false 로 바꿔주어야합니다.

org.jets3t.service.StorageService Class 에 setMethod를 추가합니다.

public void setHttpsOnly(boolean isHttpsOnly){ this.isHttpsOnly = isHttpsOnly; }

해당 메소드를 그럼 자동으로 파일업로드시 org.jets3t.service.impl.rest.httpclient.RestStorageService 에서 http, https 설정하는 setupConnection method() 에서 자동으로 http 를 셋팅합니다.

사용방법은

org.jets3t.service.S3Service s3Service = new RestS3Service(awsCredentials);
s3Service.setHttpsOnly(isHttpsOnly);
S3Bucket bucket = s3Service.getBucket(bucketName);

S3Service 에서 부모에 있는 setHttpsOnly 메소드를 호출하여 false 로 변경해주면 됩니다.

Feb 7, 2012 - value.replace('x','z') -> value.replaceAll('x','z');

value.replace(“x”,”z”); : value 안에서 x라는 값을 z로 변경. 처음 z 가 나오는 한 부분만 바뀌므로 replaceAll 명령이 필요합니다. 그러나 자바스크립트에는 replaceAll 이라는 명령어가 존재하지 않으므로 정규식을 사용하여야합니다. 간단하게 “” 와 ‘‘를 //로 바꿔서 사용하고 뒤에 정규식을 붙이면 됩니다.

g : 모든 문자에 대하여 적용한다.
i : 대소문자를 가리지 않는다.
\s : 공백을 의미한다.
\ : 특수문자를 사용할때 사용한다. ex) \" , \' , \[ , \/
| : or 조건을 의미한다.
(.*?) : 두 문자열사이의 모든 문자를 의미한다. ex) a(.*?)b : a와b 사이의 모든 문자.

value.replace(/x/gi, “z”); 해석은 x라는 단어를 대소문자 구분없이 모두 z로 바꾸라는 정규식명령이 되므로, 실질적으로 value.replaceAll(‘x’, ‘z’); 라는 명령이 됩니다.

더 자세한 정규식 표현은 http://kio.zc.bz/Lecture/regexp.html 에서 확인하시기 바랍니다.