List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:org.apache.axis2.jaxws.description.impl.EndpointInterfaceDescriptionImpl.java
public OperationDescription[] getDispatchableOperation(QName operationQName) { // REVIEW: Can this be synced at a more granular level? Can't sync on dispatchableOperations because // it may be null, but also the initialization must finish before next thread sees // dispatachableOperations != null synchronized (this) { if (dispatchableOperations == null) { initializeDispatchableOperationsList(); }//from w w w . j a v a 2 s . c o m } // Note that OperationDescriptionImpl creates operation qname with empty namespace. Thus // using only the localPart to get dispatchable operations. QName key = new QName("", operationQName.getLocalPart()); List<OperationDescription> operations = dispatchableOperations.get(key); if (operations != null) { return operations.toArray(new OperationDescription[operations.size()]); } return new OperationDescription[0]; }
From source file:org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.java
private boolean isPortDeclared(QName portQName) { // TODO: This needs to account for declaration of the port via annotations in addition to just WSDL // TODO: Add logic to check the portQN namespace against the WSDL Definition NS boolean portIsDeclared = false; if (!DescriptionUtils.isEmpty(portQName)) { if (getWSDLWrapper() != null) { Definition wsdlDefn = getWSDLWrapper().getDefinition(); Service wsdlService = wsdlDefn.getService(serviceQName); Port wsdlPort = wsdlService.getPort(portQName.getLocalPart()); portIsDeclared = (wsdlPort != null); } else {/*w w w. j a v a 2s. c om*/ // TODO: Add logic to determine if port is declared via annotations when no WSDL is present. For now, we have to assume it is declared // so getPort(...) and createDispatch(...) calls work when there is no WSDL. portIsDeclared = true; } } else { // PortQName is null, so the runtime gets to choose which one to use. Since there's no WSDL // we'll use annotations, so it is implicitly declared portIsDeclared = true; } return portIsDeclared; }
From source file:org.apache.axis2.jaxws.handler.SOAPHeadersAdapter.java
/** * Returns a list of XML strings that have the same namespace as the QName key. The * returned list is not "live"; it manipulating the list will not result in changed * headers on the message./*from w w w. jav a 2 s . c o m*/ * @param _key Object -- QName key of header XML strings you intend to retrieve */ public List<String> get(Object _key) { // notify the HandlerChainProcessor that a transformation has occurred possibly due to a handler method call into here HandlerChainProcessor.trackInternalCall(mc, HandlerChainProcessor.TRACKER.SOAP_HEADERS_ADAPTER_CALLED); try { if (!(keySet().contains(_key))) { return null; } QName key = (QName) _key; Message m = mc.getMessage(); List<Block> blocks = m.getHeaderBlocks(key.getNamespaceURI(), key.getLocalPart(), null, getXMLStringBlockFactory(), null); if (blocks == null || blocks.size() == 0) { return null; } // Get the strings from the blocks ArrayList<String> xmlStrings = new ArrayList<String>(); for (int i = 0; i < blocks.size(); i++) { Block block = blocks.get(i); String value = (block == null) ? null : (String) block.getBusinessObject(false); xmlStrings.add(value); } return xmlStrings; } catch (Throwable t) { throw ExceptionFactory.makeWebServiceException(t); } }
From source file:org.apache.axis2.jaxws.handler.SOAPHeadersAdapter.java
/** * put will inject the headers into the SOAP message immediately * @param key Object -- QName key of header XML strings you wish to be put on the SOAP header * @param values List<String> -- list of XML strings that have the same namespace as the QName key */// w w w .j a v a2s . c o m public List<String> put(QName key, List<String> values) { // notify the HandlerChainProcessor that a transformation has occurred possibly due to a handler method call into here HandlerChainProcessor.trackInternalCall(mc, HandlerChainProcessor.TRACKER.SOAP_HEADERS_ADAPTER_CALLED); Message m = mc.getMessage(); if (log.isDebugEnabled()) { log.debug("put(" + key + " , " + values + ")"); } // Get the old value List<String> old = get(key); if (values != null) { if (old != null) { // Replace the existing header blocks m.removeHeaderBlock(key.getNamespaceURI(), key.getLocalPart()); } for (int i = 0; i < values.size(); i++) { String value = values.get(i); Block block = getXMLStringBlockFactory().createFrom(value, null, key); m.appendHeaderBlock(key.getNamespaceURI(), key.getLocalPart(), block); } } return old; }
From source file:org.apache.axis2.jaxws.handler.SOAPHeadersAdapter.java
/** * remove will immediately remove the headers from the SOAP message that match the QName key * @param _key Object -- QName key of header XML strings you wish to remove from the SOAP header *///from ww w. j a v a 2 s .c om public List<String> remove(Object _key) { // notify the HandlerChainProcessor that a transformation has occurred possibly due to a handler method call into here HandlerChainProcessor.trackInternalCall(mc, HandlerChainProcessor.TRACKER.SOAP_HEADERS_ADAPTER_CALLED); try { if (!(keySet().contains(_key))) { return null; } if (!(_key instanceof QName)) { throw ExceptionFactory.makeWebServiceException("key must be of type " + QName.class.getName()); } QName key = (QName) _key; if (log.isDebugEnabled()) { log.debug("remove(" + key + ")"); } // Get the old value List<String> old = get(key); Message m = mc.getMessage(); List<Block> blocks = m.getHeaderBlocks(key.getNamespaceURI(), key.getLocalPart(), null, getXMLStringBlockFactory(), null); if (blocks == null || blocks.size() == 0) { return null; } // Get the strings from the blocks ArrayList<String> xmlStrings = new ArrayList<String>(); for (Block block : blocks) { String value = (block == null) ? null : (String) block.getBusinessObject(false); xmlStrings.add(value); m.removeHeaderBlock(key.getNamespaceURI(), key.getLocalPart()); } keySet().remove(key); return old; } catch (Throwable t) { throw ExceptionFactory.makeWebServiceException(t); } }
From source file:org.apache.axis2.jaxws.handler.SoapMessageContext.java
public Object[] getHeaders(QName qname, JAXBContext jaxbcontext, boolean allRoles) { if (log.isDebugEnabled()) { log.debug("Getting all Headers for Qname: " + qname); }// www . ja va 2 s. c o m if (qname == null) { if (log.isDebugEnabled()) { log.debug("Invalid QName, QName cannot be null"); } throw ExceptionFactory.makeWebServiceException(Messages.getMessage("soapMessageContextErr1")); } if (jaxbcontext == null) { if (log.isDebugEnabled()) { log.debug("Invalid JAXBContext, JAXBContext cannot be null"); } throw ExceptionFactory.makeWebServiceException(Messages.getMessage("soapMessageContextErr2")); } // The header information is returned as a list of jaxb objects List<Object> list = new ArrayList<Object>(); String namespace = qname.getNamespaceURI(); String localPart = qname.getLocalPart(); BlockFactory blockFactory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class); Message m = messageCtx.getMessage(); JAXBBlockContext jbc = new JAXBBlockContext(jaxbcontext); // If allRoles is not specified, pass in a set of roles. // The headers must support that role. RolePlayer rolePlayer = null; if (allRoles == false) { rolePlayer = getRolePlayer(); } if (m.getNumHeaderBlocks() > 0) { // Get the list of JAXB Blocks List<Block> blockList = m.getHeaderBlocks(namespace, localPart, jbc, blockFactory, rolePlayer); // Create list of JAXB objects if (blockList != null && blockList.size() > 0) { try { Iterator it = blockList.iterator(); while (it.hasNext()) { Block block = (Block) it.next(); Object bo = block.getBusinessObject(false); if (bo != null) { if (log.isDebugEnabled()) { log.debug("Extracted BO from Header Block"); } list.add(bo); } } } catch (XMLStreamException e) { throw ExceptionFactory.makeWebServiceException(e); } } } return list.toArray(new Object[0]); }
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/*w w w .ja v a 2 s . c om*/ * @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/*from 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.MethodMarshallerUtils.java
/** * Unmarshal the service/system exception from a Message. This is used by all of the * marshallers// w w w .j av a2 s.c o m * * @param operationDesc * @param marshalDesc * @param message * @return Throwable * @throws WebServiceException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws XMLStreamException * @throws InvocationTargetException * @throws NoSuchMethodException */ static Throwable demarshalFaultResponse(OperationDescription operationDesc, MarshalServiceRuntimeDescription marshalDesc, Message message) throws WebServiceException, ClassNotFoundException, IllegalAccessException, InstantiationException, XMLStreamException, InvocationTargetException, NoSuchMethodException { Throwable exception = null; // Get the fault from the message and get the detail blocks (probably one) XMLFault xmlfault = message.getXMLFault(); Block[] detailBlocks = xmlfault.getDetailBlocks(); // If there is only one block, get the element name of that block. QName elementQName = null; if (detailBlocks != null && detailBlocks.length >= 1) { elementQName = detailBlocks[0].getQName(); if (log.isDebugEnabled()) { if (detailBlocks.length > 1) { log.debug("The detail element has multiple child elements. " + "Only the first child is examined to determine if this is a service exception. " + "If this first detail child is mapped to a service exception, " + "the information in other detail children may be ignored. " + "The most common scenario is that the second child is a " + "{http://jax-ws.dev.java.net/}exception element, which is used " + "by some vendors for debugging. "); } } } if (log.isDebugEnabled()) { log.debug("element QName which will be used to find a service exception = " + elementQName); log.debug("XMLFault Dump = " + xmlfault.dump("")); log.debug("OperationDesc Dump =" + operationDesc); } // Use the element name to find the matching FaultDescriptor FaultDescription faultDesc = null; if (elementQName != null) { for (int i = 0; i < operationDesc.getFaultDescriptions().length && faultDesc == null; i++) { FaultDescription fd = operationDesc.getFaultDescriptions()[i]; FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(fd); if (faultBeanDesc != null) { QName tryQName = new QName(faultBeanDesc.getFaultBeanNamespace(), faultBeanDesc.getFaultBeanLocalName()); if (log.isErrorEnabled()) { log.debug(" FaultDescription qname is (" + tryQName + ") and detail element qname is (" + elementQName + ")"); } if (elementQName.equals(tryQName)) { faultDesc = fd; } } } } if (faultDesc == null && elementQName != null) { // If not found, retry the search using just the local name for (int i = 0; i < operationDesc.getFaultDescriptions().length && faultDesc == null; i++) { FaultDescription fd = operationDesc.getFaultDescriptions()[i]; FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(fd); if (faultBeanDesc != null) { String tryName = faultBeanDesc.getFaultBeanLocalName(); if (elementQName.getLocalPart().equals(tryName)) { faultDesc = fd; } } } } if (faultDesc == null) { // This is a system exception if the method does not throw a checked exception or if // the detail block is missing or contains multiple items. exception = createSystemException(xmlfault, message); } else { if (log.isErrorEnabled()) { log.debug("Ready to demarshal service exception. The detail entry name is " + elementQName); } FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(faultDesc); boolean isLegacy = (faultDesc.getFaultInfo() == null || faultDesc.getFaultInfo().length() == 0); // Get the JAXB object from the block JAXBBlockContext blockContext = new JAXBBlockContext(marshalDesc.getPackages()); // Note that faultBean may not be a bean, it could be a primitive Class faultBeanFormalClass; try { faultBeanFormalClass = loadClass(faultBeanDesc.getFaultBeanClassName()); } catch (ClassNotFoundException e) { faultBeanFormalClass = loadClass(faultBeanDesc.getFaultBeanClassName(), operationDesc.getEndpointInterfaceDescription().getEndpointDescription().getAxisService() .getClassLoader()); } // Use "by java type" marshalling if necessary if (blockContext.getConstructionType() != JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH && isNotJAXBRootElement(faultBeanFormalClass, marshalDesc)) { blockContext.setProcessType(faultBeanFormalClass); } // Get the jaxb block and business object Block jaxbBlock = factory.createFrom(detailBlocks[0], blockContext); Object faultBeanObject = jaxbBlock.getBusinessObject(true); // At this point, faultBeanObject is an object that can be rendered as an // element. We want the object that represents the type. if (faultBeanObject instanceof JAXBElement) { faultBeanObject = ((JAXBElement) faultBeanObject).getValue(); } if (log.isErrorEnabled()) { log.debug("Unmarshalled the detail element into a JAXB object"); } // Construct the JAX-WS generated exception that holds the faultBeanObject Class exceptionClass; try { exceptionClass = loadClass(faultDesc.getExceptionClassName()); } catch (ClassNotFoundException e) { exceptionClass = loadClass(faultDesc.getExceptionClassName(), operationDesc.getEndpointInterfaceDescription().getEndpointDescription().getAxisService() .getClassLoader()); } if (log.isErrorEnabled()) { log.debug("Found FaultDescription. The exception name is " + exceptionClass.getName()); } exception = createServiceException(xmlfault.getReason().getText(), exceptionClass, faultBeanObject, faultBeanFormalClass, marshalDesc, isLegacy); } return exception; }
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()); }/*ww w . j a va 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); } }