Spring Web Services (Spring-WS) হলো Spring Framework এর একটি প্রজেক্ট, যা SOAP (Simple Object Access Protocol) ওয়েব সার্ভিস তৈরি এবং ব্যবহার করতে ব্যবহৃত হয়। এটি SOAP-ভিত্তিক ওয়েব সার্ভিসগুলোর জন্য একটি লাইটওয়েট এবং নমনীয় সমাধান প্রদান করে। Spring-WS মূলত ওয়েব সার্ভিসের বার্তা-পদক্ষেপ (message-driven) প্রক্রিয়ার উপর গুরুত্ব দেয় এবং এটি বেশ কয়েকটি প্রোটোকল এবং স্ট্যান্ডার্ড সমর্থন করে যেমন WS-Security, WS-Addressing ইত্যাদি।
Spring Web Services (Spring-WS) হলো Spring Framework এর একটি অংশ, যা SOAP ভিত্তিক Web Services তৈরি এবং ব্যবহারের জন্য ব্যবহৃত হয়। এটি মূলত SOAP (Simple Object Access Protocol) ভিত্তিক ওয়েব সার্ভিসগুলোকে সহজে ডেভেলপ এবং কনজিউম করার জন্য বিশেষভাবে ডিজাইন করা হয়েছে। Spring Web Services SOAP এর সাথে কাজ করার জন্য Spring এর শক্তিশালী বৈশিষ্ট্য এবং স্ট্রাকচার ব্যবহার করে এবং এটি WSDL (Web Services Description Language) এবং XML Schema সমর্থন করে।
Spring Web Services ডেভেলপারদের জন্য একটি শক্তিশালী প্ল্যাটফর্ম প্রদান করে SOAP ভিত্তিক ওয়েব সার্ভিসগুলোকে তৈরির জন্য এবং এর সাহায্যে আপনি সহজেই SOAP মেসেজ তৈরি, প্রক্রিয়াকরণ এবং কনজিউম করতে পারবেন। এটি REST এর মতো স্টাইল ব্যবহার না করে SOAP ভিত্তিক ওয়েব সার্ভিসের জন্য ডিজাইন করা হয়েছে।
ধাপ ১: Maven ডিপেন্ডেন্সি যোগ করা
Spring Web Services ব্যবহার করার জন্য আপনাকে Maven এর মাধ্যমে ডিপেন্ডেন্সি যোগ করতে হবে। নিচের ডিপেন্ডেন্সিগুলো pom.xml ফাইলে যোগ করুন:
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
ধাপ ২: WSDL এবং XSD তৈরি করা
Spring Web Services এ Contract First Development পদ্ধতি অনুসরণ করা হয়, যেখানে প্রথমে WSDL এবং XSD তৈরি করা হয়। উদাহরণস্বরূপ, একটি সাধারণ XSD ফাইল তৈরি করা যাক:
<!-- resources/schemas/countries.xsd -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/countries" targetNamespace="http://example.com/countries" elementFormDefault="qualified">
<xs:element name="getCountryRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getCountryResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="country" type="country" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="country">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="population" type="xs:int" />
<xs:element name="capital" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
ধাপ ৩: Spring-WS কনফিগারেশন তৈরি করা
Spring Web Services এ Spring Boot দিয়ে SOAP সার্ভিস তৈরি করা খুবই সহজ। প্রথমে একটি কনফিগারেশন ক্লাস তৈরি করতে হবে, যেখানে আপনি SOAP সার্ভিস কনফিগার করবেন:
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.xml.validation.XmlValidator;
@Configuration
public class WebServiceConfig {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext context) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(context);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}
@Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("schemas/countries.xsd"));
}
}
ধাপ ৪: SOAP Web Service Endpoint তৈরি করা
এখন একটি Endpoint তৈরি করতে হবে, যা SOAP রিকোয়েস্ট গ্রহণ করবে এবং রেসপন্স পাঠাবে। Spring-WS এর জন্য একটি @Endpoint অ্যানোটেশন ব্যবহার করা হয়:
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
@Endpoint
public class CountryEndpoint {
private static final String NAMESPACE_URI = "http://example.com/countries";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
GetCountryResponse response = new GetCountryResponse();
Country country = new Country();
country.setName(request.getName());
country.setCapital("Example Capital");
country.setPopulation(123456);
response.setCountry(country);
return response;
}
}
এই কোডে, getCountry() মেথডটি SOAP রিকোয়েস্ট গ্রহণ করছে এবং একটি GetCountryResponse অবজেক্ট রিটার্ন করছে, যা XML ফরম্যাটে রেসপন্স হিসেবে পাঠানো হবে।
ধাপ ৫: WSDL প্রকাশ করা
Spring Web Services আপনাকে WSDL ফাইল তৈরি এবং প্রকাশ করার সুযোগ দেয়। কনফিগারেশন ক্লাসে WSDL তৈরি এবং প্রকাশ করতে নিচের কোডটি যোগ করতে হবে:
@Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
definition.setPortTypeName("CountriesPort");
definition.setLocationUri("/ws");
definition.setTargetNamespace("http://example.com/countries");
definition.setSchema(countriesSchema);
return definition;
}
এখন আপনি WSDL ফাইলটি এই URL থেকে দেখতে পারবেন: http://localhost:8080/ws/countries.wsdl
ধাপ ৬: SOAP Client তৈরি করা
Spring Web Services দিয়ে আপনি শুধু সার্ভার নয়, ক্লায়েন্ট সার্ভিসও তৈরি করতে পারেন। একটি সাধারণ SOAP Client তৈরি করার উদাহরণ:
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;
public class CountryClient extends WebServiceGatewaySupport {
public GetCountryResponse getCountry(String name) {
GetCountryRequest request = new GetCountryRequest();
request.setName(name);
GetCountryResponse response = (GetCountryResponse) getWebServiceTemplate()
.marshalSendAndReceive("http://localhost:8080/ws", request,
new SoapActionCallback("http://example.com/countries/GetCountryRequest"));
return response;
}
}
Spring Web Services (Spring-WS) হলো একটি শক্তিশালী এবং স্থিতিশীল SOAP ভিত্তিক ওয়েব সার্ভিস ফ্রেমওয়ার্ক, যা Spring Framework এর উপর ভিত্তি করে তৈরি। এটি Contract First Development, WS-Security, এবং XML Schema Validation সমর্থন করে। SOAP ভিত্তিক ওয়েব সার্ভিস তৈরি এবং ব্যবহারের জন্য Spring-WS একটি শক্তিশালী এবং কার্যকর সমাধান, বিশেষ করে যখন নিরাপত্তা এবং ডেটা ইন্টিগ্রিটির প্রয়োজনীয়তা থাকে।
Spring Web Services (Spring-WS) হলো Spring Framework এর একটি প্রজেক্ট, যা SOAP (Simple Object Access Protocol) ওয়েব সার্ভিস তৈরি এবং ব্যবহার করতে ব্যবহৃত হয়। এটি SOAP-ভিত্তিক ওয়েব সার্ভিসগুলোর জন্য একটি লাইটওয়েট এবং নমনীয় সমাধান প্রদান করে। Spring-WS মূলত ওয়েব সার্ভিসের বার্তা-পদক্ষেপ (message-driven) প্রক্রিয়ার উপর গুরুত্ব দেয় এবং এটি বেশ কয়েকটি প্রোটোকল এবং স্ট্যান্ডার্ড সমর্থন করে যেমন WS-Security, WS-Addressing ইত্যাদি।
Spring Web Services (Spring-WS) হলো Spring Framework এর একটি অংশ, যা SOAP ভিত্তিক Web Services তৈরি এবং ব্যবহারের জন্য ব্যবহৃত হয়। এটি মূলত SOAP (Simple Object Access Protocol) ভিত্তিক ওয়েব সার্ভিসগুলোকে সহজে ডেভেলপ এবং কনজিউম করার জন্য বিশেষভাবে ডিজাইন করা হয়েছে। Spring Web Services SOAP এর সাথে কাজ করার জন্য Spring এর শক্তিশালী বৈশিষ্ট্য এবং স্ট্রাকচার ব্যবহার করে এবং এটি WSDL (Web Services Description Language) এবং XML Schema সমর্থন করে।
Spring Web Services ডেভেলপারদের জন্য একটি শক্তিশালী প্ল্যাটফর্ম প্রদান করে SOAP ভিত্তিক ওয়েব সার্ভিসগুলোকে তৈরির জন্য এবং এর সাহায্যে আপনি সহজেই SOAP মেসেজ তৈরি, প্রক্রিয়াকরণ এবং কনজিউম করতে পারবেন। এটি REST এর মতো স্টাইল ব্যবহার না করে SOAP ভিত্তিক ওয়েব সার্ভিসের জন্য ডিজাইন করা হয়েছে।
ধাপ ১: Maven ডিপেন্ডেন্সি যোগ করা
Spring Web Services ব্যবহার করার জন্য আপনাকে Maven এর মাধ্যমে ডিপেন্ডেন্সি যোগ করতে হবে। নিচের ডিপেন্ডেন্সিগুলো pom.xml ফাইলে যোগ করুন:
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
ধাপ ২: WSDL এবং XSD তৈরি করা
Spring Web Services এ Contract First Development পদ্ধতি অনুসরণ করা হয়, যেখানে প্রথমে WSDL এবং XSD তৈরি করা হয়। উদাহরণস্বরূপ, একটি সাধারণ XSD ফাইল তৈরি করা যাক:
<!-- resources/schemas/countries.xsd -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/countries" targetNamespace="http://example.com/countries" elementFormDefault="qualified">
<xs:element name="getCountryRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getCountryResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="country" type="country" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="country">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="population" type="xs:int" />
<xs:element name="capital" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
ধাপ ৩: Spring-WS কনফিগারেশন তৈরি করা
Spring Web Services এ Spring Boot দিয়ে SOAP সার্ভিস তৈরি করা খুবই সহজ। প্রথমে একটি কনফিগারেশন ক্লাস তৈরি করতে হবে, যেখানে আপনি SOAP সার্ভিস কনফিগার করবেন:
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.xml.validation.XmlValidator;
@Configuration
public class WebServiceConfig {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext context) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(context);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}
@Bean
public XsdSchema countriesSchema() {
return new SimpleXsdSchema(new ClassPathResource("schemas/countries.xsd"));
}
}
ধাপ ৪: SOAP Web Service Endpoint তৈরি করা
এখন একটি Endpoint তৈরি করতে হবে, যা SOAP রিকোয়েস্ট গ্রহণ করবে এবং রেসপন্স পাঠাবে। Spring-WS এর জন্য একটি @Endpoint অ্যানোটেশন ব্যবহার করা হয়:
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
@Endpoint
public class CountryEndpoint {
private static final String NAMESPACE_URI = "http://example.com/countries";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
GetCountryResponse response = new GetCountryResponse();
Country country = new Country();
country.setName(request.getName());
country.setCapital("Example Capital");
country.setPopulation(123456);
response.setCountry(country);
return response;
}
}
এই কোডে, getCountry() মেথডটি SOAP রিকোয়েস্ট গ্রহণ করছে এবং একটি GetCountryResponse অবজেক্ট রিটার্ন করছে, যা XML ফরম্যাটে রেসপন্স হিসেবে পাঠানো হবে।
ধাপ ৫: WSDL প্রকাশ করা
Spring Web Services আপনাকে WSDL ফাইল তৈরি এবং প্রকাশ করার সুযোগ দেয়। কনফিগারেশন ক্লাসে WSDL তৈরি এবং প্রকাশ করতে নিচের কোডটি যোগ করতে হবে:
@Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
definition.setPortTypeName("CountriesPort");
definition.setLocationUri("/ws");
definition.setTargetNamespace("http://example.com/countries");
definition.setSchema(countriesSchema);
return definition;
}
এখন আপনি WSDL ফাইলটি এই URL থেকে দেখতে পারবেন: http://localhost:8080/ws/countries.wsdl
ধাপ ৬: SOAP Client তৈরি করা
Spring Web Services দিয়ে আপনি শুধু সার্ভার নয়, ক্লায়েন্ট সার্ভিসও তৈরি করতে পারেন। একটি সাধারণ SOAP Client তৈরি করার উদাহরণ:
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;
public class CountryClient extends WebServiceGatewaySupport {
public GetCountryResponse getCountry(String name) {
GetCountryRequest request = new GetCountryRequest();
request.setName(name);
GetCountryResponse response = (GetCountryResponse) getWebServiceTemplate()
.marshalSendAndReceive("http://localhost:8080/ws", request,
new SoapActionCallback("http://example.com/countries/GetCountryRequest"));
return response;
}
}
Spring Web Services (Spring-WS) হলো একটি শক্তিশালী এবং স্থিতিশীল SOAP ভিত্তিক ওয়েব সার্ভিস ফ্রেমওয়ার্ক, যা Spring Framework এর উপর ভিত্তি করে তৈরি। এটি Contract First Development, WS-Security, এবং XML Schema Validation সমর্থন করে। SOAP ভিত্তিক ওয়েব সার্ভিস তৈরি এবং ব্যবহারের জন্য Spring-WS একটি শক্তিশালী এবং কার্যকর সমাধান, বিশেষ করে যখন নিরাপত্তা এবং ডেটা ইন্টিগ্রিটির প্রয়োজনীয়তা থাকে।
আপনি আমাকে যেকোনো প্রশ্ন করতে পারেন, যেমনঃ
Are you sure to start over?