|
1 /* |
|
2 * Copyright (c) 1997, 2012, 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.xml.internal.ws.server.provider.AsyncProviderInvokerTube; |
|
32 import com.sun.istack.internal.NotNull; |
|
33 import org.w3c.dom.Element; |
|
34 |
|
35 import javax.xml.ws.EndpointReference; |
|
36 import javax.xml.ws.handler.MessageContext; |
|
37 import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
38 import java.security.Principal; |
|
39 |
|
40 /** |
|
41 * Partial {@link WSWebServiceContext} implementation. This implementation depends on |
|
42 * {@link Packet} and concrete implementations provide it via |
|
43 * {@link #getRequestPacket()}. |
|
44 * |
|
45 * @see InvokerTube, |
|
46 * @see AsyncProviderInvokerTube |
|
47 * |
|
48 * @author Jitendra Kotamraju |
|
49 */ |
|
50 public abstract class AbstractWebServiceContext implements WSWebServiceContext { |
|
51 |
|
52 private final WSEndpoint endpoint; |
|
53 |
|
54 public AbstractWebServiceContext(@NotNull WSEndpoint endpoint) { |
|
55 this.endpoint = endpoint; |
|
56 } |
|
57 |
|
58 public MessageContext getMessageContext() { |
|
59 Packet packet = getRequestPacket(); |
|
60 if (packet == null) { |
|
61 throw new IllegalStateException("getMessageContext() can only be called while servicing a request"); |
|
62 } |
|
63 return new EndpointMessageContextImpl(packet); |
|
64 } |
|
65 |
|
66 public Principal getUserPrincipal() { |
|
67 Packet packet = getRequestPacket(); |
|
68 if (packet == null) { |
|
69 throw new IllegalStateException("getUserPrincipal() can only be called while servicing a request"); |
|
70 } |
|
71 return packet.webServiceContextDelegate.getUserPrincipal(packet); |
|
72 } |
|
73 |
|
74 public boolean isUserInRole(String role) { |
|
75 Packet packet = getRequestPacket(); |
|
76 if (packet == null) { |
|
77 throw new IllegalStateException("isUserInRole() can only be called while servicing a request"); |
|
78 } |
|
79 return packet.webServiceContextDelegate.isUserInRole(packet,role); |
|
80 } |
|
81 |
|
82 public EndpointReference getEndpointReference(Element...referenceParameters) { |
|
83 return getEndpointReference(W3CEndpointReference.class, referenceParameters); |
|
84 } |
|
85 |
|
86 public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element...referenceParameters) { |
|
87 Packet packet = getRequestPacket(); |
|
88 if (packet == null) { |
|
89 throw new IllegalStateException("getEndpointReference() can only be called while servicing a request"); |
|
90 } |
|
91 String address = packet.webServiceContextDelegate.getEPRAddress(packet, endpoint); |
|
92 String wsdlAddress = null; |
|
93 if(endpoint.getServiceDefinition() != null) { |
|
94 wsdlAddress = packet.webServiceContextDelegate.getWSDLAddress(packet,endpoint); |
|
95 } |
|
96 return clazz.cast(endpoint.getEndpointReference(clazz,address,wsdlAddress, referenceParameters)); |
|
97 } |
|
98 |
|
99 } |