01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.customer.wraped;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import javax.jws.WebMethod;
24: import javax.jws.WebParam;
25: import javax.jws.WebService;
26:
27: import org.apache.cxf.customer.Customer;
28: import org.apache.cxf.customer.Customers;
29: import org.codehaus.jra.Delete;
30: import org.codehaus.jra.Get;
31: import org.codehaus.jra.HttpResource;
32: import org.codehaus.jra.Post;
33: import org.codehaus.jra.Put;
34:
35: // END SNIPPET: service
36: @WebService(targetNamespace="http://cxf.apache.org/jra")
37: public class CustomerService {
38: long currentId = 1;
39: Map<Long, Customer> customers = new HashMap<Long, Customer>();
40:
41: public CustomerService() {
42: Customer customer = createCustomer();
43: customers.put(customer.getId(), customer);
44: }
45:
46: @Get
47: @HttpResource(location="/customers")
48: @WebMethod
49: public Customers getCustomers() {
50: Customers cbean = new Customers();
51: cbean.setCustomer(customers.values());
52: return cbean;
53: }
54:
55: @Get
56: @HttpResource(location="/customers/{id}")
57: @WebMethod
58: public Customer getCustomer(@WebParam(name="id")
59: Long id) {
60: return customers.get(id);
61: }
62:
63: @Put
64: @HttpResource(location="/customers/{id}")
65: @WebMethod
66: public void updateCustomer(@WebParam(name="id")
67: String id, Customer c) {
68: customers.put(c.getId(), c);
69: }
70:
71: @Post
72: @HttpResource(location="/customers")
73: @WebMethod
74: public void addCustomer(@WebParam(name="customer")
75: Customer c) {
76: long id = ++currentId;
77: c.setId(id);
78:
79: customers.put(id, c);
80: }
81:
82: @Delete
83: @HttpResource(location="/customers/{id}")
84: @WebMethod
85: public void deleteCustomer(String id) {
86: customers.remove(new Long(id));
87: }
88:
89: final Customer createCustomer() {
90: Customer c = new Customer();
91: c.setName("Dan Diephouse");
92: c.setId(123);
93: return c;
94: }
95: }
96: // END SNIPPET: service
|