Skip to content

Package: PathParam

PathParam

Coverage

1: /*
2: * Copyright (c) 2018, 2019 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.websocket.server;
19:
20: import java.lang.annotation.ElementType;
21: import java.lang.annotation.Retention;
22: import java.lang.annotation.RetentionPolicy;
23: import java.lang.annotation.Target;
24:
25: /**
26: * This annotation may be used to annotate method parameters on server endpoints where a URI-template has been used in
27: * the path-mapping of the {@link ServerEndpoint} annotation. The method parameter may be of type String, any Java
28: * primitive type or any boxed version thereof. If a client URI matches the URI-template, but the requested path
29: * parameter cannot be decoded, then the websocket's error handler will be called.
30: *
31: * <p>
32: * For example:-
33: *
34: * <pre>
35: * <code>
36: * @ServerEndpoint("/bookings/{guest-id}")
37: * public class BookingServer {
38: *
39: * @OnMessage
40: * public void processBookingRequest(@PathParam("guest-id") String guestID, String message, Session session) {
41: * // process booking from the given guest here
42: * }
43: * }
44: * </code>
45: * </pre>
46: *
47: * <p>
48: * For example:-
49: *
50: * <pre>
51: * <code>
52: * @ServerEndpoint("/rewards/{vip-level}")
53: * public class RewardServer {
54: *
55: * @OnMessage
56: * public void processReward(@PathParam("vip-level") Integer vipLevel, String message, Session session) {
57: * // process reward here
58: * }
59: * }
60: * </code>
61: * </pre>
62: *
63: * @author dannycoward
64: */
65: @Retention(RetentionPolicy.RUNTIME)
66: @Target(ElementType.PARAMETER)
67: public @interface PathParam {
68:
69: /**
70: * The name of the variable used in the URI-template. If the name does not match a path variable in the
71: * URI-template, the value of the method parameter this annotation annotates is {@code null}.
72: *
73: * @return the name of the variable used in the URI-template.
74: */
75: public String value();
76: }