325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.addressing;
325N/A
325N/Aimport com.sun.xml.internal.ws.api.server.WSEndpoint;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
325N/Aimport com.sun.xml.internal.ws.api.WSBinding;
325N/Aimport com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
325N/Aimport com.sun.xml.internal.ws.api.message.Packet;
325N/Aimport com.sun.xml.internal.ws.api.pipe.Tube;
325N/Aimport com.sun.xml.internal.ws.api.pipe.TubeCloner;
325N/Aimport com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
325N/Aimport com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
325N/Aimport static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED;
325N/Aimport static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.ONLY_ANONYMOUS_ADDRESS_SUPPORTED;
325N/Aimport com.sun.xml.internal.ws.resources.AddressingMessages;
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.istack.internal.Nullable;
325N/A
325N/Aimport javax.xml.ws.soap.AddressingFeature;
325N/Aimport javax.xml.ws.WebServiceException;
325N/A
325N/A/**
325N/A * @author Rama Pulavarthi
325N/A */
325N/Apublic class W3CWsaServerTube extends WsaServerTube{
325N/A private final AddressingFeature af;
325N/A
325N/A public W3CWsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) {
325N/A super(endpoint, wsdlPort, binding, next);
325N/A af = binding.getFeature(AddressingFeature.class);
325N/A }
325N/A
325N/A public W3CWsaServerTube(W3CWsaServerTube that, TubeCloner cloner) {
325N/A super(that, cloner);
325N/A this.af = that.af;
325N/A }
325N/A
325N/A @Override
325N/A public W3CWsaServerTube copy(TubeCloner cloner) {
325N/A return new W3CWsaServerTube(this, cloner);
325N/A }
325N/A
325N/A @Override
325N/A protected void checkMandatoryHeaders(
325N/A Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
325N/A boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) {
325N/A super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo,
325N/A foundFaultTo, foundMessageId, foundRelatesTo);
325N/A
325N/A // find Req/Response or Oneway using WSDLModel(if it is availabe)
325N/A WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
325N/A // Taking care of protocol messages as they do not have any corresponding operations
325N/A if (wbo != null) {
325N/A // if two-way and no wsa:MessageID is found
325N/A if (!wbo.getOperation().isOneWay() && !foundMessageId) {
325N/A throw new MissingAddressingHeaderException(addressingVersion.messageIDTag,packet);
325N/A }
325N/A }
325N/A
325N/A }
325N/A
325N/A @Override
325N/A protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
325N/A return getResponseRequirement(wbo) == WSDLBoundOperation.ANONYMOUS.required;
325N/A }
325N/A
325N/A private WSDLBoundOperation.ANONYMOUS getResponseRequirement(@Nullable WSDLBoundOperation wbo) {
325N/A try {
325N/A if (af.getResponses() == AddressingFeature.Responses.ANONYMOUS) {
325N/A return WSDLBoundOperation.ANONYMOUS.required;
325N/A } else if (af.getResponses() == AddressingFeature.Responses.NON_ANONYMOUS) {
325N/A return WSDLBoundOperation.ANONYMOUS.prohibited;
325N/A }
325N/A } catch (NoSuchMethodError e) {
325N/A //Ignore error, defaut to optional
325N/A }
325N/A //wsaw wsdl binding case will have some value set on wbo
325N/A return wbo != null ? wbo.getAnonymous() : WSDLBoundOperation.ANONYMOUS.optional;
325N/A }
325N/A
325N/A @Override
325N/A protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
325N/A String replyToValue = null;
325N/A String faultToValue = null;
325N/A
325N/A if (replyTo != null)
325N/A replyToValue = replyTo.getAddress();
325N/A
325N/A if (faultTo != null)
325N/A faultToValue = faultTo.getAddress();
325N/A WSDLBoundOperation.ANONYMOUS responseRequirement = getResponseRequirement(wbo);
325N/A
325N/A switch (responseRequirement) {
325N/A case prohibited:
325N/A if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A
325N/A if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A break;
325N/A case required:
325N/A if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A
325N/A if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A break;
325N/A default:
325N/A // ALL: no check
325N/A }
325N/A }
325N/A
325N/A /*
325N/A @Override
325N/A protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
325N/A return getResponseRequirement(wbo) == AddressingFeature.Responses.ANONYMOUS;
325N/A }
325N/A
325N/A private AddressingFeature.Responses getResponseRequirement(@Nullable WSDLBoundOperation wbo) {
325N/A if (af.getResponses() == AddressingFeature.Responses.ALL && wbo != null) {
325N/A //wsaw wsdl binding case will have some value set on wbo
325N/A WSDLBoundOperation.ANONYMOUS anon = wbo.getAnonymous();
325N/A if (wbo.getAnonymous() == WSDLBoundOperation.ANONYMOUS.required)
325N/A return AddressingFeature.Responses.ANONYMOUS;
325N/A else if (wbo.getAnonymous() == WSDLBoundOperation.ANONYMOUS.prohibited)
325N/A return AddressingFeature.Responses.NON_ANONYMOUS;
325N/A else
325N/A return AddressingFeature.Responses.ALL;
325N/A
325N/A } else
325N/A return af.getResponses();
325N/A }
325N/A
325N/A @Override
325N/A protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
325N/A String replyToValue = null;
325N/A String faultToValue = null;
325N/A
325N/A if (replyTo != null)
325N/A replyToValue = replyTo.getAddress();
325N/A
325N/A if (faultTo != null)
325N/A faultToValue = faultTo.getAddress();
325N/A AddressingFeature.Responses responseRequirement = getResponseRequirement(wbo);
325N/A
325N/A switch (responseRequirement) {
325N/A case NON_ANONYMOUS:
325N/A if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A
325N/A if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A break;
325N/A case ANONYMOUS:
325N/A if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A
325N/A if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri))
325N/A throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
325N/A break;
325N/A default:
325N/A // ALL: no check
325N/A }
325N/A }
325N/A */
325N/A}