Debian Codegraph @

samples/moxy/README.html

raw
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <!--
3
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
6 Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
7
8 The contents of this file are subject to the terms of either the GNU
9 General Public License Version 2 only ("GPL") or the Common Development
10 and Distribution License("CDDL") (collectively, the "License"). You
11 may not use this file except in compliance with the License. You can
12 obtain a copy of the License at
13 http://glassfish.java.net/public/CDDL+GPL_1_1.html
14 or packager/legal/LICENSE.txt. See the License for the specific
15 language governing permissions and limitations under the License.
16
17 When distributing the software, include this License Header Notice in each
18 file and include the License file at packager/legal/LICENSE.txt.
19
20 GPL Classpath Exception:
21 Oracle designates this particular file as subject to the "Classpath"
22 exception as provided by Oracle in the GPL Version 2 section of the License
23 file that accompanied this code.
24
25 Modifications:
26 If applicable, add the following below the License Header, with the fields
27 enclosed by brackets [] replaced by your own identifying information:
28 "Portions Copyright [year] [name of copyright owner]"
29
30 Contributor(s):
31 If you wish your version of this file to be governed by only the CDDL or
32 only the GPL Version 2, indicate your decision by adding "[Contributor]
33 elects to include this software in this distribution under the [CDDL or GPL
34 Version 2] license." If you don't indicate a single choice of license, a
35 recipient has the option to distribute your version of this file under
36 either the CDDL, the GPL Version 2 or to extend the choice of license to
37 its licensees as provided above. However, if you add GPL Version 2 code
38 and therefore, elected the GPL Version 2 license, then the option applies
39 only if the new code is made subject to such option by the copyright
40 holder.
41
42 -->
43 <html><head><title>MOXy Example</title></head>
44
45
46 <body>
47 <h1>MOXy Example</h1>
48
49 <h2>What is MOXy</h2>
50 <p>This example demonstrates that you can utilize MOXy extensions when dealing with XML representation when developing a Jersey based RESTful Web application</p>
51
52 <p>MOXy is EclipseLink's Object to XML Mapping services. MOXy allows for a POJO object model to be mapped to an XML schema. The Java Architecture for XML Binding (JAXB) provides a Java standard for object XML mapping (OXM). MOXy supports JAXB, as well as providing its' own native API and integration with Web Services.
53 </p>
54
55 <h2>MOXy XML Path Mapping Extension</h2>
56
57 <p>The MOXy extension shown in this example is described on the Eclipse Wiki site
58 at <a href="http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/MOXyExtensions">http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/MOXyExtensions</a>.
59 It allows you to specify path based mapping via @XmlPath annotation.
60 </p>
61
62 <p>If the MOXy extension was not used, the XML represenation of the customer data would look like follows:
63 <pre>
64 &lt;customer&gt;
65 &lt;name&gt;Jane Doe&lt;/name&gt;
66 &lt;address&gt;
67 &lt;city&gt;My Town&lt;/city&gt;
68 &lt;street&gt;123 Any Street&lt;/street&gt;
69 &lt;/address&gt;
70 &lt;phoneNumbers type="work"&gt;613-555-1111&lt;/phoneNumbers&gt;
71 &lt;phoneNumbers type="cell"&gt;613-555-2222&lt;/phoneNumbers&gt;
72 &lt;/customer&gt;
73 </pre>
74 By adding <code>@org.eclipse.persistence.oxm.annotations.XmlPath</code> annotation to the bean definition classes,
75 you will get the following XML representation instead:
76 <pre>
77 &lt;customer&gt;
78 <b>&lt;personal-info&gt;</b>
79 &lt;name&gt;Jane Doe&lt;/name&gt;
80 <b>&lt;/personal-info&gt;
81 &lt;contact-info&gt;</b>
82 &lt;address&gt;
83 &lt;city&gt;My Town&lt;/city&gt;
84 &lt;street&gt;123 Any Street&lt;/street&gt;
85 &lt;/address&gt;
86 <b>&lt;phone-number type="work"&gt;</b>613-555-1111<b>&lt;/phone-number&gt;</b>
87 <b>&lt;phone-number type="cell"&gt;</b>613-555-2222<b>&lt;/phone-number&gt;</b>
88 <b>&lt;/contact-info&gt;</b>
89 &lt;/customer&gt;
90 </pre>
91 XML Path expressions used are:
92 <ul>
93 <li>personal-info/name/text()</li>
94 <li>contact-info/address</li>
95 <li>contact-info/phone-number</li>
96 </ul>
97 Please check out the source code and the wiki page linked above for the detailed information on the XML Path mapping feature.
98 </p>
99
100 <h2>Replacing Implicit JAXB Runtime With MOXy</h2>
101 <p>Since MOXy is a JAXB implementation, the example still utilizes the standard Jersey JAXB message body reader/writer providers.
102 To make Jersey use MOXy runtime, you just need to put a <code>jaxb.properties</code> file into the Java package
103 containing your JAXB beans. The file should have the following content:
104 <pre>
105 javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
106 </pre>
107 Concrete file used in this example is placed under <code>src/main/resources/com/sun/jersey/samples/moxy/beans/jaxb.properties</code>
108 </p>
109 <h2>REST Resources</h2>
110 <p>The example consists of a single REST Resource represented by the following Java class:</p>
111 <dl>
112 <dt><code>com.sun.jersey.samples.moxy.CustomerResource</code></dt>
113 <dd>A resource class that maintains a single customer data.</dd>
114 </dl>
115 <p>The mapping of the URI path space is presented in the following table:</p>
116 <table border="1">
117 <tr>
118 <th>URI path</th>
119 <th>Resource class</th>
120 <th>HTTP methods</th>
121 </tr>
122 <tr>
123 <td>/customer</td>
124 <td>CustomerResource</td>
125 <td>GET</td>
126 </tr>
127 <tr>
128 <td>/customer</td>
129 <td>CustomerResource</td>
130 <td>PUT</td>
131 </tr>
132 </table>
133
134 <h2>Running the Example</h2>
135
136 <p>If you are working with Jersey GlassFish update center module installed into your existing GlassFish instance,
137 you will need to follow instructions at <a href="../../README.html">the module README file</a> in order to
138 deploy the example.
139
140 <p>Otherwise, you can run the example using embedded GlassFish as follows:</p>
141
142 <blockquote><code>mvn clean package embedded-glassfish:run</code></blockquote>
143 <p>or you can run the example using Jetty as follows:</p>
144
145 <blockquote><code>mvn clean package jetty:run</code></blockquote>
146 <p>From a web browser, visit:</p>
147 <blockquote><code><a href="http://localhost:8080/moxy/customer">http://localhost:8080/moxy/customer</a></code>
148 </blockquote>
149 </body></html>