24 Eylül 2021 Cuma

SpringWebServices WebServiceGatewaySupport Sınıfı

Giriş
Şu satırı dahil ederiz
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
Maven
Şu satırı dahil ederiz
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
Açıklaması şöyleWebServiceTemplate yazısına bakabilirsiniz
This is the central class for client-side Web services. It provides a message-driven approach to sending and receiving Spring WebServiceMessage instances.
getWebServiceTemplate metodu
Örnek
Şöyle yaparız
public class ArticleClient extends WebServiceGatewaySupport {

  public GetArticleResponse getArticle(int id){
    GetArticleRequest getArticleRequest = new GetArticleRequest();
    getArticleRequest.setId(id);
    return (GetArticleResponse) getWebServiceTemplate()
.marshalSendAndReceive(getArticleRequest);
  }
}
setDefaultUri metodu
Şöyle yaparız
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class SoapClientConfig {

  @Bean
  public Jaxb2Marshaller marshaller(){
    Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
    jaxb2Marshaller.setContextPath("com.medium.article");
    return jaxb2Marshaller;
  }

  @Bean
  public ArticleClient articleClient(Jaxb2Marshaller jaxb2Marshaller) {
    ArticleClient articleClient = new ArticleClient();
    articleClient.setDefaultUri("http://localhost:8080/ws/article");
    articleClient.setMarshaller(jaxb2Marshaller);
    articleClient.setUnmarshaller(jaxb2Marshaller);
    return articleClient;
  }
}

Hiç yorum yok:

Yorum Gönder