Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- cognito
- elasticsearch
- vgw
- 구조분해 할당
- Await
- 단축 평가
- 온프레미스
- 옵셔널 체이닝
- 비구조화 할당
- prometheus
- 자바스크립트
- Kubernetes
- docker
- Custom Resource
- optional chaining
- null 병합 연산자
- docker swarm
- transit gateway
- Service
- api gateway
- AWS
- Proxy Resource
- CloudFormation
- Site-to-Site VPN
- VPC
- DynamoDB
- On-Premise
- grafana
- JavaScript
- Endpoints
Archives
- Today
- Total
만자의 개발일지
[Java] SOAP API 사용하기 (feat.Maven) 본문
Java로 SOAP API를 사용할 일이 생겨서 간단하게 정리해보고자 한다.
준비물은 Maven(pom.xml) 과 javax.xml.soap 패키지 이다.
의존성 추가
우선 아래 사이트로 접속해준다.
https://mvnrepository.com/artifact/javax.xml.soap
그 다음 맨 위에 있는 Javax XML SOAP API 클릭
그러면 여러가지 버전과 옆에 Usages라고 노란줄로 표시되있는게 나오는데 Usages는 각 버전에 대한 사용빈도수를 의미하고 필자는 가장 많이 사용된 1.4.0을 사용할 것이다.
Maven을 사용할 것이니 Maven을 클릭하고 아래에 나와있는 코드를 pom.xml 안에다 복붙해준다.
사이트 이름은 mvnrepository인데 Gradle까지 지원해준다 ㄷㄷ..
여기서 주의할 점은 dependency 태그는 dependencies안에 존재해야한다.
<dependencies>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
SOAP 사용
// SOAP requestMessage example
String inputSource =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<soap12:Envelope> " +
" <soap12:Body>" +
" ... " +
" ... " +
" ... " +
" <soap12:Body>" +
"</soap12:Envelope> ";
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
DOMSource requestSource = new DOMSource(documentBuilder.parse(new InputSource(new StringReader(inputSource))));
//프로토콜 버전은 자신이 사용하는 버전에 맞추기 SOAP 1.1의 경우 SOAPConstants.SOAP_1_1PROTOCOL
SOAPMessage requestSOAPMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
SOAPPart requestSOAPPart = requestSOAPMessage.getSOAPPart();
requestSOAPPart.setContent(requestSource);
SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
// URL은 요청을 보낼 URL
SOAPMessage responseSOAPMessage = connection.call(requestSOAPMessage, URL);
ByteArrayOutputStream out = new ByteArrayOutputStream();
responseSOAPMessage.writeTo(out);
soapResult = new String(out.toByteArray(), "UTF-8");
참고
'Java > Java' 카테고리의 다른 글
[Java] Annotation 이란 (0) | 2022.01.18 |
---|---|
[Java] ArrayList 상속으로 foreach 구현 (0) | 2022.01.17 |
[Java] DocumentBuilderFactory 와 DocumentBuilder (1) | 2022.01.14 |
[Java] new 연산자란 (0) | 2021.06.21 |
[Java] 리터럴(literal)이란? (0) | 2021.06.18 |
Comments