311.6. 예
311.6.1. WebService 클라이언트 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
다음 경로는 요청을 마샬링하고 응답 또는 오류를 분리할 수 있도록 지원합니다.
String WS_URI = "cxf://http://myserver/customerservice?serviceClass=com.example.customerservice&dataFormat=MESSAGE";
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:customerServiceClient")
.onException(Exception.class)
.handled(true)
.unmarshal(soapDF)
.end()
.marshal(soapDF)
.to(WS_URI)
.unmarshal(soapDF);
아래 스니펫에서는 서비스 인터페이스에 대한 프록시를 생성하고 위의 경로를 호출합니다.
import org.apache.camel.Endpoint;
import org.apache.camel.component.bean.ProxyHelper;
...
Endpoint startEndpoint = context.getEndpoint("direct:customerServiceClient");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// CustomerService below is the service endpoint interface, *not* the javax.xml.ws.Service subclass
CustomerService proxy = ProxyHelper.createProxy(startEndpoint, classLoader, CustomerService.class);
GetCustomersByNameResponse response = proxy.getCustomersByName(new GetCustomersByName());
311.6.2. WebService 서버 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
다음 경로를 사용하면 jms 대기열 customerServiceQueue에서 수신하고 CustomerServiceImpl 클래스를 사용하여 요청을 처리하는 webservice 서버를 설정합니다. 물론 customerServiceImpl은 CustomerService 인터페이스를 구현해야 합니다. 서버 클래스를 직접 인스턴스화하는 대신 Spring 컨텍스트에서 일반Bean으로 정의할 수 있습니다.
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
CustomerService serverBean = new CustomerServiceImpl();
from("jms://queue:customerServiceQueue")
.onException(Exception.class)
.handled(true)
.marshal(soapDF)
.end()
.unmarshal(soapDF)
.bean(serverBean)
.marshal(soapDF);