List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMinimalMethodMarshaller.java
/** * Calculate the index of the first block for the parameter and * the last block (inclusive) for the parameter * @param firstIndex//from w ww . jav a2 s . c o m * @param lastIndex * @param params * @param qNames */ private static void calculateBodyIndex(int[] firstIndex, int[] lastIndex, ParameterDescription[] params, List<QName> qNames) { if (log.isDebugEnabled()) { log.debug("Start calculateBodyIndex"); for (int i = 0; i < qNames.size(); i++) { log.debug(" QName " + i + " = " + qNames.get(i)); } } for (int pi = 0; pi < params.length; pi++) { if (pi >= 0) { ParameterDescription pd = params[pi]; if (log.isDebugEnabled()) { log.debug(" ParameterDescription =" + pd.toString()); log.debug(" original firstIndex = " + firstIndex[pi]); log.debug(" original lastIndex = " + lastIndex[pi]); } firstIndex[pi] = -1; // Reset index lastIndex[pi] = -1; // Reset index // Found a parameter that is expected in the body // Calculate its index by looking for an exact qname match for (int qi = 0; qi < qNames.size(); qi++) { QName qName = qNames.get(qi); if (qName.getLocalPart().equals(pd.getPartName())) { if (qName.getNamespaceURI().equals(pd.getTargetNamespace())) { if (firstIndex[pi] < 0) { if (log.isDebugEnabled()) { log.debug(" set first index to " + qi); } firstIndex[pi] = qi; } lastIndex[pi] = qi; } } } // Fallback to searching for just the part name if (firstIndex[pi] < 0) { for (int qi = 0; qi < qNames.size(); qi++) { QName qName = qNames.get(qi); if (qName.getLocalPart().equals(pd.getPartName())) { if (firstIndex[pi] < 0) { if (log.isDebugEnabled()) { log.debug(" fallback: set first index to " + qi); } firstIndex[pi] = qi; } lastIndex[pi] = qi; } } } if (log.isDebugEnabled()) { log.debug(" last index = " + lastIndex[pi]); } } } if (log.isDebugEnabled()) { log.debug("End calculateBodyIndex"); } }
From source file:org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.java
/** * Marshal the element enabled objects (pvList) to the Message * * @param pdeList element enabled objects * @param message Message//w w w . j a v a2s . c o m * @param packages Packages needed to do a JAXB Marshal * @param contextProperties RequestContext or ResponseContext or null * @throws MessageException */ static void toMessage(List<PDElement> pdeList, Message message, TreeSet<String> packages, Map<String, Object> contextProperties) throws WebServiceException { int totalBodyBlocks = 0; for (int i = 0; i < pdeList.size(); i++) { PDElement pde = pdeList.get(i); if (!pde.getParam().isHeader() && pde.getElement() != null) { // Element is null for SWARef attachment totalBodyBlocks++; } } int index = message.getNumBodyBlocks(); for (int i = 0; i < pdeList.size(); i++) { PDElement pde = pdeList.get(i); // Create JAXBContext JAXBBlockContext context = new JAXBBlockContext(packages); Attachment attachment = pde.getAttachment(); if (attachment == null) { // Normal Flow: Not an attachment // Marshal by type only if necessary if (pde.getByJavaTypeClass() != null) { context.setProcessType(pde.getByJavaTypeClass()); if (pde.getParam() != null) { context.setIsxmlList(pde.getParam().isListType()); } } // Create a JAXBBlock out of the value. // (Note that the PDElement.getValue always returns an object // that has an element rendering...ie. it is either a JAXBElement or // has @XmlRootElement defined Block block = factory.createFrom(pde.getElement().getElementValue(), context, pde.getElement().getQName()); if (pde.getParam().isHeader()) { // Header block if (pde.getElement().getTypeValue() != null) { // The value is non-null, add a header. QName qname = block.getQName(); message.setHeaderBlock(qname.getNamespaceURI(), qname.getLocalPart(), block); } else { // The value is null, it is still best to add a nil header. // But query to see if an override is desired. if (isWriteWithNilHeader(contextProperties)) { QName qname = block.getQName(); message.setHeaderBlock(qname.getNamespaceURI(), qname.getLocalPart(), block); } } } else { // Body block if (totalBodyBlocks < 1) { // If there is only one block, use the following "more performant" method message.setBodyBlock(block); } else { message.setBodyBlock(index, block); } index++; } } else { // The parameter is an attachment AttachmentType type = pde.getParam().getAttachmentDescription().getAttachmentType(); if (type == AttachmentType.SWA) { // All we need to do is set the data handler on the message. // For SWA attachments, the message does not reference the attachment. message.addDataHandler(attachment.getDataHandler(), attachment.getContentID()); message.setDoingSWA(true); } else { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr")); } } } }
From source file:org.apache.axis2.jaxws.marshaller.impl.alt.RPCLitMethodMarshaller.java
public Message marshalResponse(Object returnObject, Object[] signatureArgs, OperationDescription operationDesc, Protocol protocol) throws WebServiceException { EndpointInterfaceDescription ed = operationDesc.getEndpointInterfaceDescription(); EndpointDescription endpointDesc = ed.getEndpointDescription(); // We want to respond with the same protocol as the request, // It the protocol is null, then use the Protocol defined by the binding if (protocol == null) { protocol = Protocol.getProtocolForBinding(endpointDesc.getBindingType()); }/*from w w w. ja v a 2s . c o m*/ // Note all exceptions are caught and rethrown with a WebServiceException try { // Sample RPC message // .. // <soapenv:body> // <m:opResponse xmlns:m="urn://api"> // <param xsi:type="data:foo" >...</param> // </m:op> // </soapenv:body> // // Important points. // 1) RPC has an operation element under the body. This is the name of the // wsdl operation. // 2) The data blocks are located underneath the operation element. (In doc/lit // the data elements are underneath the body. // 3) The name of the data blocks (param) are defined by the wsdl:part not the // schema. Note that it is unqualified. // 4) The type of the data block (data:foo) is defined by schema (thus there is // JAXB type rendering. Since we are using JAXB to marshal the data, // we always generate an xsi:type attribute. This is an implemenation detail // and is not defined by any spec. // Get the operation information ParameterDescription[] pds = operationDesc.getParameterDescriptions(); MarshalServiceRuntimeDescription marshalDesc = MethodMarshallerUtils.getMarshalDesc(endpointDesc); TreeSet<String> packages = marshalDesc.getPackages(); // Create the message MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class); Message m = mf.create(protocol); // Indicate the style and operation element name. This triggers the message to // put the data blocks underneath the operation element m.setStyle(Style.RPC); QName rpcOpQName = getRPCOperationQName(operationDesc, false); String localPart = rpcOpQName.getLocalPart() + "Response"; QName responseOp = new QName(rpcOpQName.getNamespaceURI(), localPart, rpcOpQName.getPrefix()); m.setOperationElement(responseOp); // Put the return object onto the message Class returnType = operationDesc.getResultActualType(); String returnNS = null; String returnLocalPart = null; if (operationDesc.isResultHeader()) { returnNS = operationDesc.getResultTargetNamespace(); returnLocalPart = operationDesc.getResultName(); } else { returnNS = ""; // According to WSI BP the body part is unqualified returnLocalPart = operationDesc.getResultPartName(); } if (returnType != void.class) { AttachmentDescription attachmentDesc = operationDesc.getResultAttachmentDescription(); if (attachmentDesc != null) { if (attachmentDesc.getAttachmentType() == AttachmentType.SWA) { // Create an Attachment object with the signature value Attachment attachment = new Attachment(returnObject, returnType, attachmentDesc, operationDesc.getResultPartName()); m.addDataHandler(attachment.getDataHandler(), attachment.getContentID()); m.setDoingSWA(true); } else { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("pdElementErr")); } } else { // TODO should we allow null if the return is a header? //Validate input parameters for operation and make sure no input parameters are null. //As per JAXWS Specification section 3.6.2.3 if a null value is passes as an argument //to a method then an implementation MUST throw WebServiceException. if (returnObject == null) { throw ExceptionFactory.makeWebServiceException( Messages.getMessage("NullParamErr3", operationDesc.getJavaMethodName())); } Element returnElement = null; QName returnQName = new QName(returnNS, returnLocalPart); if (marshalDesc.getAnnotationDesc(returnType).hasXmlRootElement()) { returnElement = new Element(returnObject, returnQName); } else { returnElement = new Element(returnObject, returnQName, returnType); } // Use marshalling by java type if necessary Class byJavaType = null; if (!operationDesc.isResultHeader() || MethodMarshallerUtils.isNotJAXBRootElement(returnType, marshalDesc)) { byJavaType = returnType; } MethodMarshallerUtils.toMessage(returnElement, returnType, operationDesc.isListType(), marshalDesc, m, byJavaType, operationDesc.isResultHeader()); } } // Convert the holder objects into a list of JAXB objects for marshalling List<PDElement> pdeList = MethodMarshallerUtils.getPDElements(marshalDesc, pds, signatureArgs, false, // output false, true); // use partName since this is rpc/lit // We want to use "by Java Type" marshalling for // all body elements and all non-JAXB objects for (PDElement pde : pdeList) { ParameterDescription pd = pde.getParam(); Class type = pd.getParameterActualType(); if (!pd.isHeader() || MethodMarshallerUtils.isNotJAXBRootElement(type, marshalDesc)) { pde.setByJavaTypeClass(type); } } // TODO Should we check for null output body values? Should we check for null output header values ? // Put values onto the message MethodMarshallerUtils.toMessage(pdeList, m, packages, null); // Enable SWA for nested SwaRef attachments if (operationDesc.hasResponseSwaRefAttachments()) { m.setDoingSWA(true); } return m; } catch (Exception e) { throw ExceptionFactory.makeWebServiceException(e); } }
From source file:org.apache.axis2.jaxws.message.impl.BlockImpl.java
/** * Called if we have passed the pivot point but someone wants to output the block. The actual * block implementation may choose to override this setting. *//*from w w w .ja v a 2 s. c o m*/ protected XMLStreamReader _postPivot_getXMLStreamReader() throws XMLStreamException, WebServiceException { if (log.isDebugEnabled()) { QName theQName = isQNameAvailable() ? getQName() : new QName("unknown"); log.debug( "The Block for " + theQName + " is already consumed and therefore it is only partially read."); log.debug("If you need this block preserved, please set the " + Constants.SAVE_REQUEST_MSG + " property on the MessageContext."); } QName qName = getQName(); String text = ""; if (qName.getNamespaceURI().length() > 0) { text = "<prefix:" + qName.getLocalPart() + " xmlns:prefix='" + qName.getNamespaceURI() + "'/>"; } else { text = "<" + qName.getLocalPart() + "/>"; } StringReader sr = new StringReader(text); return StAXUtils.createXMLStreamReader(sr); }
From source file:org.apache.axis2.jaxws.message.impl.XMLPartBase.java
/** * XMLPart should be constructed via the XMLPartFactory. This constructor creates an XMLPart from * the specified root./* ww w . ja v a2 s . c o m*/ * * @param root * @param protocol (if null, the soap protocol is inferred from the namespace) * @throws WebServiceException */ XMLPartBase(OMElement root, Protocol protocol) throws WebServiceException { content = root; contentType = OM; QName qName = root.getQName(); if (protocol == null) { if (qName.getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { this.protocol = Protocol.soap11; } else if (qName.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { this.protocol = Protocol.soap12; } } else if (protocol == Protocol.rest) { this.protocol = Protocol.rest; // Axis2 stores XML/HTTP messages inside a soap11 envelope. We will mimic this behavior if (qName.getNamespaceURI().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { // Okay } else if (qName.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { // throw ExceptionFactory. // makeWebServiceException(Messages.getMessage("restWithSOAPErr")); // Okey } else { content = _createSpine(Protocol.rest, Style.DOCUMENT, 0, root); contentType = SPINE; } } else { this.protocol = protocol; } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
public void setBodyBlock(int index, Block block) throws WebServiceException { // Forces the parser to read all of the blocks getNumBodyBlocks();//from w w w . j av a 2 s. co m block.setParent(getParent()); OMElement bElement = _getBodyBlockParent(); OMElement om = this._getChildOMElement(bElement, index); // The block is supposed to represent a single element. // But if it does not represent an element , the following will fail. QName qName = block.getQName(); OMNamespace ns = soapFactory.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()); OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, false); if (om == null) { bElement.addChild(newOM); } else { om.insertSiblingBefore(newOM); om.detach(); } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
public void setBodyBlock(Block block) throws WebServiceException { // Forces the parser to read all of the blocks getNumBodyBlocks();/*w w w . j a va 2 s .c o m*/ block.setParent(getParent()); // Remove all of the children OMElement bElement = _getBodyBlockParent(); Iterator it = bElement.getChildren(); while (it.hasNext()) { it.next(); it.remove(); } if (block.isElementData()) { // If the block is element data then it is safe to create // an OMElement representing the block // The block is supposed to represent a single element. // But if it does not represent an element , the following will fail. QName qName = block.getQName(); OMNamespace ns = soapFactory.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()); OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, false); bElement.addChild(newOM); } else { // This needs to be fixed, but for now we will require that there must be an // element...otherwise no block is added try { QName qName = block.getQName(); OMNamespace ns = soapFactory.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()); OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, false); bElement.addChild(newOM); } catch (Throwable t) { if (log.isDebugEnabled()) { log.debug("An attempt was made to pass a Source or String that does not " + "have an xml element. Processing continues with an empty payload."); } } } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
public void setOperationElement(QName operationQName) { OMElement opElement = this._getBodyBlockParent(); if (!(opElement instanceof SOAPBody)) { OMNamespace ns = soapFactory.createOMNamespace(operationQName.getNamespaceURI(), operationQName.getPrefix()); opElement.setLocalName(operationQName.getLocalPart()); opElement.setNamespace(ns);/*from ww w . j av a 2s . c o m*/ // Necessary to avoid duplicate namespaces later. opElement.declareNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); } }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * Create child SOAPElement//w w w .j a v a 2 s . com * * @param parent SOAPElement * @param name Name * @return */ protected SOAPElement createElement(SOAPElement parent, QName qName) throws SOAPException { SOAPElement child; if (parent instanceof SOAPEnvelope) { if (qName.getNamespaceURI().equals(parent.getNamespaceURI())) { if (qName.getLocalPart().equals("Body")) { child = ((SOAPEnvelope) parent).addBody(); } else { child = ((SOAPEnvelope) parent).addHeader(); } } else { child = parent.addChildElement(qName); } } else if (parent instanceof SOAPBody) { if (qName.getNamespaceURI().equals(parent.getNamespaceURI()) && qName.getLocalPart().equals("Fault")) { child = ((SOAPBody) parent).addFault(); } else { child = ((SOAPBody) parent).addBodyElement(qName); } } else if (parent instanceof SOAPHeader) { child = ((SOAPHeader) parent).addHeaderElement(qName); } else if (parent instanceof SOAPFault) { // This call assumes that the addChildElement implementation // is smart enough to add "Detail" or "SOAPFaultElement" objects. child = parent.addChildElement(qName); } else if (parent instanceof Detail) { child = ((Detail) parent).addDetailEntry(qName); } else { child = parent.addChildElement(qName); } return child; }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * add attributes// ww w.j ava 2 s. c om * * @param NameCreator nc * @param element SOAPElement which is the target of the new attributes * @param reader XMLStreamReader whose cursor is at START_ELEMENT * @throws SOAPException */ protected void addAttributes(NameCreator nc, SOAPElement element, XMLStreamReader reader) throws SOAPException { if (log.isDebugEnabled()) { log.debug("addAttributes: Entry"); } // Add the attributes from the reader int size = reader.getAttributeCount(); for (int i = 0; i < size; i++) { QName qName = reader.getAttributeName(i); String prefix = reader.getAttributePrefix(i); String value = reader.getAttributeValue(i); Name name = nc.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); element.addAttribute(name, value); try { if (log.isDebugEnabled()) { log.debug("Setting attrType"); } String namespace = qName.getNamespaceURI(); Attr attr = null; // This is an org.w3c.dom.Attr if (namespace == null || namespace.length() == 0) { attr = element.getAttributeNode(qName.getLocalPart()); } else { attr = element.getAttributeNodeNS(namespace, qName.getLocalPart()); } if (attr != null) { String attrType = reader.getAttributeType(i); attr.setUserData(SAAJConverter.OM_ATTRIBUTE_KEY, attrType, null); if (log.isDebugEnabled()) { log.debug("Storing attrType in UserData: " + attrType); } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("An error occured while processing attrType: " + e.getMessage()); } } } if (log.isDebugEnabled()) { log.debug("addAttributes: Exit"); } }