복붙노트

[SPRING] wsdl을 사용하여 SPRING-WS에서 웹 서비스 서비스 사용

SPRING

wsdl을 사용하여 SPRING-WS에서 웹 서비스 서비스 사용

저와 WSDL을 가지고 있습니다. : / sample / hello? wsdl. 나는 Spring-ws에서 설정함으로써 webservice 서비스를 호출하려고한다. springconfig.xml의 태그에이 wsdl을 매개 변수로 전달했습니다. 아무도 봄 - ws 에서이 webservice를 소비하는 방법을 말해주십시오.

해결법

  1. ==============================

    1.pom 파일에 다음 종속성을 추가하십시오.

    pom 파일에 다음 종속성을 추가하십시오.

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>2.1.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.5</version>
    </dependency>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    
        <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
    
        <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="contextPath" value="com.yourcomany.model" />
        </bean>
    
        <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
            <constructor-arg ref="messageFactory" />
            <property name="marshaller" ref="marshaller"></property>
            <property name="unmarshaller" ref="marshaller"></property>
            <property name="messageSender">
                <bean
                    class="org.springframework.ws.transport.http.HttpComponentsMessageSender" />
            </property>
            <property name="defaultUri"
                value="http://<hostname>:<portnumber>/sample/hello" />
        </bean>
    
    </beans>
    

    예를 들어, SOAP 요청 XML이

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xxx="http://yourcomapny.com">
       <soapenv:Header/>
       <soapenv:Body>
          <xxx:InputParameters>
             <xxx:paramONE>1</xxx:paramONE>
          </xxx:InputParameters>
       </soapenv:Body>
    </soapenv:Envelope>
    

    SOAP 응답 XML은 다음과 같이 보입니다.

    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
       <env:Header>
          ...
       </env:Header>
       <env:Body>
          <xxx:OutputParameters xmlns:xxx="http://yourcompany.com">
             <xxx:paramONE>0</xxx:paramONE>
          </xxx:OutputParameters>
       </env:Body>
    </env:Envelope>
    

    해당 클래스 (marshaller bean에 지정한 패키지 아래 : com.yourcompany.model)는 각각 다음과 같습니다.

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = { "paramONE" })
    @XmlRootElement(name = "InputParameters", namespace = "http://yourcompany.com")
    public class InputParameters {
    
        @XmlElement(required = true, namespace = "http://yourcompany.com")
        private String paramONE;
    
        public String getParamONE() {
            return paramONE;
        }
    
        public void setParamONE(String paramONE) {
            this.paramONE = paramONE;
        }
    
    }
    

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = { "paramONE" })
    @XmlRootElement(name = "OutputParameters", namespace = "http://yourcompany.com")
    public class OutputParameters {
    
        @XmlElement(required = true, namespace = "http://yourcompany.com")
        private BigDecimal paramONE;
    
        public BigDecimal getParamONE() {
            return this.paramONE;
        }
    
        public void setParamONE(BigDecimal paramONE) {
            this.paramONE= paramONE;
        }
    
    }
    
    @XmlRegistry
    public class ObjectFactory {
    
        public ObjectFactory() {
        }
    
        public InputParameters createYourRequest() {
            return new InputParameters();
        }
    
        public OutputParameters createYourResponse() {
            return new OutputParameters();
        }
    
    }
    

    인터페이스 :

    public interface YourService {
    
        BigDecimal getValue(String paramOne);
    
    }
    

    이행

    @Component("yourServiceClient")
    public class YourServiceClient implements YourService {
    
        private static final ObjectFactory WS_CLIENT_FACTORY = new ObjectFactory();
    
        private WebServiceTemplate webServiceTemplate;
    
        @Autowired
        public YourServiceClient(WebServiceTemplate webServiceTemplate) {
            this.webServiceTemplate = webServiceTemplate;
        }
    
        @Override
        public BigDecimal getValue(String paramOne) {
            InputParameters request = WS_CLIENT_FACTORY
                    .createYourRequest();
            request.setParamONE(paramOne);
    
            OutputParameters response = (OutputParameters) webServiceTemplate
                    .marshalSendAndReceive(request);
    
            return response.getParamONE();
        }
    
    }
    
  2. ==============================

    2.@ Taoufik Mohdit 대답이 완료되었습니다!

    @ Taoufik Mohdit 대답이 완료되었습니다!

    입출력 객체를 빌드하려면 Webservice-Client를 사용할 수 있습니다 : Spring WS, JAXB 및 하나의 WSDL 파일을 사용한 일반적인 접근 방식? 이러한 객체를 자동으로 빌드하는 방법

  3. ==============================

    3.이 질문이 여전히 활발하다는 것을 감안할 때 스프링 웹 서비스 프레임 워크의 최근 버전과 Spring의 일반적인 변경 사항을 반영하는 업데이트를 게시 할 것이라고 생각했습니다.

    이 질문이 여전히 활발하다는 것을 감안할 때 스프링 웹 서비스 프레임 워크의 최근 버전과 Spring의 일반적인 변경 사항을 반영하는 업데이트를 게시 할 것이라고 생각했습니다.

    WebServiceTemplate은 여전히 ​​클라이언트 측 웹 서비스 액세스의 핵심 클래스입니다. 더 자세한 정보는 필자가 작성한 WSDL 파일에서 시작하여 Spring-WS를 사용하여 웹 서비스를 사용하는 방법에 대한 자세한 예제를 확인할 수있다.

  4. from https://stackoverflow.com/questions/18641928/consume-webservice-service-in-spring-ws-using-wsdl by cc-by-sa and MIT license