578bccafc9af02798ab915add99a45751853e91e
[SpringWebServicesForFun/.git] /
1 package de.spring.webservices.client;
2
3 import name.gumartinm.spring_ws.parent.ParentEnumType;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Service;
7 import org.springframework.ws.client.core.WebServiceTemplate;
8
9 import de.spring.webservices.auto.CustomBindingExampleFault_Exception;
10 import de.spring.webservices.auto.CustomBindingExampleRequest;
11 import de.spring.webservices.auto.CustomBindingExampleResponse;
12 import de.spring.webservices.auto.ExampleFault_Exception;
13 import de.spring.webservices.auto.ExampleRequest;
14 import de.spring.webservices.auto.ExampleResponse;
15 import de.spring.webservices.auto.Examples;
16 import de.spring.webservices.auto.ExamplesService;
17
18 /**
19  * Someone could write code like this one in order to send and receive
20  * information from our Web Services.
21  * 
22  */
23 @Service("exampleClientService")
24 public class ExampleClientService {     
25     private final WebServiceTemplate webServiceTemplate;
26
27     @Autowired
28     public ExampleClientService(WebServiceTemplate webServiceTemplate) {
29             this.webServiceTemplate = webServiceTemplate;
30     }
31
32         public ExampleResponse sendAndReceiveJava() throws ExampleFault_Exception {
33         final ExampleRequest exampleRequest = new ExampleRequest();
34         exampleRequest.setData("SCARLETT JAVA. IT IS CANON.");
35
36         final Examples exampleService = new ExamplesService().getExamplesSoap12();
37         final ExampleResponse exampleResponse = exampleService.example(exampleRequest);
38         
39         return exampleResponse;
40     }
41     
42         public ExampleResponse sendAndReceiveSpring() {
43         final ExampleRequest exampleRequest = new ExampleRequest();
44         exampleRequest.setData("SCARLETT SPRING. IT IS CANON.");
45
46         final ExampleResponse exampleResponse = (ExampleResponse)
47                 this.webServiceTemplate.marshalSendAndReceive(exampleRequest);
48         
49         return exampleResponse;
50     }
51         
52         public CustomBindingExampleResponse sendAndReceiveJavaCustom() throws CustomBindingExampleFault_Exception {
53         final CustomBindingExampleRequest customBindingxampleRequest =
54                         new CustomBindingExampleRequest();
55         customBindingxampleRequest.setData("CUSTOM BINDING JAVA. SCARLETT. IT IS CANON.");
56         customBindingxampleRequest.setParentEnum(ParentEnumType.FIRST);
57   
58         final Examples exampleService = new ExamplesService().getExamplesSoap12();
59         final CustomBindingExampleResponse customBindingExampleResponse =
60                 exampleService.customBindingExample(customBindingxampleRequest);
61         
62         return customBindingExampleResponse;
63     }
64         
65         public CustomBindingExampleResponse sendAndReceiveSpringCustom() {
66         final CustomBindingExampleRequest customBindingxampleRequest =
67                         new CustomBindingExampleRequest();
68         customBindingxampleRequest.setData("CUSTOM BINDING SPRING. SCARLETT. IT IS CANON.");
69
70         final CustomBindingExampleResponse customBindingExampleResponse =
71                         (CustomBindingExampleResponse) this.webServiceTemplate
72                         .marshalSendAndReceive(customBindingxampleRequest);
73         
74         return customBindingExampleResponse;
75     }
76 }