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/* 27 * SOAPHandlerProcessor.java 28 * 29 * Created on February 8, 2006, 5:43 PM 30 * 31 * 32 */ 33 34package com.sun.xml.internal.ws.handler; 35 36import com.sun.xml.internal.ws.api.WSBinding; 37import com.sun.xml.internal.ws.api.SOAPVersion; 38import com.sun.xml.internal.ws.api.message.Message; 39import com.sun.xml.internal.ws.api.message.Messages; 40import com.sun.xml.internal.ws.encoding.soap.SOAP12Constants; 41import com.sun.xml.internal.ws.encoding.soap.SOAPConstants; 42import java.util.List; 43import java.util.logging.Level; 44import javax.xml.namespace.QName; 45import javax.xml.ws.ProtocolException; 46import javax.xml.ws.handler.Handler; 47 48/** 49 * 50 * @author WS Development Team 51 */ 52final class SOAPHandlerProcessor<C extends MessageUpdatableContext> extends HandlerProcessor<C> { 53 54 /** 55 * Creates a new instance of SOAPHandlerProcessor 56 */ 57 public SOAPHandlerProcessor(boolean isClient, HandlerTube owner, WSBinding binding, List<? extends Handler> chain) { 58 super(owner, binding, chain); 59 this.isClient = isClient; 60 } 61 62 /** 63 * Replace the message in the given message context with a 64 * fault message. If the context already contains a fault 65 * message, then return without changing it. 66 * 67 * <p>This method should only be called during a request, 68 * because during a response an exception from a handler 69 * is dispatched rather than replacing the message with 70 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY 71 * to determine whether it is being called on the client 72 * or the server side. If this changes in the spec, then 73 * something else will need to be passed to the method 74 * to determine whether the fault code is client or server. 75 */ 76 final void insertFaultMessage(C context, 77 ProtocolException exception) { 78 try { 79 if(!context.getPacketMessage().isFault()) { 80 Message faultMessage = Messages.create(binding.getSOAPVersion(), 81 exception,determineFaultCode(binding.getSOAPVersion())); 82 context.setPacketMessage(faultMessage); 83 } 84 } catch (Exception e) { 85 // severe since this is from runtime and not handler 86 logger.log(Level.SEVERE, 87 "exception while creating fault message in handler chain", e); 88 throw new RuntimeException(e); 89 } 90 } 91 92 /** 93 * <p>Figure out if the fault code local part is client, 94 * server, sender, receiver, etc. This is called by 95 * insertFaultMessage. 96 */ 97 private QName determineFaultCode(SOAPVersion soapVersion) { 98 return isClient ? soapVersion.faultCodeClient : soapVersion.faultCodeServer; 99 } 100 101} 102