Skip to content

Instantly share code, notes, and snippets.

@hinunbi
Last active August 29, 2015 14:09
Show Gist options
  • Save hinunbi/5c31175180be3982294f to your computer and use it in GitHub Desktop.
Save hinunbi/5c31175180be3982294f to your computer and use it in GitHub Desktop.
마이크로 SOAP 웹 서비스 클라이언트
마이크로 SOAP 웹 서비스 클라이언트 인용
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<!-- 웹 서비스와 웹 URL 지정 -->
<cxf:cxfEndpoint id="PaymentServiceEndpoint"
serviceClass="com.brm.ws.payment.PaymentPortType"
address="http://localhost:9090/paymentService">
</cxf:cxfEndpoint>
<bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
<!-- 카멜 라우팅 정의 -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- 카멜 오루 처리 로직 무시 -->
<route errorHandlerRef="noErrorHandler">
<!-- 이체 웹 서비스 동기 호출 엔드포인트 -->
<from uri="direct:payment" />
<!-- 이체 웹 서비스 인터페이스 엔드포인트 -->
<to uri="cxf:bean:PaymentServiceEndpoint?defaultOperationName=transferFunds" />
</route>
</camelContext>
</beans>
prompt> mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-spring -DarchetypeVersion=2.13.2 -DarchetypeRepository=https://repository.apache.org/content/groups/public
...
Define value for property 'groupId': : com.brm
Define value for property 'artifactId': : mwsc-example
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': com.brm: : com.brm.ws
[main] SpringCamelContext INFO Apache Camel 2.13.2 (CamelContext: camel-1) is starting
[main] ManagedManagementStrategy INFO JMX is enabled
[main] DefaultTypeConverter INFO Loaded 193 type converters
[main] SpringCamelContext INFO AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
[main] SpringCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[main] ReflectionServiceFactoryBean INFO Creating Service {http://payment.ws.brm.com/}PaymentPortTypeService from class com.brm.ws.payment.PaymentPortType
[main] SpringCamelContext INFO Route: route1 started and consuming from: Endpoint[direct://payment]
[main] SpringCamelContext INFO Total 1 routes, of which 1 is started.
[main] SpringCamelContext INFO Apache Camel 2.13.2 (CamelContext: camel-1) started in 0.900 seconds
Calling Web Service... : com.brm.ws.payment.TransferRequest@2ec8f0a4[amount=1000000,bank=Bank of Camel,from=Jakub,to=Scott]
Response from Web Service : com.brm.ws.payment.TransferResponse@332b9f79[reply=OK]
Calling Web Service... : com.brm.ws.payment.TransferRequest@32a6faa9[amount=10000000,bank=Bank of Camel,from=Jakub,to=Scott]
SOAP fault : 이체 한도 금액 초과: 이체 요청 금액(10000000)
[Thread-1] SpringCamelContext INFO Apache Camel 2.13.2 (CamelContext: camel-1) is shutting down
[Thread-1] DefaultShutdownStrategy INFO Starting to graceful shutdown 1 routes (timeout 300 seconds)
[el-1) thread #0 - ShutdownTask] DefaultShutdownStrategy INFO Route: route1 shutdown complete, was consuming from: Endpoint[direct://payment]
[Thread-1] DefaultShutdownStrategy INFO Graceful shutdown of 1 routes completed in 0 seconds
[Thread-1] SpringCamelContext INFO Apache Camel 2.13.2 (CamelContext: camel-1) uptime 1.259 seconds
[Thread-1] SpringCamelContext INFO Apache Camel 2.13.2 (CamelContext: camel-1) is shutdown in 0.010 seconds
prompt> mvn test
...
<!-- mwsc-example -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
package com.brm.ws.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.brm.ws.payment.Fault;
import com.brm.ws.payment.TransferException;
import com.brm.ws.payment.TransferException_Exception;
import com.brm.ws.payment.TransferRequest;
import com.brm.ws.payment.TransferResponse;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/camel-context.xml" })
public class WsClientTest {
@Produce(uri = "direct:payment")
ProducerTemplate wsClient;
@Test
public void testSmallAmount() {
TransferRequest request = new TransferRequest();
request.setBank("Bank of Camel");
request.setFrom("Jakub");
request.setTo("Scott");
request.setAmount(1000000); // 이체 가능 금액
System.err.println("Calling Web Service... : " + ReflectionToStringBuilder.toString(request));
try {
TransferResponse response = wsClient.requestBody(request, TransferResponse.class);
assertNotNull(response);
assertEquals("OK", response.getReply());
System.err.println("Response from Web Service : " + ReflectionToStringBuilder.toString(response));
} catch (CamelExecutionException e) {
e.printStackTrace();
}
}
@Test
public void testLargeAmount() {
TransferRequest request = new TransferRequest();
request.setBank("Bank of Camel");
request.setFrom("Jakub");
request.setTo("Scott");
request.setAmount(10000000); // 이체 불가능 금액
System.err.println("Calling Web Service... : " + ReflectionToStringBuilder.toString(request));
try {
TransferResponse response = wsClient.requestBody(request, TransferResponse.class);
} catch (CamelExecutionException e) {
TransferException_Exception cause = (TransferException_Exception) e.getCause();
TransferException transferException = cause.getFaultInfo();
Fault fault = transferException.getFault();
System.err.println("Fault from Web Service : " + fault.getReason());
}
}
}
prompt> wsdl2java -verbose -encoding utf-8 http://localhost:9090/paymentService?wsdl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment