001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.handler;
020:
021: import org.apache.axis2.jaxws.ExceptionFactory;
022: import org.apache.axis2.jaxws.core.MessageContext;
023: import org.apache.axis2.jaxws.i18n.Messages;
024: import org.apache.axis2.jaxws.message.Block;
025: import org.apache.axis2.jaxws.message.Message;
026: import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
027: import org.apache.axis2.jaxws.message.factory.BlockFactory;
028: import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
029: import org.apache.axis2.jaxws.message.factory.MessageFactory;
030: import org.apache.axis2.jaxws.registry.FactoryRegistry;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: import javax.xml.bind.JAXBContext;
035: import javax.xml.namespace.QName;
036: import javax.xml.soap.SOAPConstants;
037: import javax.xml.soap.SOAPMessage;
038: import javax.xml.stream.XMLStreamException;
039:
040: import java.util.ArrayList;
041: import java.util.HashSet;
042: import java.util.List;
043: import java.util.Set;
044:
045: /**
046: * The SOAPMessageContext is the context handed to SOAP-based application handlers. It provides
047: * access to the SOAP message that represents the request or response via SAAJ. It also allows
048: * access to any properties that have been registered and set on the MessageContext.
049: */
050: public class SoapMessageContext extends BaseMessageContext implements
051: javax.xml.ws.handler.soap.SOAPMessageContext {
052: private static final Log log = LogFactory
053: .getLog(SoapMessageContext.class);
054:
055: public SoapMessageContext(MessageContext messageCtx) {
056: super (messageCtx);
057: }
058:
059: public Object[] getHeaders(QName qname, JAXBContext jaxbcontext,
060: boolean flag) {
061: if (log.isDebugEnabled()) {
062: log.debug("Getting all Headers for Qname: " + qname);
063: }
064:
065: if (qname == null) {
066: if (log.isDebugEnabled()) {
067: log.debug("Invalid QName, QName cannot be null");
068: }
069: ExceptionFactory.makeWebServiceException(Messages
070: .getMessage(""));
071: }
072: if (jaxbcontext == null) {
073: if (log.isDebugEnabled()) {
074: log
075: .debug("Invalid JAXBContext, JAXBContext cannot be null");
076: }
077: ExceptionFactory.makeWebServiceException(Messages
078: .getMessage("SOAPMessageContextErr2"));
079: }
080:
081: if (flag == false) {
082: //TODO: Implement, In this case we need to only return headers targetted at roles
083: // currently played by this SOAPNode.
084:
085: }
086: List<Object> list = new ArrayList<Object>();
087: String namespace = qname.getNamespaceURI();
088: String localPart = qname.getLocalPart();
089: BlockFactory blockFactory = (JAXBBlockFactory) FactoryRegistry
090: .getFactory(JAXBBlockFactory.class);
091: Message m = messageCtx.getMessage();
092: JAXBBlockContext jbc = new JAXBBlockContext(jaxbcontext);
093: if (m.getNumHeaderBlocks() > 0) {
094: Block hb = m.getHeaderBlock(namespace, localPart, jbc,
095: blockFactory);
096: if (hb != null) {
097: try {
098:
099: Object bo = hb.getBusinessObject(false);
100: if (bo != null) {
101: if (log.isDebugEnabled()) {
102: log.debug("Extracted BO from Header Block");
103: }
104: list.add(bo);
105: }
106:
107: } catch (XMLStreamException e) {
108: ExceptionFactory.makeWebServiceException(e);
109: }
110: }
111: }
112: return list.toArray(new Object[0]);
113:
114: }
115:
116: public SOAPMessage getMessage() {
117: Message msg = messageCtx.getMEPContext().getMessageObject();
118: return msg.getAsSOAPMessage();
119: }
120:
121: public Set<String> getRoles() {
122: // TODO implement better. We should be doing smarter checking of the header,
123: // especially for the Ultimate receiver actor/role
124:
125: /*
126: * JAVADOC to help get this implemented correctly:
127: *
128: * Gets the SOAP actor roles associated with an execution of the handler
129: * chain. Note that SOAP actor roles apply to the SOAP node and are
130: * managed using SOAPBinding.setRoles and SOAPBinding.getRoles. Handler
131: * instances in the handler chain use this information about the SOAP
132: * actor roles to process the SOAP header blocks. Note that the SOAP
133: * actor roles are invariant during the processing of SOAP message
134: * through the handler chain.
135: */
136:
137: HashSet<String> roles = new HashSet<String>(3);
138: // JAX-WS 10.1.1.1 defaults:
139: // SOAP 1.1
140: roles.add(SOAPConstants.URI_SOAP_ACTOR_NEXT);
141: // SOAP 1.2
142: roles.add(SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER);
143: roles.add(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT);
144: return roles;
145: }
146:
147: public void setMessage(SOAPMessage soapmessage) {
148: // TODO I don't like this at all.
149: try {
150: Message msg = ((MessageFactory) FactoryRegistry
151: .getFactory(MessageFactory.class))
152: .createFrom(soapmessage);
153: messageCtx.getMEPContext().setMessage(msg);
154: } catch (XMLStreamException e) {
155: // TODO log it, and throw something?
156: }
157: }
158: }
|