Spring Web Services সেটআপ এবং কনফিগারেশন

স্প্রিং ওয়েব সার্ভিসেস (Spring Web Services) - Java Technologies

260

স্প্রিং ওয়েব সার্ভিসেস (Spring Web Services) সেটআপ এবং কনফিগারেশন একটি গুরুত্বপূর্ণ ধাপ, যা SOAP বা RESTful ওয়েব সার্ভিস তৈরি ও পরিচালনা সহজ করে। নিচে স্প্রিং ওয়েব সার্ভিস সেটআপ এবং কনফিগারেশন করার প্রক্রিয়া বিস্তারিতভাবে বর্ণনা করা হলো।


প্রয়োজনীয় ডিপেন্ডেন্সি সংযোজন

Spring Web Services ব্যবহার করার জন্য প্রথমে প্রকল্পে প্রয়োজনীয় ডিপেন্ডেন্সি যোগ করতে হবে। Maven বা Gradle-এ ডিপেন্ডেন্সি যুক্ত করার পদ্ধতি নিচে দেখানো হলো।

Maven ডিপেন্ডেন্সি

<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-core</artifactId>
    <version>2.4.0</version>
</dependency>

Gradle ডিপেন্ডেন্সি

implementation 'org.springframework.ws:spring-ws-core:2.4.0'

প্রজেক্ট স্ট্রাকচার

Spring Web Services প্রজেক্টের জন্য একটি আদর্শ স্ট্রাকচার তৈরি করা হয়, যাতে নিচের ফোল্ডারগুলো থাকে:

  • src/main/java: এন্ডপয়েন্ট এবং কনফিগারেশন ফাইল।
  • src/main/resources: WSDL এবং XML স্কিমা ফাইল।
  • src/main/webapp: ওয়েব অ্যাপ্লিকেশনের জন্য প্রয়োজনীয় ফাইল।

XML স্কিমা তৈরি

XML স্কিমা (XSD ফাইল) ওয়েব সার্ভিসে ডেটার কাঠামো নির্ধারণ করে। উদাহরণস্বরূপ, একটি উদাহরণ স্কিমা ফাইল নিচে দেখানো হলো:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/ws" targetNamespace="http://example.com/ws" elementFormDefault="qualified">
    <xs:element name="GetExampleRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="id" type="xs:int" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="GetExampleResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="message" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

WSDL ফাইল তৈরি

SOAP ওয়েব সার্ভিসের জন্য একটি WSDL ফাইল প্রয়োজন। WSDL ফাইলটি সার্ভিসের এন্ডপয়েন্ট, অপারেশন, এবং ডেটা টাইপ নির্দেশ করে।


Spring Boot অ্যাপ্লিকেশন সেটআপ

Spring Boot ব্যবহার করে Spring Web Services সহজে সেটআপ করা যায়। Spring Initializr থেকে প্রজেক্ট তৈরি করুন এবং SOAP Web Services ডিপেন্ডেন্সি যোগ করুন।

Main Application ক্লাস

@SpringBootApplication
public class SpringWsApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringWsApplication.class, args);
    }
}

এন্ডপয়েন্ট তৈরি

Spring Web Services এ এন্ডপয়েন্ট তৈরি করতে @Endpoint এবং @PayloadRoot annotations ব্যবহার করা হয়। উদাহরণ:

@Endpoint
public class ExampleEndpoint {

    @PayloadRoot(namespace = "http://example.com/ws", localPart = "GetExampleRequest")
    @ResponsePayload
    public GetExampleResponse handleExampleRequest(@RequestPayload GetExampleRequest request) {
        GetExampleResponse response = new GetExampleResponse();
        response.setMessage("Hello, ID: " + request.getId());
        return response;
    }
}

SOAP কনফিগারেশন

SOAP মেসেজ হ্যান্ডলিংয়ের জন্য SOAP কনফিগারেশন সেটআপ করতে হবে।

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<>(servlet, "/ws/*");
    }

    @Bean
    public XsdSchema exampleSchema() {
        return new SimpleXsdSchema(new ClassPathResource("example.xsd"));
    }

    @Bean
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema exampleSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("ExamplePort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://example.com/ws");
        wsdl11Definition.setSchema(exampleSchema);
        return wsdl11Definition;
    }
}

অ্যাপ্লিকেশন রান করা

সব সেটআপ এবং কনফিগারেশন সম্পন্ন হলে অ্যাপ্লিকেশন চালান এবং /ws এন্ডপয়েন্টে SOAP মেসেজ পাঠিয়ে সঠিক রেসপন্স পাওয়া যায় কিনা তা নিশ্চিত করুন।


সারাংশ

Spring Web Services সেটআপ এবং কনফিগারেশন একটি সুসংগঠিত প্রক্রিয়া, যা ডিপেন্ডেন্সি যোগ করা থেকে শুরু করে WSDL, XML স্কিমা, এবং SOAP কনফিগারেশন তৈরির মাধ্যমে সম্পন্ন হয়। সঠিকভাবে সেটআপ করা হলে, এটি একটি কার্যকর এবং নির্ভরযোগ্য ওয়েব সার্ভিস প্রদান করে।

Content added By

স্প্রিং ওয়েব সার্ভিস প্রজেক্ট তৈরি করার জন্য Maven বা Gradle টুল ব্যবহার করা হয়। এগুলো ডিপেন্ডেন্সি ম্যানেজমেন্ট এবং বিল্ড অটোমেশনের জন্য গুরুত্বপূর্ণ। এখানে বিস্তারিতভাবে Maven এবং Gradle দিয়ে Spring Web Services প্রজেক্ট তৈরির প্রক্রিয়া তুলে ধরা হলো।


Maven দিয়ে Spring Web Services প্রজেক্ট তৈরি

প্রজেক্ট সেটআপ

Maven প্রজেক্ট তৈরি করতে নিচের ধাপগুলো অনুসরণ করুন:

  1. Maven প্রজেক্ট তৈরি করুন
    Maven কমান্ড ব্যবহার করে একটি নতুন প্রজেক্ট তৈরি করুন:

    mvn archetype:generate -DgroupId=com.example -DartifactId=spring-webservice -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    

    এতে একটি বেসিক Maven প্রজেক্ট তৈরি হবে।

  2. Pom.xml ফাইল আপডেট করুন
    প্রজেক্টের pom.xml ফাইলে প্রয়োজনীয় ডিপেন্ডেন্সি যোগ করুন।

    Pom.xml উদাহরণ:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
    </dependencies>
    
  3. Build করুন
    Maven বিল্ড সিস্টেম চালিয়ে দেখুন প্রজেক্ট সঠিকভাবে কাজ করছে কিনা:

    mvn clean install
    

Gradle দিয়ে Spring Web Services প্রজেক্ট তৈরি

প্রজেক্ট সেটআপ

Gradle ব্যবহার করে প্রজেক্ট তৈরি করতে নিচের ধাপগুলো অনুসরণ করুন:

  1. Gradle প্রজেক্ট তৈরি করুন
    Gradle কমান্ড ব্যবহার করে একটি নতুন প্রজেক্ট তৈরি করুন:

    gradle init --type java-application
    

    এটি একটি বেসিক Gradle প্রজেক্ট সেটআপ করবে।

  2. build.gradle ফাইল আপডেট করুন
    Gradle এর build.gradle ফাইলে প্রয়োজনীয় ডিপেন্ডেন্সি যোগ করুন।

    build.gradle উদাহরণ:

    plugins {
        id 'org.springframework.boot' version '2.7.0'
        id 'io.spring.dependency-management' version '1.0.11.RELEASE'
        id 'java'
    }
    
    group = 'com.example'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '11'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web-services'
        implementation 'org.springframework.boot:spring-boot-starter'
        implementation 'javax.xml.bind:jaxb-api:2.3.1'
    }
    
    test {
        useJUnitPlatform()
    }
    
  3. Build করুন
    Gradle বিল্ড সিস্টেম চালিয়ে দেখুন প্রজেক্ট সঠিকভাবে কাজ করছে কিনা:

    gradle build
    

প্রজেক্ট চালু করা

প্রজেক্ট তৈরি ও ডিপেন্ডেন্সি যুক্ত করার পরে নিচের ধাপগুলো অনুসরণ করে Spring Web Services অ্যাপ্লিকেশন চালু করুন:

  1. Spring Boot অ্যাপ্লিকেশন ক্লাস তৈরি করুন
    একটি Application ক্লাস তৈরি করুন এবং @SpringBootApplication অ্যানোটেশন ব্যবহার করুন:

    @SpringBootApplication
    public class SpringWebServiceApplication {
        public static void main(String[] args) {
            SpringApplication.run(SpringWebServiceApplication.class, args);
        }
    }
    
  2. কনফিগারেশন এবং এন্ডপয়েন্ট যোগ করুন
    SOAP এন্ডপয়েন্ট এবং প্রয়োজনীয় কনফিগারেশন যোগ করুন।
  3. অ্যাপ্লিকেশন চালু করুন
    Maven ব্যবহার করলে:

    mvn spring-boot:run
    

    Gradle ব্যবহার করলে:

    gradle bootRun
    

Maven ও Gradle এর মধ্যে পার্থক্য

  • Maven XML ভিত্তিক বিল্ড টুল। এটি স্ট্যান্ডার্ড এবং ডকুমেন্টেশন সমৃদ্ধ।
  • Gradle Groovy বা Kotlin DSL ভিত্তিক এবং অত্যন্ত ফ্লেক্সিবল। এটি দ্রুত বিল্ড প্রসেস প্রদান করে।

সারাংশ:
Maven বা Gradle ব্যবহার করে Spring Web Services প্রজেক্ট তৈরি করা খুবই সহজ এবং সময়-সাশ্রয়ী। Maven ডকুমেন্টেশন ও স্ট্যান্ডার্ডাইজড স্ট্রাকচারের জন্য জনপ্রিয়, আর Gradle দ্রুত এবং কাস্টমাইজেবিলিটির জন্য আদর্শ।

Content added By

Spring Web Services প্রজেক্টে যোগ করার জন্য Maven বা Gradle ব্যবহার করা হয়। নিচে Maven এবং Gradle উভয়ের জন্য প্রয়োজনীয় ডিপেনডেন্সি উল্লেখ করা হলো।


Maven ডিপেনডেন্সি

<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-core</artifactId>
    <version>3.1.1</version> <!-- সর্বশেষ ভার্সনটি ব্যবহার করুন -->
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
    <version>3.1.1</version> <!-- স্প্রিং বুট প্রজেক্টের জন্য -->
</dependency>

Gradle ডিপেনডেন্সি

implementation 'org.springframework.ws:spring-ws-core:3.1.1' // SOAP সার্ভিসের জন্য
implementation 'org.springframework.boot:spring-boot-starter-web-services:3.1.1' // Spring Boot ইন্টিগ্রেশন

অন্যান্য প্রয়োজনীয় ডিপেনডেন্সি

JAXB (Java Architecture for XML Binding)

SOAP মেসেজ প্রসেসিংয়ের জন্য JAXB প্রয়োজন হতে পারে। নিচে JAXB-এর ডিপেনডেন্সি উল্লেখ করা হলো:

Maven:

<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>3.0.1</version>
</dependency>

Gradle:

implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.1'

Spring Security (প্রয়োজনীয় হলে)

SOAP সার্ভিস সিকিউর করার জন্য Spring Security এর ডিপেনডেন্সি যুক্ত করতে পারেন।

Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

Gradle:

implementation 'org.springframework.boot:spring-boot-starter-security'

ডিপেনডেন্সি ব্যবহারের জন্য সাধারণ নির্দেশনা

  • Maven ব্যবহার করলে, pom.xml ফাইলে ডিপেনডেন্সিগুলো যোগ করুন।
  • Gradle ব্যবহার করলে, build.gradle ফাইলে implementation হিসেবে ডিপেনডেন্সি উল্লেখ করুন।
  • সর্বশেষ ভার্সন ব্যবহারের জন্য Spring Framework এর অফিসিয়াল ডকুমেন্টেশন দেখুন।

ডিপেনডেন্সিগুলো সঠিকভাবে যোগ করার পর Spring Web Services ফ্রেমওয়ার্ক ব্যবহার করে SOAP সার্ভিস তৈরি শুরু করতে পারবেন।

Content added By

Spring Boot দিয়ে একটি Spring Web Service তৈরি করা হলো SOAP ভিত্তিক সার্ভিস ডেভেলপমেন্টকে সহজ এবং দ্রুত করার একটি কার্যকর পদ্ধতি। এখানে বিস্তারিতভাবে একটি SOAP সার্ভিস তৈরির ধাপগুলো ব্যাখ্যা করা হয়েছে।


প্রয়োজনীয় টুলস এবং লাইব্রেরি

Spring Boot দিয়ে Spring Web Service তৈরি করার জন্য নিম্নলিখিত টুলস ও লাইব্রেরি প্রয়োজন হবে:

  • জাভা ডেভেলপমেন্ট কিট (JDK)
  • মেভেন (Maven) বা গ্র্যাডল (Gradle)
  • Spring Boot Starter Web Services ডিপেনডেন্সি

স্টেপ ১: প্রজেক্ট সেটআপ

মেভেন প্রজেক্টের জন্য pom.xml কনফিগারেশন

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

স্টেপ ২: XML Schema তৈরি

SOAP সার্ভিসে ডেটা আদান-প্রদানের জন্য একটি XML Schema Definition (XSD) তৈরি করতে হবে। উদাহরণস্বরূপ, একটি সার্ভিস ব্যবহারকারীর ডেটা ফিরিয়ে দেবে।

user-details.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="GetUserDetailsRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="userId" type="xs:int"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="GetUserDetailsResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string"/>
                <xs:element name="email" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

স্টেপ ৩: XML Schema থেকে ক্লাস জেনারেশন

Spring Boot XSD ফাইল থেকে জাভা ক্লাস তৈরি করতে JAXB ব্যবহার করে। এটি করতে, মেভেন প্লাগইন ব্যবহার করা যেতে পারে।

মেভেন প্লাগইন কনফিগারেশন:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.5.0</version>
    <executions>
        <execution>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
        <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
    </configuration>
</plugin>

স্টেপ ৪: SOAP Endpoint তৈরি করা

UserDetailsEndpoint ক্লাস:

@Endpoint
public class UserDetailsEndpoint {
    private static final String NAMESPACE_URI = "http://example.com/users";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "GetUserDetailsRequest")
    @ResponsePayload
    public GetUserDetailsResponse getUserDetails(@RequestPayload GetUserDetailsRequest request) {
        GetUserDetailsResponse response = new GetUserDetailsResponse();
        response.setName("John Doe");
        response.setEmail("john.doe@example.com");
        return response;
    }
}

স্টেপ ৫: ওয়েব সার্ভিস কনফিগারেশন

SOAP সার্ভিসকে ওয়েব অ্যাপ্লিকেশনের অংশ হিসেবে তৈরি করতে WebServiceConfig কনফিগারেশন ক্লাস ব্যবহার করা হয়।

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext context) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(context);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<>(servlet, "/ws/*");
    }

    @Bean(name = "users")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema usersSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("UserDetailsPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://example.com/users");
        wsdl11Definition.setSchema(usersSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema usersSchema() {
        return new SimpleXsdSchema(new ClassPathResource("user-details.xsd"));
    }
}

স্টেপ ৬: অ্যাপ্লিকেশন চালানো

Spring Boot অ্যাপ্লিকেশন চালাতে নিচের main ক্লাস তৈরি করুন।

@SpringBootApplication
public class SpringWebServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringWebServiceApplication.class, args);
    }
}

সারাংশ

Spring Boot দিয়ে Spring Web Service তৈরি করা SOAP সার্ভিস ডেভেলপমেন্টের একটি আধুনিক ও কার্যকর উপায়। এর মাধ্যমে দ্রুত একটি কার্যকরী ও স্ট্যান্ডার্ড ওয়েব সার্ভিস তৈরি করা যায়, যা বিভিন্ন প্ল্যাটফর্ম ও প্রযুক্তির সাথে সহজেই ইন্টিগ্রেট হতে পারে।


Content added By

আমরা এখানে একটি SOAP ওয়েব সার্ভিস তৈরি করব, যা একটি নির্দিষ্ট নাম গ্রহণ করবে এবং একটি স্বাগত বার্তা ফিরিয়ে দেবে।


প্রয়োজনীয় পরিবেশ

  • Java Development Kit (JDK)
  • Spring Boot
  • Maven/Gradle
  • IDE (যেমন IntelliJ IDEA, Eclipse)

প্রোজেক্টের স্ট্রাকচার

src
├── main
│   ├── java
│   │   └── com.example.soapws
│   │       ├── SoapWebServiceApplication.java
│   │       ├── ws
│   │       │   ├── endpoint
│   │       │   │   └── HelloWorldEndpoint.java
│   │       │   ├── config
│   │       │   │   └── WebServiceConfig.java
│   │       │   └── schema
│   │       │       └── HelloWorld.xsd
│   ├── resources
│       ├── application.properties
│       └── wsdl
│           └── HelloWorld.wsdl

ধাপ ১: Maven ডিপেন্ডেন্সি

pom.xml ফাইলে নিচের ডিপেন্ডেন্সি যোগ করুন:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
</dependencies>

ধাপ ২: XSD (XML Schema) তৈরি

HelloWorld.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           targetNamespace="http://example.com/helloworld" 
           xmlns="http://example.com/helloworld" 
           elementFormDefault="qualified">
    <xs:element name="HelloRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="HelloResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="message" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

ধাপ ৩: কনফিগারেশন ক্লাস

WebServiceConfig.java:

package com.example.soapws.ws.config;

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.config.annotation.EnableWs;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;

@EnableWs
@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(name = "helloworld")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema helloWorldSchema) {
        DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
        definition.setPortTypeName("HelloWorldPort");
        definition.setLocationUri("/ws");
        definition.setTargetNamespace("http://example.com/helloworld");
        definition.setSchema(helloWorldSchema);
        return definition;
    }

    @Bean
    public XsdSchema helloWorldSchema() {
        return new SimpleXsdSchema(new ClassPathResource("ws/schema/HelloWorld.xsd"));
    }
}

ধাপ ৪: এন্ডপয়েন্ট তৈরি

HelloWorldEndpoint.java:

package com.example.soapws.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;
import com.example.soapws.ws.schema.HelloRequest;
import com.example.soapws.ws.schema.HelloResponse;

@Endpoint
public class HelloWorldEndpoint {
    private static final String NAMESPACE_URI = "http://example.com/helloworld";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HelloRequest")
    @ResponsePayload
    public HelloResponse sayHello(@RequestPayload HelloRequest request) {
        HelloResponse response = new HelloResponse();
        response.setMessage("Hello, " + request.getName() + "!");
        return response;
    }
}

ধাপ ৫: অ্যাপ্লিকেশন ক্লাস

SoapWebServiceApplication.java:

package com.example.soapws;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SoapWebServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(SoapWebServiceApplication.class, args);
    }
}

ধাপ ৬: অ্যাপ্লিকেশন প্রোপার্টিজ

application.properties:

server.port=8080

ধাপ ৭: WSDL ফাইল অ্যাক্সেস করা

আপনার ওয়েব সার্ভার চালু হলে, ব্রাউজারে যান এবং WSDL ফাইল দেখতে নিচের URL ব্যবহার করুন:

http://localhost:8080/ws/helloworld.wsdl

এই উদাহরণটি আপনার প্রথম SOAP ওয়েব সার্ভিস তৈরির জন্য প্রয়োজনীয় ধাপগুলো কভার করে। এটি একটি নাম গ্রহণ করবে এবং সংশ্লিষ্ট স্বাগত বার্তা ফিরিয়ে দেবে।

Content added By
Promotion

Are you sure to start over?

Loading...