List of usage examples for javax.xml.namespace QName toString
public String toString()
From source file:org.apache.axis.encoding.ser.BeanDeserializer.java
/** * Deserializer interface called on each child element encountered in * the XML stream.//from w w w . ja v a2s. com * @param namespace is the namespace of the child element * @param localName is the local name of the child element * @param prefix is the prefix used on the name of the child element * @param attributes are the attributes of the child element * @param context is the deserialization context. * @return is a Deserializer to use to deserialize a child (must be * a derived class of SOAPHandler) or null if no deserialization should * be performed. */ public SOAPHandler onStartChild(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) throws SAXException { handleMixedContent(); BeanPropertyDescriptor propDesc = null; FieldDesc fieldDesc = null; SOAPConstants soapConstants = context.getSOAPConstants(); String encodingStyle = context.getEncodingStyle(); boolean isEncoded = Constants.isSOAP_ENC(encodingStyle); QName elemQName = new QName(namespace, localName); // The collectionIndex needs to be reset for Beans with multiple arrays if ((prevQName == null) || (!prevQName.equals(elemQName))) { collectionIndex = -1; } boolean isArray = false; QName itemQName = null; if (typeDesc != null) { // Lookup the name appropriately (assuming an unqualified // name for SOAP encoding, using the namespace otherwise) String fieldName = typeDesc.getFieldNameForElement(elemQName, isEncoded); propDesc = (BeanPropertyDescriptor) propertyMap.get(fieldName); fieldDesc = typeDesc.getFieldByName(fieldName); if (fieldDesc != null) { ElementDesc element = (ElementDesc) fieldDesc; isArray = element.isMaxOccursUnbounded(); itemQName = element.getItemQName(); } } if (propDesc == null) { // look for a field by this name. propDesc = (BeanPropertyDescriptor) propertyMap.get(localName); } // Workaround if (propDesc == null) { StringBuffer sb = new StringBuffer(); sb.append(Character.toLowerCase(localName.charAt(0))); if (localName.length() > 1) sb.append(localName.substring(1)); // look for a field by this name. propDesc = (BeanPropertyDescriptor) propertyMap.get(sb.toString()); } // try and see if this is an xsd:any namespace="##any" element before // reporting a problem if (propDesc == null || (((prevQName != null) && prevQName.equals(elemQName) && !(propDesc.isIndexed() || isArray) && getAnyPropertyDesc() != null))) { // try to put unknown elements into a SOAPElement property, if // appropriate prevQName = elemQName; propDesc = getAnyPropertyDesc(); if (propDesc != null) { try { MessageElement[] curElements = (MessageElement[]) propDesc.get(value); int length = 0; if (curElements != null) { length = curElements.length; } MessageElement[] newElements = new MessageElement[length + 1]; if (curElements != null) { System.arraycopy(curElements, 0, newElements, 0, length); } MessageElement thisEl = context.getCurElement(); newElements[length] = thisEl; propDesc.set(value, newElements); // if this is the first pass through the MessageContexts // make sure that the correct any element is set, // that is the child of the current MessageElement, however // on the first pass this child has not been set yet, so // defer it to the child SOAPHandler if (!localName.equals(thisEl.getName())) { return new SOAPHandler(newElements, length); } return new SOAPHandler(); } catch (Exception e) { throw new SAXException(e); } } } if (propDesc == null) { // No such field throw new SAXException(Messages.getMessage("badElem00", javaType.getName(), localName)); } prevQName = elemQName; // Get the child's xsi:type if available QName childXMLType = context.getTypeFromAttributes(namespace, localName, attributes); String href = attributes.getValue(soapConstants.getAttrHref()); Class fieldType = propDesc.getType(); // If no xsi:type or href, check the meta-data for the field if (childXMLType == null && fieldDesc != null && href == null) { childXMLType = fieldDesc.getXmlType(); if (itemQName != null) { // This is actually a wrapped literal array and should be // deserialized with the ArrayDeserializer childXMLType = Constants.SOAP_ARRAY; fieldType = propDesc.getActualType(); } else { childXMLType = fieldDesc.getXmlType(); } } // Get Deserializer for child, default to using DeserializerImpl Deserializer dSer = getDeserializer(childXMLType, fieldType, href, context); // It is an error if the dSer is not found - the only case where we // wouldn't have a deserializer at this point is when we're trying // to deserialize something we have no clue about (no good xsi:type, // no good metadata). if (dSer == null) { dSer = context.getDeserializerForClass(propDesc.getType()); } // Fastpath nil checks... if (context.isNil(attributes)) { if ((propDesc.isIndexed() || isArray)) { if (!((dSer != null) && (dSer instanceof ArrayDeserializer))) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); addChildDeserializer(dSer); return (SOAPHandler) dSer; } } return null; } if (dSer == null) { throw new SAXException(Messages.getMessage("noDeser00", childXMLType.toString())); } if (constructorToUse != null) { if (constructorTarget == null) { constructorTarget = new ConstructorTarget(constructorToUse, this); } dSer.registerValueTarget(constructorTarget); } else if (propDesc.isWriteable()) { // If this is an indexed property, and the deserializer we found // was NOT the ArrayDeserializer, this is a non-SOAP array: // <bean> // <field>value1</field> // <field>value2</field> // ... // In this case, we want to use the collectionIndex and make sure // the deserialized value for the child element goes into the // right place in the collection. // Register value target if ((itemQName != null || propDesc.isIndexed() || isArray) && !(dSer instanceof ArrayDeserializer)) { collectionIndex++; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc, collectionIndex)); } else { // If we're here, the element maps to a single field value, // whether that be a "basic" type or an array, so use the // normal (non-indexed) BeanPropertyTarget form. collectionIndex = -1; dSer.registerValueTarget(new BeanPropertyTarget(value, propDesc)); } } // Let the framework know that we need this deserializer to complete // for the bean to complete. addChildDeserializer(dSer); return (SOAPHandler) dSer; }
From source file:org.apache.axis.handlers.soap.MustUnderstandChecker.java
public void invoke(MessageContext msgContext) throws AxisFault { // Do SOAP semantics here if (log.isDebugEnabled()) { log.debug(Messages.getMessage("semanticCheck00")); }/*from w w w. j a va2 s .c o m*/ Message msg = msgContext.getCurrentMessage(); if (msg == null) return; // nothing to do if there's no message SOAPEnvelope env = msg.getSOAPEnvelope(); Vector headers = null; if (service != null) { ArrayList acts = service.getActors(); headers = env.getHeadersByActor(acts); } else { headers = env.getHeaders(); } // 1. Check mustUnderstands Vector misunderstoodHeaders = null; Enumeration enumeration = headers.elements(); while (enumeration.hasMoreElements()) { SOAPHeaderElement header = (SOAPHeaderElement) enumeration.nextElement(); // Ignore header, if it is a parameter to the operation if (msgContext != null && msgContext.getOperation() != null) { OperationDesc oper = msgContext.getOperation(); if (oper.getParamByQName(header.getQName()) != null) { continue; } } if (header.getMustUnderstand() && !header.isProcessed()) { if (misunderstoodHeaders == null) misunderstoodHeaders = new Vector(); misunderstoodHeaders.addElement(header); } } SOAPConstants soapConstants = msgContext.getSOAPConstants(); // !!! we should indicate SOAP1.2 compliance via the // MessageContext, not a boolean here.... if (misunderstoodHeaders != null) { AxisFault fault = new AxisFault(soapConstants.getMustunderstandFaultQName(), null, null, null, null, null); StringBuffer whatWasMissUnderstood = new StringBuffer(256); enumeration = misunderstoodHeaders.elements(); while (enumeration.hasMoreElements()) { SOAPHeaderElement badHeader = (SOAPHeaderElement) enumeration.nextElement(); QName badQName = new QName(badHeader.getNamespaceURI(), badHeader.getName()); if (whatWasMissUnderstood.length() != 0) whatWasMissUnderstood.append(", "); whatWasMissUnderstood.append(badQName.toString()); // !!! If SOAP 1.2, insert misunderstood fault headers here if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { SOAPHeaderElement newHeader = new SOAPHeaderElement(Constants.URI_SOAP12_ENV, Constants.ELEM_NOTUNDERSTOOD); newHeader.addAttribute(null, Constants.ATTR_QNAME, badQName); fault.addHeader(newHeader); } } fault.setFaultString(Messages.getMessage("noUnderstand00", whatWasMissUnderstood.toString())); throw fault; } }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Method writeSchemaElementDecl//from w w w. j av a 2 s . c om * * @param qname * @param element * @throws AxisFault */ public void writeSchemaElementDecl(QName qname, Element element) throws AxisFault { if (writtenElementQNames.contains(qname)) { throw new AxisFault(Constants.FAULT_SERVER_GENERAL, Messages.getMessage("duplicateSchemaElement", qname.toString()), null, null); } writeSchemaElement(qname.getNamespaceURI(), element); writtenElementQNames.add(qname); }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Create a schema type element (either simpleType or complexType) for * the particular type/qName combination. If the type is named, we * handle inserting the new type into the appropriate <schema> * in the WSDL types section. If the type is anonymous, we append the * definition underneath the Element which was passed as the container * (typically a field of a higher-level type or a parameter in a wrapped * operation)./* w w w . j av a 2 s .c o m*/ * * @param type Java type to write * @param qName the desired type QName * @param containingElement a schema element ("element" or "attribute") * which should either receive a type="" attribute decoration * (for named types) or a child element defining an anonymous * type * @return true if the type was already present or was added, false if there was a problem * @throws AxisFault */ private boolean makeTypeElement(Class type, QName qName, Element containingElement) throws AxisFault { // Get a corresponding QName if one is not provided if ((qName == null) || Constants.equals(Constants.SOAP_ARRAY, qName)) { qName = getTypeQName(type); } boolean anonymous = isAnonymousType(qName); // Can't have an anonymous type outside of a containing element if (anonymous && (containingElement == null)) { throw new AxisFault(Messages.getMessage("noContainerForAnonymousType", qName.toString())); } // If we've already got this type (because it's a native type or // because we've already written it), just add the type="" attribute // (if appropriate) and return. if (!addToTypesList(qName) && !anonymous) { if (containingElement != null) { containingElement.setAttribute("type", getQNameString(qName)); } return true; } // look up the serializer in the TypeMappingRegistry SerializerFactory factory; factory = (SerializerFactory) tm.getSerializer(type, qName); // If no factory is found, use the BeanSerializerFactory // if applicable, otherwise issue errors and treat as an anyType if (factory == null) { if (isEnumClass(type)) { factory = new EnumSerializerFactory(type, qName); } else if (isBeanCompatible(type, true)) { factory = new BeanSerializerFactory(type, qName); } else { return false; } } // factory is not null Serializer ser = (Serializer) factory.getSerializerAs(Constants.AXIS_SAX); // if we can't get a serializer, that is bad. if (ser == null) { throw new AxisFault(Messages.getMessage("NoSerializer00", type.getName())); } Element typeEl; try { typeEl = ser.writeSchema(type, this); } catch (Exception e) { throw AxisFault.makeFault(e); } // If this is an anonymous type, just make the type element a child // of containingElement. If not, set the "type" attribute of // containingElement to the right QName, and make sure the type is // correctly written into the appropriate <schema> element. if (anonymous) { if (typeEl == null) { containingElement.setAttribute("type", getQNameString(getTypeQName(type))); } else { containingElement.appendChild(typeEl); } } else { if (typeEl != null) { typeEl.setAttribute("name", qName.getLocalPart()); // Write the type in the appropriate <schema> writeSchemaTypeDecl(qName, typeEl); } if (containingElement != null) { containingElement.setAttribute("type", getQNameString(qName)); } } // store the mapping of type qname and its correspoding java type if (emitter != null) { emitter.getQName2ClassMap().put(qName, type); } return true; }
From source file:org.apache.axis2.client.Options.java
/** * This method checks to see if additional work needs to be * done in order to complete the object reconstitution. * Some parts of the object restored from the readExternal() * cannot be completed until we have a configurationContext * from the active engine. The configurationContext is used * to help this object to plug back into the engine's * configuration and deployment objects. * * @param cc The configuration context object representing the active configuration *//*from w ww .j a v a 2 s.c o m*/ public void activate(ConfigurationContext cc) { // see if there's any work to do if (!needsToBeReconciled) { // return quick return; } String logCorrelationIDString = getLogCorrelationIDString(); // use the supplied configuration context // get the axis configuration AxisConfiguration axisConfig = cc.getAxisConfiguration(); // We previously saved metaTransportIn; restore it if (metaTransportIn != null) { QName qin = metaTransportIn.getQName(); TransportInDescription tmpIn = null; try { tmpIn = axisConfig.getTransportIn(qin.getLocalPart()); } catch (Exception exin) { // if a fault is thrown, log it and continue log.trace(logCorrelationIDString + "activate(): exception caught when getting the TransportInDescription [" + qin.toString() + "] from the AxisConfiguration [" + exin.getClass().getName() + " : " + exin.getMessage() + "]"); } if (tmpIn != null) { transportIn = tmpIn; } else { log.trace(logCorrelationIDString + "activate(): No TransportInDescription found for [" + qin.toString() + "]"); transportIn = null; } } else { log.trace(logCorrelationIDString + "activate(): No TransportInDescription "); transportIn = null; } // We previously saved metaTransportOut; restore it if (metaTransportOut != null) { QName qout = metaTransportOut.getQName(); TransportOutDescription tmpOut = null; try { tmpOut = axisConfig.getTransportOut(qout.getLocalPart()); } catch (Exception exout) { // if a fault is thrown, log it and continue log.trace(logCorrelationIDString + "activate(): exception caught when getting the TransportOutDescription [" + qout.toString() + "] from the AxisConfiguration [" + exout.getClass().getName() + " : " + exout.getMessage() + "]"); } if (tmpOut != null) { transportOut = tmpOut; } else { log.trace(logCorrelationIDString + "activate(): No TransportOutDescription found for [" + qout.toString() + "]"); transportOut = null; } } else { log.trace(logCorrelationIDString + "activate(): No TransportOutDescription "); transportOut = null; } // We previously saved metaListener; restore it if (metaListener != null) { // see if we can find an existing object String listenerClass = metaListener.getClassName(); log.trace(logCorrelationIDString + "activate(): TransportListener found for [" + listenerClass + "] "); } else { listener = null; log.trace(logCorrelationIDString + "activate(): No TransportListener "); } //------------------------------------------------------- // done, reset the flag //------------------------------------------------------- needsToBeReconciled = false; }
From source file:org.apache.axis2.context.externalize.ActivateUtils.java
/** * Find the AxisOperation object that matches the criteria * /*from www . j a v a2s . com*/ * @param axisConfig The AxisConfiguration object * @param opClassName the class name string for the target object * (could be a derived class) * @param opQName the name associated with the operation * @return the AxisOperation object that matches the given criteria */ public static AxisOperation findOperation(AxisConfiguration axisConfig, String opClassName, QName opQName) { HashMap services = axisConfig.getServices(); Iterator its = services.values().iterator(); while (its.hasNext()) { AxisService service = (AxisService) its.next(); Iterator ito = service.getOperations(); while (ito.hasNext()) { AxisOperation operation = (AxisOperation) ito.next(); String tmpOpName = operation.getClass().getName(); QName tmpOpQName = operation.getName(); if ((tmpOpName.equals(opClassName)) && (tmpOpQName.equals(opQName))) { // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findOperation(axisCfg): returning [" + opClassName + "] [" + opQName.toString() + "]"); } return operation; } } } // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findOperation(axisCfg): [" + opClassName + "] [" + opQName.toString() + "] returning [null]"); } return null; }
From source file:org.apache.axis2.context.externalize.ActivateUtils.java
/** * Find the AxisOperation object that matches the criteria * //from w w w. ja v a 2s . co m * @param service The AxisService object * @param opClassName The class name string for the target object * (could be a derived class) * @param opQName the name associated with the operation * @return the AxisOperation object that matches the given criteria */ public static AxisOperation findOperation(AxisService service, String opClassName, QName opQName) { if (service == null) { return null; } Iterator ito = service.getOperations(); // Previous versions of Axis2 didn't use a namespace on the operation name, so they wouldn't // have externalized a namespace. If that's the case, only compare the localPart of the // operation name String namespace = opQName.getNamespaceURI(); boolean ignoreNamespace = false; if (namespace == null || "".equals(namespace)) { ignoreNamespace = true; } while (ito.hasNext()) { AxisOperation operation = (AxisOperation) ito.next(); String tmpOpName = operation.getClass().getName(); QName tmpOpQName = operation.getName(); if ((tmpOpName.equals(opClassName)) && ((ignoreNamespace && (tmpOpQName.getLocalPart().equals(opQName.getLocalPart())) || (tmpOpQName.equals(opQName))))) { if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findOperation(service): ignoreNamespace [" + ignoreNamespace + "] returning [" + opClassName + "] [" + opQName.toString() + "]"); } return operation; } } // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findOperation(service): ignoreNamespace [" + ignoreNamespace + " classname [" + opClassName + "] QName [" + opQName.toString() + "] returning [null]"); } return null; }
From source file:org.apache.axis2.context.externalize.ActivateUtils.java
/** * Find the AxisMessage object that matches the criteria * /*from w ww . j a v a2 s. com*/ * @param op The AxisOperation object * @param msgName The name associated with the message * @param msgElementName The name associated with the message element * @return the AxisMessage object that matches the given criteria */ public static AxisMessage findMessage(AxisOperation op, String msgName, String msgElementName) { // Several kinds of AxisMessages can be associated with a particular // AxisOperation. The kinds of AxisMessages that are typically // accessible are associated with "in" and "out". // There are also different kinds of AxisOperations, and each // type of AxisOperation can have its own mix of AxisMessages // depending on the style of message exchange pattern (mep) if (op == null) { // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findMessage(): [" + msgName + "] [" + msgElementName + "] returning [null] - no AxisOperation"); } return null; } if (msgName == null) { // nothing to match with, expect to match against a name // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findMessage(): [" + msgName + "] [" + msgElementName + "] returning [null] - message name is not set"); } return null; } String tmpName = null; String tmpElementName = null; //------------------------------------- // first try the "out" message //------------------------------------- AxisMessage out = null; try { out = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); } catch (Exception ex) { // just absorb the exception } if (out != null) { tmpName = out.getName(); QName tmpQout = out.getElementQName(); if (tmpQout != null) { tmpElementName = tmpQout.toString(); } } // check the criteria for a match boolean matching = matchMessageNames(tmpName, tmpElementName, msgName, msgElementName); if (matching) { // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findMessage(): returning OUT message [" + msgName + "] [" + msgElementName + "] "); } return out; } //------------------------------------- // next, try the "in" message //------------------------------------- AxisMessage in = null; try { in = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE); } catch (Exception ex) { // just absorb the exception } if (in != null) { tmpName = in.getName(); QName tmpQin = in.getElementQName(); if (tmpQin != null) { tmpElementName = tmpQin.toString(); } } else { tmpName = null; tmpElementName = null; } // check the criteria for a match matching = matchMessageNames(tmpName, tmpElementName, msgName, msgElementName); if (matching) { // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findMessage(): returning IN message [" + msgName + "] [" + msgElementName + "] "); } return in; } // if we got here, then no match was found // trace point if (log.isTraceEnabled()) { log.trace("ObjectStateUtils:findMessage(): [" + msgName + "] [" + msgElementName + "] returning [null]"); } return null; }
From source file:org.apache.axis2.context.MessageContext.java
/** * Save the contents of this MessageContext instance. * <p/>/*from w w w . j ava2s . c o m*/ * NOTE: Transient fields and static fields are not saved. * Also, objects that represent "static" data are * not saved, except for enough information to be * able to find matching objects when the message * context is re-constituted. * * @param o The stream to write the object contents to * @throws IOException */ public void writeExternal(ObjectOutput o) throws IOException { SafeObjectOutputStream out = SafeObjectOutputStream.install(o); String logCorrelationIDString = getLogIDString(); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): writing to output stream"); } //--------------------------------------------------------- // in order to handle future changes to the message // context definition, be sure to maintain the // object level identifiers //--------------------------------------------------------- // serialization version ID out.writeLong(serialVersionUID); // revision ID out.writeInt(revisionID); //--------------------------------------------------------- // various simple fields //--------------------------------------------------------- // the type of execution flow for the message context out.writeInt(FLOW); // various flags out.writeBoolean(processingFault); out.writeBoolean(paused); out.writeBoolean(outputWritten); out.writeBoolean(newThreadRequired); out.writeBoolean(isSOAP11); out.writeBoolean(doingREST); out.writeBoolean(doingMTOM); out.writeBoolean(doingSwA); out.writeBoolean(responseWritten); out.writeBoolean(serverSide); out.writeLong(getLastTouchedTime()); out.writeObject(getLogCorrelationID()); //----------------------------------------------------------------------- // Create and initialize the OMOutputFormat for Message Externalization //----------------------------------------------------------------------- OMOutputFormat outputFormat = new OMOutputFormat(); outputFormat.setSOAP11(isSOAP11); boolean persistOptimized = getPersistOptimized(); if (persistOptimized) { outputFormat.setDoOptimize(true); } String charSetEnc = (String) getProperty(MessageContext.CHARACTER_SET_ENCODING); if (charSetEnc == null) { OperationContext opContext = getOperationContext(); if (opContext != null) { charSetEnc = (String) opContext.getProperty(MessageContext.CHARACTER_SET_ENCODING); } } if (charSetEnc == null) { charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING; } outputFormat.setCharSetEncoding(charSetEnc); // ---------------------------------------------------------- // Externalize the Message // ---------------------------------------------------------- MessageExternalizeUtils.writeExternal(out, this, logCorrelationIDString, outputFormat); // --------------------------------------------------------- // ArrayList executionChain // handler and phase related data //--------------------------------------------------------- // The strategy is to save some metadata about each // member of the list and the order of the list. // Then when the message context is re-constituted, // try to match up with phases and handlers on the // engine. // // Non-null list: // UTF - description string // boolean - active flag // int - current handler index // int - current phase index // int - expected number of entries in the list // objects - MetaDataEntry object per list entry // last entry will be empty MetaDataEntry // with MetaDataEntry.LAST_ENTRY marker // int - adjusted number of entries in the list // includes the last empty entry // // Empty list: // UTF - description string // boolean - empty flag //--------------------------------------------------------- out.writeUTF("executionChain"); if (executionChain != null && executionChain.size() > 0) { // start writing data to the output stream out.writeBoolean(ExternalizeConstants.ACTIVE_OBJECT); out.writeInt(currentHandlerIndex); out.writeInt(currentPhaseIndex); out.writeInt(executionChain.size()); // put the metadata on each member of the list into a buffer // match the current index with the actual saved list int nextIndex = 0; Iterator<Handler> i = executionChain.iterator(); while (i.hasNext()) { Object obj = i.next(); String objClass = obj.getClass().getName(); // start the meta data entry for this object MetaDataEntry mdEntry = new MetaDataEntry(); mdEntry.setClassName(objClass); // get the correct object-specific name String qnameAsString; if (obj instanceof Phase) { Phase phaseObj = (Phase) obj; qnameAsString = phaseObj.getName(); // add the list of handlers to the meta data setupPhaseList(phaseObj, mdEntry); } else if (obj instanceof Handler) { Handler handlerObj = (Handler) obj; qnameAsString = handlerObj.getName(); } else { // TODO: will there be any other kinds of objects in the execution Chain? qnameAsString = "NULL"; } mdEntry.setQName(qnameAsString); // update the index for the entry in the chain if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): ***BEFORE OBJ WRITE*** executionChain entry class [" + objClass + "] qname [" + qnameAsString + "]"); } out.writeObject(mdEntry); // update the index so that the index // now indicates the next entry that // will be attempted nextIndex++; if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): ***AFTER OBJ WRITE*** executionChain entry class [" + objClass + "] qname [" + qnameAsString + "]"); } } // end while entries in execution chain // done with the entries in the execution chain // add the end-of-list marker MetaDataEntry lastEntry = new MetaDataEntry(); lastEntry.setClassName(MetaDataEntry.END_OF_LIST); out.writeObject(lastEntry); nextIndex++; // nextIndex also gives us the number of entries // that were actually saved as opposed to the // number of entries in the executionChain out.writeInt(nextIndex); } else { // general case: handle "null" or "empty" out.writeBoolean(ExternalizeConstants.EMPTY_OBJECT); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): executionChain is NULL"); } } //--------------------------------------------------------- // LinkedList executedPhases //--------------------------------------------------------- // The strategy is to save some metadata about each // member of the list and the order of the list. // Then when the message context is re-constituted, // try to match up with phases and handlers on the // engine. // // Non-null list: // UTF - description string // boolean - active flag // int - expected number of entries in the list // objects - MetaDataEntry object per list entry // last entry will be empty MetaDataEntry // with MetaDataEntry.LAST_ENTRY marker // int - adjusted number of entries in the list // includes the last empty entry // // Empty list: // UTF - description string // boolean - empty flag //--------------------------------------------------------- out.writeUTF("executedPhases"); if (executedPhases != null && executedPhases.size() > 0) { // start writing data to the output stream out.writeBoolean(ExternalizeConstants.ACTIVE_OBJECT); out.writeInt(executedPhases.size()); // put the metadata on each member of the list into a buffer int execNextIndex = 0; Iterator<Handler> iterator = executedPhases.iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); String objClass = obj.getClass().getName(); // start the meta data entry for this object MetaDataEntry mdEntry = new MetaDataEntry(); mdEntry.setClassName(objClass); // get the correct object-specific name String qnameAsString; if (obj instanceof Phase) { Phase inPhaseObj = (Phase) obj; qnameAsString = inPhaseObj.getName(); // add the list of handlers to the meta data setupPhaseList(inPhaseObj, mdEntry); } else if (obj instanceof Handler) { Handler inHandlerObj = (Handler) obj; qnameAsString = inHandlerObj.getName(); } else { // TODO: will there be any other kinds of objects in the list qnameAsString = "NULL"; } mdEntry.setQName(qnameAsString); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): ***BEFORE Executed List OBJ WRITE*** executedPhases entry class [" + objClass + "] qname [" + qnameAsString + "]"); } out.writeObject(mdEntry); // update the index so that the index // now indicates the next entry that // will be attempted execNextIndex++; if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): " + "***AFTER Executed List OBJ WRITE*** " + "executedPhases entry class [" + objClass + "] " + "qname [" + qnameAsString + "]"); } } // end while entries in execution chain // done with the entries in the execution chain // add the end-of-list marker MetaDataEntry lastEntry = new MetaDataEntry(); lastEntry.setClassName(MetaDataEntry.END_OF_LIST); out.writeObject(lastEntry); execNextIndex++; // execNextIndex also gives us the number of entries // that were actually saved as opposed to the // number of entries in the executedPhases out.writeInt(execNextIndex); } else { // general case: handle "null" or "empty" out.writeBoolean(ExternalizeConstants.EMPTY_OBJECT); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): executedPhases is NULL"); } } //--------------------------------------------------------- // options //--------------------------------------------------------- // before saving the Options, make sure there is a message ID String tmpID = getMessageID(); if (tmpID == null) { // get an id to use when restoring this object tmpID = UIDGenerator.generateUID(); setMessageID(tmpID); } if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): message ID [" + tmpID + "]"); } out.writeUTF("options"); out.writeObject(options); //--------------------------------------------------------- // operation //--------------------------------------------------------- // axis operation //--------------------------------------------------------- out.writeUTF("axisOperation"); metaAxisOperation = null; if (axisOperation != null) { // TODO: may need to include the meta data for the axis service that is // the parent of the axis operation // make sure the axis operation has a name associated with it QName aoTmpQName = axisOperation.getName(); if (aoTmpQName == null) { aoTmpQName = new QName(ExternalizeConstants.EMPTY_MARKER); axisOperation.setName(aoTmpQName); } metaAxisOperation = new MetaDataEntry(axisOperation.getClass().getName(), axisOperation.getName().toString()); } out.writeObject(metaAxisOperation); //--------------------------------------------------------- // operation context //--------------------------------------------------------- // The OperationContext has pointers to MessageContext objects. // In order to avoid having multiple copies of the object graph // being saved at different points in the serialization, // it is important to isolate this message context object. out.writeUTF("operationContext"); if (operationContext != null) { operationContext.isolateMessageContext(this); } out.writeObject(operationContext); //--------------------------------------------------------- // service //--------------------------------------------------------- // axis service //------------------------- // this is expected to be the parent of the axis operation object out.writeUTF("axisService"); metaAxisService = null; if (axisService != null) { String serviceAndPortNames = ActivateUtils.getAxisServiceExternalizeExtraName(axisService); // If there is a service & port QName stored on the AxisService then write it out so // it can be used during deserialization to hook up the message context to the // correct AxisService. metaAxisService = new MetaDataEntry(axisService.getClass().getName(), axisService.getName(), serviceAndPortNames); } out.writeObject(metaAxisService); //------------------------- // serviceContextID string //------------------------- out.writeObject(serviceContextID); //------------------------- // serviceContext //------------------------- // is this the same as the parent of the OperationContext? boolean isParent = false; out.writeUTF("serviceContext"); if (operationContext != null) { ServiceContext opctxParent = operationContext.getServiceContext(); if (serviceContext != null) { if (serviceContext.equals(opctxParent)) { // the ServiceContext is the parent of the OperationContext isParent = true; } } } if (serviceContext == null) { out.writeBoolean(ExternalizeConstants.EMPTY_OBJECT); } else { out.writeBoolean(ExternalizeConstants.ACTIVE_OBJECT); out.writeBoolean(isParent); // only write out the object if it is not the parent if (!isParent) { out.writeObject(serviceContext); } } //--------------------------------------------------------- // axisServiceGroup //--------------------------------------------------------- out.writeUTF("axisServiceGroup"); metaAxisServiceGroup = null; if (axisServiceGroup != null) { metaAxisServiceGroup = new MetaDataEntry(axisServiceGroup.getClass().getName(), axisServiceGroup.getServiceGroupName()); } out.writeObject(metaAxisServiceGroup); //----------------------------- // serviceGroupContextId string //----------------------------- out.writeObject(serviceGroupContextId); //------------------------- // serviceGroupContext //------------------------- // is this the same as the parent of the ServiceContext? isParent = false; out.writeUTF("serviceGroupContext"); if (serviceContext != null) { ServiceGroupContext srvgrpctxParent = (ServiceGroupContext) serviceContext.getParent(); if (serviceGroupContext != null) { if (serviceGroupContext.equals(srvgrpctxParent)) { // the ServiceGroupContext is the parent of the ServiceContext isParent = true; } } } if (serviceGroupContext == null) { out.writeBoolean(ExternalizeConstants.EMPTY_OBJECT); } else { out.writeBoolean(ExternalizeConstants.ACTIVE_OBJECT); out.writeBoolean(isParent); // only write out the object if it is not the parent if (!isParent) { out.writeObject(serviceGroupContext); } } //--------------------------------------------------------- // axis message //--------------------------------------------------------- out.writeUTF("axisMessage"); metaAxisMessage = null; if (axisMessage != null) { // This AxisMessage is expected to belong to the AxisOperation // that has already been recorded for this MessageContext. // If an AxisMessage associated with this Messagecontext is // associated with a different AxisOperation, then more // meta information would need to be saved // make sure the axis message has a name associated with it String amTmpName = axisMessage.getName(); if (amTmpName == null) { amTmpName = ExternalizeConstants.EMPTY_MARKER; axisMessage.setName(amTmpName); } // get the element name if there is one QName amTmpElementQName = axisMessage.getElementQName(); String amTmpElemQNameString = null; if (amTmpElementQName != null) { amTmpElemQNameString = amTmpElementQName.toString(); } metaAxisMessage = new MetaDataEntry(axisMessage.getClass().getName(), axisMessage.getName(), amTmpElemQNameString); } out.writeObject(metaAxisMessage); //--------------------------------------------------------- // configuration context //--------------------------------------------------------- // NOTE: Currently, there does not seem to be any // runtime data important to this message context // in the configuration context. // if so, then need to save that runtime data and reconcile // it with the configuration context on the system when // this message context object is restored //--------------------------------------------------------- // session context //--------------------------------------------------------- out.writeObject(sessionContext); //--------------------------------------------------------- // transport //--------------------------------------------------------- //------------------------------ // incomingTransportName string //------------------------------ out.writeObject(incomingTransportName); // TransportInDescription transportIn metaTransportIn = null; if (transportIn != null) { metaTransportIn = new MetaDataEntry(null, transportIn.getName()); } out.writeObject(metaTransportIn); // TransportOutDescription transportOut metaTransportOut = null; if (transportOut != null) { metaTransportOut = new MetaDataEntry(null, transportOut.getName()); } out.writeObject(metaTransportOut); //--------------------------------------------------------- // properties //--------------------------------------------------------- // Write out the local properties on the MessageContext // Don't write out the properties from other hierarchical layers. // (i.e. don't use getProperties()) out.writeUTF("properties"); // write marker out.writeMap(properties); //--------------------------------------------------------- // special data //--------------------------------------------------------- out.writeUTF("selfManagedData"); serializeSelfManagedData(out); //--------------------------------------------------------- // done //--------------------------------------------------------- if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":writeExternal(): completed writing to output stream for " + logCorrelationIDString); } }
From source file:org.apache.axis2.context.MessageContext.java
/** * This method checks to see if additional work needs to be * done in order to complete the object reconstitution. * Some parts of the object restored from the readExternal() * cannot be completed until we have a configurationContext * from the active engine. The configurationContext is used * to help this object to plug back into the engine's * configuration and deployment objects. * * @param cc The configuration context object representing the active configuration *//*w ww . j a v a2s. co m*/ public void activate(ConfigurationContext cc) { // see if there's any work to do if (!needsToBeReconciled) { // return quick return; } // use the supplied configuration context setConfigurationContext(cc); // get the axis configuration AxisConfiguration axisConfig = configurationContext.getAxisConfiguration(); // We previously saved metaAxisService; restore it if (metaAxisService != null) { this.setAxisService(ActivateUtils.findService(axisConfig, metaAxisService.getClassName(), metaAxisService.getQNameAsString(), metaAxisService.getExtraName())); } // We previously saved metaAxisServiceGroup; restore it if (metaAxisServiceGroup != null) { this.setAxisServiceGroup(ActivateUtils.findServiceGroup(axisConfig, metaAxisServiceGroup.getClassName(), metaAxisServiceGroup.getQNameAsString())); } // We previously saved metaAxisOperation; restore it if (metaAxisOperation != null) { AxisService serv = axisService; if (serv != null) { // TODO: check for the empty name this.setAxisOperation(ActivateUtils.findOperation(serv, metaAxisOperation.getClassName(), metaAxisOperation.getQName())); } else { this.setAxisOperation(ActivateUtils.findOperation(axisConfig, metaAxisOperation.getClassName(), metaAxisOperation.getQName())); } } // We previously saved metaAxisMessage; restore it if (metaAxisMessage != null) { AxisOperation op = axisOperation; if (op != null) { // TODO: check for the empty name this.setAxisMessage(ActivateUtils.findMessage(op, metaAxisMessage.getQNameAsString(), metaAxisMessage.getExtraName())); } } //--------------------------------------------------------------------- // operation context //--------------------------------------------------------------------- // this will do a full hierarchy, so do it first // then we can re-use its objects if (operationContext != null) { operationContext.activate(cc); // this will be set as the parent of the message context // after the other context objects have been activated } //--------------------------------------------------------------------- // service context //--------------------------------------------------------------------- if (serviceContext == null) { // get the parent serviceContext of the operationContext if (operationContext != null) { serviceContext = operationContext.getServiceContext(); } } // if we have a service context, make sure it is usable if (serviceContext != null) { // for some reason, the service context might be set differently from // the operation context parent serviceContext.activate(cc); } //--------------------------------------------------------------------- // service group context //--------------------------------------------------------------------- if (serviceGroupContext == null) { // get the parent serviceGroupContext of the serviceContext if (serviceContext != null) { serviceGroupContext = (ServiceGroupContext) serviceContext.getParent(); } } // if we have a service group context, make sure it is usable if (serviceGroupContext != null) { // for some reason, the service group context might be set differently from // the service context parent serviceGroupContext.activate(cc); } //--------------------------------------------------------------------- // other context-related reconciliation //--------------------------------------------------------------------- this.setParent(operationContext); //--------------------------------------------------------------------- // options //--------------------------------------------------------------------- if (options != null) { options.activate(cc); } String tmpID = getMessageID(); String logCorrelationIDString = getLogIDString(); if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":activate(): message ID [" + tmpID + "] for " + logCorrelationIDString); } //--------------------------------------------------------------------- // transports //--------------------------------------------------------------------- // We previously saved metaTransportIn; restore it if (metaTransportIn != null) { QName qin = metaTransportIn.getQName(); TransportInDescription tmpIn = null; try { tmpIn = axisConfig.getTransportIn(qin.getLocalPart()); } catch (Exception exin) { // if a fault is thrown, log it and continue log.trace(logCorrelationIDString + "activate(): exception caught when getting the TransportInDescription [" + qin.toString() + "] from the AxisConfiguration [" + exin.getClass().getName() + " : " + exin.getMessage() + "]"); } if (tmpIn != null) { transportIn = tmpIn; } else { transportIn = null; } } else { transportIn = null; } // We previously saved metaTransportOut; restore it if (metaTransportOut != null) { // TODO : Check if this should really be a QName? QName qout = metaTransportOut.getQName(); TransportOutDescription tmpOut = null; try { tmpOut = axisConfig.getTransportOut(qout.getLocalPart()); } catch (Exception exout) { // if a fault is thrown, log it and continue if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + "activate(): exception caught when getting the TransportOutDescription [" + qout.toString() + "] from the AxisConfiguration [" + exout.getClass().getName() + " : " + exout.getMessage() + "]"); } } if (tmpOut != null) { transportOut = tmpOut; } else { transportOut = null; } } else { transportOut = null; } //------------------------------------------------------- // reconcile the execution chain //------------------------------------------------------- if (metaExecutionChain != null) { if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":activate(): reconciling the execution chain..."); } currentHandlerIndex = metaHandlerIndex; currentPhaseIndex = metaPhaseIndex; executionChain = restoreHandlerList(metaExecutionChain); try { deserializeSelfManagedData(); } catch (Exception ex) { // log the exception if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":activate(): *** WARNING *** deserializing the self managed data encountered Exception [" + ex.getClass().getName() + " : " + ex.getMessage() + "]", ex); } } } //------------------------------------------------------- // reconcile the lists for the executed phases //------------------------------------------------------- if (metaExecuted != null) { if (DEBUG_ENABLED && log.isTraceEnabled()) { log.trace(logCorrelationIDString + ":activate(): reconciling the executed chain..."); } if (!(executedPhasesReset)) { executedPhases = restoreExecutedList(executedPhases, metaExecuted); } } if (executedPhases == null) { executedPhases = new LinkedList<Handler>(); } //------------------------------------------------------- // finish up remaining links //------------------------------------------------------- if (operationContext != null) { operationContext.restoreMessageContext(this); } //------------------------------------------------------- // done, reset the flag //------------------------------------------------------- needsToBeReconciled = false; }