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.protocol.soap;
  27 
  28 import com.sun.xml.internal.ws.api.message.Packet;
  29 import com.sun.xml.internal.ws.api.pipe.*;
  30 import com.sun.xml.internal.ws.client.HandlerConfiguration;
  31 import javax.xml.namespace.QName;
  32 import java.util.Set;
  33 
  34 /**
  35  * @author Rama Pulavarthi
  36  */
  37 
  38 public class ServerMUTube extends MUTube {
  39 
  40     private ServerTubeAssemblerContext tubeContext;
  41     private final Set<String> roles;
  42     private final Set<QName> handlerKnownHeaders;
  43 
  44     public ServerMUTube(ServerTubeAssemblerContext tubeContext, Tube next) {
  45         super(tubeContext.getEndpoint().getBinding(), next);
  46 
  47         this.tubeContext = tubeContext;
  48 
  49         //On Server, HandlerConfiguration does n't change after publish, so store locally
  50         HandlerConfiguration handlerConfig = binding.getHandlerConfig();
  51         roles = handlerConfig.getRoles();
  52         handlerKnownHeaders = binding.getKnownHeaders();
  53     }
  54 
  55     protected ServerMUTube(ServerMUTube that, TubeCloner cloner) {
  56         super(that,cloner);
  57         tubeContext = that.tubeContext;
  58         roles = that.roles;
  59         handlerKnownHeaders = that.handlerKnownHeaders;
  60     }
  61 
  62     /**
  63      * Do MU Header Processing on incoming message (request)
  64      * @return
  65      *      if all the headers in the packet are understood, returns action such that
  66      *      next pipe will be inovked.
  67      *      if all the headers in the packet are not understood, returns action such that
  68      *      SOAPFault Message is sent to previous pipes.
  69      */
  70     @Override
  71     public NextAction processRequest(Packet request) {
  72         Set<QName> misUnderstoodHeaders = getMisUnderstoodHeaders(request.getMessage().getHeaders(),roles, handlerKnownHeaders);
  73         if((misUnderstoodHeaders == null)  || misUnderstoodHeaders.isEmpty()) {
  74             return doInvoke(super.next, request);
  75         }
  76         return doReturnWith(request.createServerResponse(createMUSOAPFaultMessage(misUnderstoodHeaders),
  77                 tubeContext.getWsdlModel(), tubeContext.getSEIModel(), tubeContext.getEndpoint().getBinding()));
  78     }
  79 
  80     public ServerMUTube copy(TubeCloner cloner) {
  81         return new ServerMUTube(this,cloner);
  82     }
  83 
  84 }