177c13e8e6784405582974f32c15356bde398d65
[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.ws.client.core.WebServiceTemplate;
7
8 import de.spring.webservices.auto.CustomBindingExampleRequest;
9 import de.spring.webservices.auto.CustomBindingExampleResponse;
10 import de.spring.webservices.auto.ExampleRequest;
11 import de.spring.webservices.auto.ExampleResponse;
12 import de.spring.webservices.auto.Examples;
13 import de.spring.webservices.auto.ExamplesService;
14
15 /**
16  * Someone could write code like this one in order to send and receive
17  * information from our Web Services.
18  * 
19  */
20 public class ExampleClientService {     
21     private final WebServiceTemplate webServiceTemplate;
22
23     @Autowired
24     public ExampleClientService(WebServiceTemplate webServiceTemplate) {
25             this.webServiceTemplate = webServiceTemplate;
26     }
27
28         public ExampleResponse sendAndReceiveJava() {
29         final ExampleRequest exampleRequest = new ExampleRequest();
30         exampleRequest.setData("SCARLETT JAVA. IT IS CANON.");
31
32         final Examples exampleService = new ExamplesService().getExamplesSoap12();
33         final ExampleResponse exampleResponse = exampleService.example(exampleRequest);
34         
35         return exampleResponse;
36     }
37     
38         public ExampleResponse sendAndReceiveSpring() {
39         final ExampleRequest exampleRequest = new ExampleRequest();
40         exampleRequest.setData("SCARLETT SPRING. IT IS CANON.");
41
42         final ExampleResponse exampleResponse = (ExampleResponse)
43                 this.webServiceTemplate.marshalSendAndReceive(exampleRequest);
44         
45         return exampleResponse;
46     }
47         
48         public CustomBindingExampleResponse sendAndReceiveJavaCustom() {
49         final CustomBindingExampleRequest customBindingxampleRequest =
50                         new CustomBindingExampleRequest();
51         customBindingxampleRequest.setData("CUSTOM BINDING JAVA. SCARLETT. IT IS CANON.");
52         customBindingxampleRequest.setParentEnum(ParentEnumType.FIRST);
53   
54         final Examples exampleService = new ExamplesService().getExamplesSoap12();
55         final CustomBindingExampleResponse customBindingExampleResponse =
56                 exampleService.customBindingExample(customBindingxampleRequest);
57         
58         return customBindingExampleResponse;
59     }
60         
61         public CustomBindingExampleResponse sendAndReceiveSpringCustom() {
62         final CustomBindingExampleRequest customBindingxampleRequest =
63                         new CustomBindingExampleRequest();
64         customBindingxampleRequest.setData("CUSTOM BINDING SPRING. SCARLETT. IT IS CANON.");
65
66         final CustomBindingExampleResponse customBindingExampleResponse =
67                         (CustomBindingExampleResponse) this.webServiceTemplate
68                         .marshalSendAndReceive(customBindingxampleRequest);
69         
70         return customBindingExampleResponse;
71     }
72 }