简体   繁体   中英

SOAP and Rest Webservice using Spring boot

I'm developing my first Spring Boot application containing both Soap and rest webservice . I've to pass Request in url as a parameter. I'm able to pass request in URL for Rest service. Is it possible to send request in URL for SOAP webservice ?

Ok I am not sure what are your intentions but about SOAP.

---------------                      ----------------
|             |   someMethodInvoke   |              |
|  Your API   | -------------------->| WEB Service  |
|             |<-------------------- |              |
---------------    someResult        ----------------

Now attending a communication with a WS you need firstly to have the schema of that API or the .WSDL from which you can generate Objects with which you will make the calls you need.

I am personally am using JAXB for generating .java classes from schema.

After for the call it self org.springframework.ws.client.core.WebServiceTemplate is the thing that gets the job done. You can use marshalSendAndReceive .

For example:

public class SomeService extends WebServiceGatewaySupport {
     ObjectFactory oFactory = new ObjectFactory();

     public ExpectedResultObject someMethodInvoke(RequestObjectGeneratedFromSchema request){
            JAXBElement<ExpectedResultObject> response = (JAXBElement<ExpectedResultObject>) getWebServiceTemplate()
                .marshalSendAndReceive("http://yourURL.com", oFactory.createreRequestObjectGeneratedFromSchemaInputMessage(request));  
            return response.getValue();
     }
}

Firstly extend the WebServiceGatewaySupport so you can invoke the getWebServiceTemplate() which return just exactly what you need : org.springframework.ws.client.core.WebServiceTemplate . Here is an example how you can use the WebServiceTemplate

Of course there are a lot of factors like security, connectivity and so on which maybe should be set. But that depends on the WS. But basicly that is all :

  1. Generate .java classes from WSDL(schema)
  2. Fill generated object with information
  3. Use some WebServiceTemplate for calling the END point

Hope I gave you some directions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM