-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes
More file actions
423 lines (308 loc) · 14.5 KB
/
Notes
File metadata and controls
423 lines (308 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
About WSDL
========
The Structure of the wsdl is like below
xml tag description
======== =========
<types> A container for data type definitions used by the web service
<message> A typed definition of the data being communicated
<portType> A set of operations supported by one or more endpoints
<binding> A protocol and data format specification for a particular port type
The main structure of the wsdl documents are looks like
<definitions>
<types>
data type definitions........
</types>
<message>
definition of the data being communicated....
</message>
<portType>
set of operations......
</portType>
<binding>
protocol and data format specification....
</binding>
for more visit : http://www.w3schools.com/webservices/ws_wsdl_documents.asp
wsdl to Java
================
During the conversation from wsdl file to java by using either wsdl2java(cxf) or wsimport(java),
In the Generated code we found some interface, class and pojo based in the element define in the wsdl
wsdl java
==== ========
wsdl:portType java Interface
Any complex type java classes
Any complex type Java classes
Note - The endpoint defined by the wsdl:service element is also generated into a Java class that is used by consumers to access endpoints implementing the service.
About CXF
=======
Tutorial : http://cxf.apache.org/docs/developing-a-service.html
Develop a service by using contract fast approach/top down approach
(wsdl-java skliton for implimentaion/wsdl-java for consuming puposes)
=========================================================
You can generate the code needed to develop your service using the following command:
wsdl2java -ant -impl -server -d <outputDir> myService.wsdl
The command does the following:
The -ant argument generates a Ant makefile, called build.xml, for your application.
The -impl argument generates a shell implementation class for each portType element in the WSDL document.
The -server argument generates a simple main() to launch your service as a stand alone application.
The -d outputDir argument tells wsdl2java to write the generated code to a directory called outputDir.
myService.wsdl is the WSDL document from which code is generated.
After execuating the command we 'll see the below kind of file
file name Desciption
======== =========
portTypeName.java The SEI. This file contains the interface your service implements. You should not edit this file.
serviceName.java The endpoint. This file contains the Java class your clients will use to make requests on the service.
portTypeNameImpl.java The skeleton implementation class. You will modify this file to implement your service.
portTypeName_portTypeNameImplPort_Server.java A basic server main() that allows you to deploy your service as a stand alone process.
develop a services by using botom up approach
(Java file to wsdl)
====================================
1. Create a Service Endpoint Interface (SEI) that defines the methods you wish to expose as a service.
Tip
=====
You can work directly from a Java class, but working from an interface is the recommended approach. Interfaces are better for sharing with the developers who will be responsible for developing the applications consuming your service. The interface is smaller and does not provide any of the service's implementation details.
2. Add the required annotations to your code.
3. Generate the WSDL contract for your service.
Tip
===
If you intend to use the SEI as the service's contract, it is not necessary to generate a WSDL contract
4. Publish the service.
Creating the SEI
===============
There are two basic patterns for creating an SEI:
>Green field development
You are developing a new service from the ground up. When starting fresh, it is best to start by creating the SEI first. You can then distribute the SEI to any developers that are responsible for implementing the services and consumers that use the SEI.
>Service enablement
In this pattern, you typically have an existing set of functionality that is implemented as a Java class and you want to service enable it. This means that you will need to do two things:
>Create an SEI that contains only the operations that are going to be exposed as part of the service.
>Modify the existing Java class so that it implements the SEI.
Example
========
SEI
-----------------
package org.apache.cxf;
public interface QuoteReporter
{
public Quote getQuote(String ticker);
}
Implimentation of SEI
-----------------------------
package org.apache.cxf;
import java.util.*;
public class StockQuoteReporter implements QuoteReporter
{
...
public Quote getQuote(String ticker)
{
Quote retVal = new Quote();
retVal.setID(ticker);
retVal.setVal(Board.check(ticker));[1]
Date retDate = new Date();
retVal.setTime(retDate.toString());
return(retVal);
}
}
Annotating the Code
==================
JAX-WS relies on the annotation feature of Java 5. The JAX-WS annotations are used to specify the metadata used to map the SEI to a fully specified service definition. Among the information provided in the annotations are the following:
The target namespace for the service.
The name of the class used to hold the request message.
The name of the class used to hold the response message.
If an operation is a one way operation.
The binding style the service uses.
The name of the class used for any custom exceptions.
The namespaces under which the types used by the service are defined.
Tip
---------
Most of the annotations have sensible defaults and do not need to be specified. However, the more information you provide in the annotations, the better defined your service definition. A solid service definition increases the likely hood that all parts of a distributed application will work together.
Required Annotation
================
The @WebService annotation
--------------------------------
The @WebService annotation is defined by the javax.jws.WebService interface and it is placed on an interface or a class that is intended to be used as a service. @WebService has the following properties:
Property Description
======== =============
name Specifies the name of the service interface. This property is mapped to the name attribute of the wsdl:portType element that defines the
service's interface in a WSDL contract. The default is to append PortType to the name of the implementation class.
targetNamespace Specifies the target namespace under which the service is defined. If this property is not specified, the target namespace is derived from the
package name.
serviceName Specifies the name of the published service. This property is mapped to the name attribute of the wsdl:service element that defines the
published service. The default is to use the name of the service's implementation class.
Note: Not allowed on the SEI
wsdlLocation Specifies the URI at which the service's WSDL contract is stored. The default is the URI at which the service is deployed.
endpointInterface Specifies the full name of the SEI that the implementation class implements. This property is only used when the attribute is used on a
service implementation class.
Note: Not allowed on the SEI
portName Specifies the name of the endpoint at which the service is published. This property is mapped to the name attribute of the wsdl:port
element that specifies the endpoint details for a published service. The default is the append Port to the name of the service's implementation class.
Note: Not allowed on the SEI
EXAMPLE
===============
SEI
-------
package com.mycompany.demo;
import javax.jws.*;
@WebService(name="quoteUpdater",
targetNamespace="http://cxf.apache.org",
wsdlLocation="http://somewhere.com/quoteExampleService?wsdl")
public interface QuoteReporter
{
public Quote getQuote(@WebParam(name="ticker") String ticker);
}
SEI Implementation
-------------------------
package org.apache.cxf;
import javax.jws.*;
@WebService(endpointInterface="org.apache.cxf.quoteReporter",
targetNamespace="http://cxf.apache.org",
portName="StockQuotePort",
serviceName="StockQuoteReporter",
)
public class StockQuoteReporter implements QuoteReporter
{
public Quote getQuote(String ticker)
{
...
}
}
Annotation and there property
===================
@SOAPBinding
The @SOAPBinding annotation is defined by the javax.jws.soap.SOAPBinding interface. It provides details about the SOAP binding used by the service when it is deployed. If the @SOAPBinding annotation is not specified, a service is published using a wrapped doc/literal SOAP binding.
You can put the @SOAPBinding annotation on the SEI and any of the SEI's methods. When it is used on a method, setting of the method's @SOAPBinding annotation take precedent.
Property property Value
======== =============
style Style.DOCUMENT (default)
Style.RPC
use Use.LITERAL (default)
Use.ENCODED
parameterStyle ParameterStyle.BARE
ParameterStyle.WRAPPED (default)
@WebMethod
The @WebMethod annotation is defined by the javax.jws.WebMethod interface. It is placed on the methods in the SEI. The @WebMethod annotation provides the information that is normally represented in the wsdl:operation element describing the operation to which the method is associated.
The following table describes the properties of the @WebMethod annotation.
property
======
operationName
action
exclude
@RequestWrapper
@ResponseWrapper
example
-----------
package org.apache.cxf;
import javax.jws.*;
import javax.xml.ws.*;
@WebService(name="quoteReporter")
public interface QuoteReporter
{
@WebMethod(operationName="getStockQuote")
@RequestWrapper(targetNamespace="http://demo.mycompany.com/types",
className="java.lang.String")
@ResponseWrapper(targetNamespace="http://demo.mycompany.com/types",
className="org.eric.demo.Quote")
public Quote getQuote(String ticker);
}
@WebFault
===========
name
targetNamespace
faultName
The @WebFault annotation is defined by the javax.xml.ws.WebFault interface.
It is placed on exceptions that are thrown by your SEI. The @WebFault annotation is used to map the Java exception to a wsdl:fault element. This information is used to marshall the exceptions into a representation that can be processed by both the service and its consumers.
@Oneway
========
The @Oneway annotation is defined by the javax.jws.Oneway interface. It is placed on the methods in the SEI that will not require a response from the service. The @Oneway annotation tells the run time that it can optimize the execution of the method by not waiting for a response and not reserving any resources to process a response.
@WebParam
===========
name
targetNamespace
mode
header
partName
The @WebParam annotation is defined by the javax.jws.WebParam interface. It is placed on the parameters on the methods defined in the SEI. The @WebParam annotation allows you to specify the direction of the parameter, if the parameter will be placed in the SOAP header, and other properties of the generated wsdl:part.
@WebResult
==========
The @WebResult annotation is defined by the javax.jws.WebResult interface. It is placed on the methods defined in the SEI. The @WebResult annotation allows you to specify the properties of the generated wsdl:part that is generated for the method's return value.
name
targetNamespace
header
partName
example
------------
package org.apache.cxf;
import javax.jws.*;
import javax.xml.ws.*;
import javax.jws.soap.*;
import javax.jws.soap.SOAPBinding.*;
import javax.jws.WebParam.*;
@WebService(name="quoteReporter")
@SOAPBinding(style=Style.RPC, use=Use.LITERAL)
public interface QuoteReporter
{
@WebMethod(operationName="getStockQuote")
@RequestWrapper(targetNamespace="http://demo.mycompany.com/types",
className="java.lang.String")
@ResponseWrapper(targetNamespace="http://demo.mycompany.com/types",
className="org.eric.demo.Quote")
@WebResult(targetNamespace="http://demo.mycompany.com/types",
name="updatedQuote")
public Quote getQuote(
@WebParam(targetNamespace="http://demo.mycompany.com/types",
name="stockTicker",
mode=Mode.IN)
String ticker
);
}
after that we can generate wsdl file from java2ws command
The Maven script for java2ws comand is
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>org.apache.hello_world.Greeter</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>
and additionally we can add :-
<configuration>
<className>...</className>
<classpath>...</classpath>
<outputFile>...</outputFile>
<genWsdl>true</genWsdl>
<genServer>false</genServer>
<genClient>false</genClient>
<genWrapperbean>false</genWrapperbean>
<frontend>jaxws</frontend>
<databinding>jaxb</databinding>
<serviceName>...</serviceName>
<soap12>false</soap12>
<targetNameSpace>...</targetNameSpace>
<verbose>false</verbose>
<quiet>false</quiet>
<attachWsdl>false</attachWsdl>
<address>...</address>
</configuration>
In the outputFile vale by default value is : ${project.build.directory}/generated/wsdl/${className}.wsdl