1 /*
   2  * Copyright (c) 1997, 2013, 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.addressing.v200408;
  27 
  28 import com.sun.xml.internal.ws.addressing.WsaClientTube;
  29 import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
  30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
  31 import com.sun.xml.internal.ws.api.WSBinding;
  32 import com.sun.xml.internal.ws.api.message.AddressingUtils;
  33 import com.sun.xml.internal.ws.api.message.Packet;
  34 import com.sun.xml.internal.ws.api.pipe.Tube;
  35 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
  36 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressing;
  37 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature;
  38 
  39 /**
  40  * @author Rama Pulavarthi
  41  */
  42 public class MemberSubmissionWsaClientTube extends WsaClientTube {
  43     private final MemberSubmissionAddressing.Validation validation;
  44 
  45     public MemberSubmissionWsaClientTube(WSDLPort wsdlPort, WSBinding binding, Tube next) {
  46         super(wsdlPort, binding, next);
  47         validation = binding.getFeature(MemberSubmissionAddressingFeature.class).getValidation();
  48 
  49     }
  50 
  51     public MemberSubmissionWsaClientTube(MemberSubmissionWsaClientTube that, TubeCloner cloner) {
  52         super(that, cloner);
  53         this.validation = that.validation;
  54 
  55     }
  56     public MemberSubmissionWsaClientTube copy(TubeCloner cloner) {
  57         return new MemberSubmissionWsaClientTube(this, cloner);
  58     }
  59 
  60     @Override
  61     protected void checkMandatoryHeaders(Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
  62                                          boolean foundFaultTo, boolean foundMessageID, boolean foundRelatesTo) {
  63         super.checkMandatoryHeaders(packet,foundAction,foundTo,foundReplyTo,foundFaultTo,foundMessageID,foundRelatesTo);
  64 
  65         // if no wsa:To header is found
  66         if (!foundTo) {
  67             throw new MissingAddressingHeaderException(addressingVersion.toTag,packet);
  68         }
  69 
  70         if (!validation.equals(MemberSubmissionAddressing.Validation.LAX)) {
  71 
  72             // if it is not one-way, response must contain wsa:RelatesTo
  73             // RelatesTo required as per
  74             // Table 5-3 of http://www.w3.org/TR/2006/WD-ws-addr-wsdl-20060216/#wsdl11requestresponse
  75             if (expectReply && (packet.getMessage() != null) && !foundRelatesTo) {
  76                 String action = AddressingUtils.getAction(packet.getMessage().getHeaders(), addressingVersion, soapVersion);
  77                 // Don't check for AddressingFaults as
  78                 // Faults for requests with duplicate MessageId will have no wsa:RelatesTo
  79                 if (!packet.getMessage().isFault() || !action.equals(addressingVersion.getDefaultFaultAction())) {
  80                     throw new MissingAddressingHeaderException(addressingVersion.relatesToTag,packet);
  81                 }
  82             }
  83         }
  84     }
  85 }