src/share/jaxws_classes/com/sun/xml/internal/ws/server/AbstractWebServiceContext.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.server;
27
28 import com.sun.xml.internal.ws.api.message.Packet;
29 import com.sun.xml.internal.ws.api.server.WSEndpoint;
30 import com.sun.xml.internal.ws.api.server.WSWebServiceContext;
31 import com.sun.istack.internal.NotNull;
32 import org.w3c.dom.Element;
33
34 import javax.xml.ws.EndpointReference;
35 import javax.xml.ws.handler.MessageContext;
36 import javax.xml.ws.wsaddressing.W3CEndpointReference;
37 import java.security.Principal;
38
39 /**
40 * Partial {@link WSWebServiceContext} implementation. This implementation depends on
41 * {@link Packet} and concrete implementations provide it via
42 * {@link #getRequestPacket()}.
43 *
44 * @see InvokerTube, AsyncProviderInvokerTube
45 *
46 * @author Jitendra Kotamraju
47 */
48 public abstract class AbstractWebServiceContext implements WSWebServiceContext {
49
50 private final WSEndpoint endpoint;
51
52 public AbstractWebServiceContext(@NotNull WSEndpoint endpoint) {
53 this.endpoint = endpoint;
54 }
55
56 public MessageContext getMessageContext() {
57 Packet packet = getRequestPacket();
58 if (packet == null) {
59 throw new IllegalStateException("getMessageContext() can only be called while servicing a request");
60 }
61 return new EndpointMessageContextImpl(packet);
62 }
63
64 public Principal getUserPrincipal() {
65 Packet packet = getRequestPacket();
66 if (packet == null) {
67 throw new IllegalStateException("getUserPrincipal() can only be called while servicing a request");
68 }
69 return packet.webServiceContextDelegate.getUserPrincipal(packet);
70 }
71
72 public boolean isUserInRole(String role) {
73 Packet packet = getRequestPacket();
74 if (packet == null) {
75 throw new IllegalStateException("isUserInRole() can only be called while servicing a request");
76 }
77 return packet.webServiceContextDelegate.isUserInRole(packet,role);
78 }
79
80 public EndpointReference getEndpointReference(Element...referenceParameters) {
81 return getEndpointReference(W3CEndpointReference.class, referenceParameters);
82 }
83
84 public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element...referenceParameters) {
85 Packet packet = getRequestPacket();
86 if (packet == null) {
87 throw new IllegalStateException("getEndpointReference() can only be called while servicing a request");
88 }
89 String address = packet.webServiceContextDelegate.getEPRAddress(packet, endpoint);
90 String wsdlAddress = null;
91 if(endpoint.getServiceDefinition() != null) {
92 wsdlAddress = packet.webServiceContextDelegate.getWSDLAddress(packet,endpoint);
93 }
94 return clazz.cast(((WSEndpointImpl)endpoint).getEndpointReference(clazz,address,wsdlAddress, referenceParameters));
95 }
96
97 }

mercurial