List of usage examples for javax.xml.namespace QName toString
public String toString()
From source file:co.turnus.trace.io.XmlTraceReader.java
private void endElement(QName name) { switch (name.toString()) { case TRACE:/*www. j a v a 2s . com*/ currentAttributable = null; break; case STEP: factory.addStep(tempStep.id, tempStep.actor, tempStep.action, tempStep.actorClass, tempStep.getAttributesMap()); currentAttributable = trace; break; case DEPENDENCY: switch (tempDep.kind) { case FSM: factory.addDependencyFsm(tempDep.sourceId, tempDep.targetId, tempDep.getAttributesMap()); break; case GUARD: factory.addDependencyGuard(tempDep.sourceId, tempDep.targetId, tempDep.guard, tempDep.direction, tempDep.getAttributesMap()); break; case PORT: factory.addDependencyPort(tempDep.sourceId, tempDep.targetId, tempDep.port, tempDep.direction, tempDep.getAttributesMap()); break; case STATEVAR: factory.addDependencyStateVar(tempDep.sourceId, tempDep.targetId, tempDep.variable, tempDep.direction, tempDep.getAttributesMap()); break; case TOKENS: factory.addDependencyTokens(tempDep.sourceId, tempDep.targetId, tempDep.sourcePort, tempDep.targetPort, tempDep.count, tempDep.getAttributesMap()); break; default: break; } currentAttributable = trace; break; default: break; } }
From source file:co.turnus.trace.io.XmlTraceReader.java
private void startElement(QName name) { switch (name.toString()) { case TRACE://w w w .j av a 2 s. co m currentAttributable = trace; break; case STEP: tempStep.clear(); tempStep.id = Long.parseLong(reader.getAttributeValue("", STEP_FIRING)); tempStep.actor = reader.getAttributeValue("", STEP_ACTOR); tempStep.action = reader.getAttributeValue("", STEP_ACTION); tempStep.actorClass = reader.getAttributeValue("", STEP_ACTOR_CLASS); currentAttributable = tempStep; if (progressPrinter != null) { progressPrinter.increment(); } break; case DEPENDENCY: tempDep.clear(); tempDep.sourceId = Long.parseLong(reader.getAttributeValue("", DEPENDENCY_SOURCE)); tempDep.targetId = Long.parseLong(reader.getAttributeValue("", DEPENDENCY_TARGET)); tempDep.kind = Kind.get(reader.getAttributeValue("", DEPENDENCY_KIND)); switch (tempDep.kind) { case GUARD: tempDep.guard = reader.getAttributeValue("", GUARD); tempDep.direction = Direction.get(reader.getAttributeValue("", DIRECTION)); break; case STATEVAR: tempDep.variable = reader.getAttributeValue("", VARIABLE); tempDep.direction = Direction.get(reader.getAttributeValue("", DIRECTION)); break; case PORT: tempDep.port = reader.getAttributeValue("", PORT); tempDep.direction = Direction.get(reader.getAttributeValue("", DIRECTION)); break; case TOKENS: tempDep.sourcePort = reader.getAttributeValue("", SOURCE_PORT); tempDep.targetPort = reader.getAttributeValue("", TARGET_PORT); tempDep.count = Integer.parseInt(reader.getAttributeValue("", COUNT)); break; default: break; } currentAttributable = tempDep; break; case ATTRIBUTE: String attName = reader.getAttributeValue("", ATTRIBUTE_NAME); Object attValue = parseAttribute(); currentAttributable.setAttribute(attName, attValue); break; default: break; } }
From source file:edu.umn.msi.tropix.common.xml.ObjectDeserializationContext.java
private void init(final QName type, final Class javaClass) throws Exception { msgContext.setEncodingStyle(""); popElementHandler();/*from w w w .j av a 2s.c o m*/ setDeserializer(type, javaClass); if (topDeserializer == null) { String arg = (type == null) ? javaClass.getName() : type.toString(); throw new Exception("noDeserializer"); } pushElementHandler(new EnvelopeHandler((SOAPHandler) this.topDeserializer)); }
From source file:org.opensaml.soap.client.soap11.decoder.http.impl.HttpClientResponseSOAP11Decoder.java
/** * Build an exception by processing a fault response, i.e. one where the HTTP response code was 500. * /*w w w. j av a2 s. c o m*/ * @param response the HTTP client response * @return the message decoding exception representing the SOAP fault * * @throws MessageDecodingException if message can not be unmarshalled * @throws IOException if there is a problem with the response entity input stream */ protected MessageDecodingException buildFaultException(HttpResponse response) throws MessageDecodingException, IOException { if (response.getEntity() == null) { throw new MessageDecodingException("No response body from server"); } Envelope soapMessage = (Envelope) unmarshallMessage(response.getEntity().getContent()); Fault fault = getFault(soapMessage); if (fault == null) { throw new MessageDecodingException( "HTTP status code was 500 but SOAP response did not contain a Fault"); } QName code = null; if (fault.getCode() != null) { code = fault.getCode().getValue(); } String msg = null; if (fault.getMessage() != null) { msg = fault.getMessage().getValue(); } log.debug("SOAP fault code '{}' with message '{}'", code != null ? code.toString() : "(not set)", msg); return new SOAP11FaultDecodingException(fault); }
From source file:gov.nih.nci.cagrid.introduce.servicetools.ReflectionResource.java
private void initializeResourceProperties(Object resourceBean, QName resourceElementQName) throws ResourceException { if (resourceBean == null) { throw new IllegalArgumentException(i18n.getMessage("nullArgument", "resourceBean")); }/* w ww .ja va 2 s .com*/ this.resourceBean = resourceBean; Class resourceBeanClazz = resourceBean.getClass(); TypeDesc typeDesc = TypeDesc.getTypeDescForClass(resourceBeanClazz); if (typeDesc == null) { throw new ResourceException(i18n.getMessage("noTypeDesc", resourceBeanClazz)); } // is type anonymous? String localTypeName = typeDesc.getXmlType().getLocalPart(); if (localTypeName.startsWith(">")) { String globalElementName = localTypeName.substring(1); // this // is Axis-dependent of course... if (resourceElementQName == null) { resourceElementQName = new QName(typeDesc.getXmlType().getNamespaceURI(), globalElementName); } } if (logger.isDebugEnabled()) { logger.debug("QName of global element for resource properties is:" + resourceElementQName); } // get the resource properties FieldDesc[] fields = typeDesc.getFields(); // Create resource properties per se this.resourcePropertySet = new SimpleResourcePropertySet(resourceElementQName); ResourceProperty prop = null; if (fields != null) { try { for (int i = 0; i < fields.length; i++) { QName rpQName = fields[i].getXmlName(); if (logger.isDebugEnabled()) { logger.debug("creating new resource property \"" + rpQName.toString() + "\""); } if (!(fields[i] instanceof ElementDesc)) { String errorMessage = i18n.getMessage("rpNotElement", fields[i].getXmlType().getLocalPart()); throw new ResourceException(errorMessage); } ElementDesc elementDesc = (ElementDesc) fields[i]; // assume nillable always false since no metadata for that SimpleResourcePropertyMetaData metaData = new SimpleResourcePropertyMetaData(rpQName, elementDesc.getMinOccurs(), elementDesc.getMaxOccurs(), false, Object.class, false); prop = createNewResourceProperty(metaData, this.resourceBean); this.resourcePropertySet.add(prop); } } catch (ResourceException e) { logger.error("", e); throw e; } catch (Exception e) { logger.error("", e); throw new ResourceException(i18n.getMessage("resourceInitError"), e); } } }
From source file:org.eclipse.swordfish.core.interceptor.EndpointResolverInterceptor.java
public void process(MessageExchange messageExchange) throws SwordfishException { Assert.notNull(wsdlStorage, "wsdlStorage is not loaded"); Exchange exchange = ServiceMixSupport.toNMRExchange(messageExchange); try {/*from w w w . j av a2 s. com*/ if (exchange.getRole() != Role.Consumer) { return; } if (exchange.getTarget() != null && ServiceMixSupport.getEndpoint(exchange.getTarget()) != null) { return; } QName interfaceName = (QName) exchange.getProperty(Endpoint.INTERFACE_NAME); if (interfaceName == null) { interfaceName = (QName) exchange.getProperty(MessageExchangeImpl.INTERFACE_NAME_PROP); } if (interfaceName == null) { return; } QName operation = exchange.getOperation(); if (operation == null) return; ServiceDescription serviceDescription; try { serviceDescription = wsdlManager.getServiceDescription(interfaceName); } catch (WSDLException e) { throw new SwordfishException( "Error resolving endpoint - cannot retrieve service description for port type " + interfaceName + " message: " + e.getMessage()); } if (serviceDescription != null) { // SwordfishPort port = serviceDescription.choosePort(operation.getLocalPart(), Transport.HTTP_STR); // Binding binding = port.getBinding(); // Map<String,String> props = new HashMap<String, String>(); // props.put(Endpoint.SERVICE_NAME, serviceDescription.getServiceQName().toString()); // Reference reference = lookup(props); QName service = serviceDescription.getServiceQName(); if (service == null) throw new SwordfishException("Error resolving endpoint - cannot resolve service for port type " + interfaceName + " operation " + operation); Map<String, Object> props = new HashMap<String, Object>(); props.put(Endpoint.SERVICE_NAME, service.toString()); InternalEndpoint serviceEndpoint = ServiceMixSupport.getEndpoint(nmr, props); if (serviceEndpoint != null) { logger.info("The service endpoint for the servicename + [" + service + "} has been found"); exchange.setTarget(new StaticReferenceImpl(Arrays.asList(serviceEndpoint))); } else { logger.info("The service endpoint for the servicename + [" + service + "} not found"); logger.info("Trying to find the transport endpoint"); serviceDescription.getAvailableLocations(); for (Map.Entry<SOAPAddress, SOAPBinding> entry : serviceDescription.getAvailableLocations() .entrySet()) { props.clear(); props.put(JbiConstants.PROTOCOL_TYPE, entry.getValue().getTransportURI()); serviceEndpoint = ServiceMixSupport.getEndpoint(nmr, props); if (serviceEndpoint != null) { logger.info("Have found the suitable endpoint with transport = " + entry.getValue().getTransportURI()); exchange.setTarget(new StaticReferenceImpl(Arrays.asList(serviceEndpoint))); exchange.getIn().setHeader(JbiConstants.HTTP_DESTINATION_URI, entry.getKey().getLocationURI()); } } } } else { logger.info("Error resolving endpoint - wsdl cannot be found for port type " + interfaceName); } } catch (Exception ex) { logger.warn("The exception happened while trying to resolve service name via supplied wsdls ", ex); } }
From source file:org.fcrepo.serialization.JcrXmlSerializer.java
private void validateJCRXML(final File file) throws InvalidSerializationFormatException, IOException { int depth = 0; try (final FileInputStream fis = new FileInputStream(file)) { final XMLEventReader reader = XMLInputFactory.newFactory().createXMLEventReader(fis); while (reader.hasNext()) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { depth++;//from www. j a va 2s .c o m final StartElement startElement = event.asStartElement(); final Attribute nameAttribute = startElement .getAttributeByName(new QName("http://www.jcp.org/jcr/sv/1.0", "name")); if (depth == 1 && nameAttribute != null && "jcr:content".equals(nameAttribute.getValue())) { throw new InvalidSerializationFormatException( "Cannot import JCR/XML starting with content node."); } if (depth == 1 && nameAttribute != null && "jcr:frozenNode".equals(nameAttribute.getValue())) { throw new InvalidSerializationFormatException("Cannot import historic versions."); } final QName name = startElement.getName(); if (!(name.getNamespaceURI().equals("http://www.jcp.org/jcr/sv/1.0") && (name.getLocalPart().equals("node") || name.getLocalPart().equals("property") || name.getLocalPart().equals("value")))) { throw new InvalidSerializationFormatException( "Unrecognized element \"" + name.toString() + "\", in import XML."); } } else { if (event.isEndElement()) { depth--; } } } reader.close(); } catch (XMLStreamException e) { throw new InvalidSerializationFormatException( "Unable to parse XML" + (e.getMessage() != null ? " (" + e.getMessage() + ")." : ".")); } }
From source file:com.legstar.proxy.invoke.jaxws.WebServiceInvoker.java
/** * Try to extract something meaningful from a SOAP Fault. * // w ww .ja v a 2 s . c o m * @param e the SOAP Fault exception * @return a fault description */ @SuppressWarnings("rawtypes") public String getFaultReasonText(final SOAPFaultException e) { if (_log.isDebugEnabled()) { SOAPFault fault = e.getFault(); if (fault != null) { QName code = fault.getFaultCodeAsQName(); String string = fault.getFaultString(); String actor = fault.getFaultActor(); _log.debug("SOAP fault contains: "); _log.debug(" Fault code = " + code.toString()); _log.debug(" Local name = " + code.getLocalPart()); _log.debug(" Namespace prefix = " + code.getPrefix() + ", bound to " + code.getNamespaceURI()); _log.debug(" Fault string = " + string); if (actor != null) { _log.debug(" Fault actor = " + actor); } Detail detail = fault.getDetail(); if (detail != null) { Iterator entries = detail.getDetailEntries(); while (entries.hasNext()) { DetailEntry newEntry = (DetailEntry) entries.next(); String value = newEntry.getValue(); _log.debug(" Detail entry = " + value); } } } else { _log.debug(e); } } SOAPFault fault = e.getFault(); if (fault != null) { StringBuffer faultMessage = new StringBuffer(e.getFault().getFaultString()); Detail detail = fault.getDetail(); if (detail != null) { Iterator entries = detail.getDetailEntries(); while (entries.hasNext()) { DetailEntry newEntry = (DetailEntry) entries.next(); faultMessage.append(" [" + newEntry.getValue() + "]"); } } return faultMessage.toString(); } else { return e.getMessage(); } }
From source file:com.bradmcevoy.property.BeanPropertySource.java
@Override public Object getProperty(QName name, Resource r) throws NotAuthorizedException { PropertyDescriptor pd = getPropertyDescriptor(r, name.getLocalPart()); if (pd == null) { throw new IllegalArgumentException("no prop: " + name.getLocalPart() + " on " + r.getClass()); }// w w w .j av a 2s . com try { return pd.getReadMethod().invoke(r, NOARGS); } catch (Exception ex) { if (ex.getCause() instanceof NotAuthorizedException) { NotAuthorizedException na = (NotAuthorizedException) ex.getCause(); throw na; } else { throw new RuntimeException(name.toString(), ex); } } }
From source file:com.vmware.vchs.publicapi.samples.VMCreateSample.java
/** * This will use the passed in vm to find the VirtualHardwareSection and modify it to attach * the Vm network to the vApp network the Vm is a child of. The first step is to search the * Vm section types for VirtualHardwareSection. If found, look in the attributes of the section * to find the VirtualHardwareSection Href value. The VirtualHardwareSection found in the Vm * has a number of extra LinkType links that can not be part of the request body when the PUT * call to update the network settings is made. Therefore, the Href is used to first GET the * VirtualHardwareSection again which responds without the links so it can be used to PUT back * to the same Href to update the Vm network settings. With the newly acquired * VirtualHardwareSection, a search through the items is done to find the network item. This * is denoted by a resource type value of "10". If found the command line options.networkName * is set as the value of the connection, and the value POOL is assigned to the ipAddressingMode * attribute. With those values set, the updated VirtualHardwareSection is then sent via a PUT * request to change the Vm network settings. * // www .jav a 2s.co m * @param vm the Vm to change network settings on */ private TaskType updateVMWithNetworkDetails(VmType vm) { // the Href to use for GET and PUT calls for the VirtualHardwareSection String hardwareHref = null; // With the VDC network details, we can now update the Vm network section to connect the Vm to the vApp network for (JAXBElement<? extends SectionType> st : vm.getSection()) { if (st.getName().toString().contains("VirtualHardwareSection")) { VirtualHardwareSectionType hardware = (VirtualHardwareSectionType) st.getValue(); // Try to find the Href attribute which is used for GET and PUT Map<QName, String> map = hardware.getOtherAttributes(); Set<QName> keys = map.keySet(); for (QName key : keys) { if (key.toString().endsWith("href")) { hardwareHref = map.get(key); break; } } // Make sure VirtualHardwareSection href was found. This is used for the GET below // and PUT to later update the network settings of the Vm. if (null != hardwareHref) { // It's necessary to GET the VirtualHardwareSection again because the current // hardware variables from the Vm contains links that can not be sent as part // of the PUT body. This GET call will only get the details without the links // that the Vm section provides. HttpResponse response = HttpUtils.httpInvoke(vcd.get(hardwareHref, options)); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { hardware = HttpUtils.unmarshal(response.getEntity(), VirtualHardwareSectionType.class); // Find the RASDType that has a ResourceType of 10, which indicates the // VMs network info for (RASDType rasType : hardware.getItem()) { if (rasType.getResourceType().getValue().equals("10")) { CimBoolean c = new CimBoolean(); c.setValue(true); rasType.setAutomaticAllocation(c); // Get the first CimString CimString cs = rasType.getConnection().get(0); // Set the network name cs.setValue(options.networkName); // Look in the list of attributes for the ip addressing mode map = cs.getOtherAttributes(); keys = map.keySet(); for (QName key : keys) { if (key.toString().endsWith("ipAddressingMode")) { // Set it to POOL map.put(key, "POOL"); break; } } break; } } } // Now do a PUT with update data com.vmware.vcloud.api.rest.schema.ovf.ObjectFactory objectFactory = new com.vmware.vcloud.api.rest.schema.ovf.ObjectFactory(); JAXBElement<VirtualHardwareSectionType> hardwareSection = objectFactory .createVirtualHardwareSection(hardware); JAXBContext jaxbContexts = null; try { jaxbContexts = JAXBContext.newInstance(VirtualHardwareSectionType.class); } catch (JAXBException ex) { throw new RuntimeException("Problem creating JAXB Context: ", ex); } // Create HttpPut request to update the VirtualHardwareSection HttpPut updateVmNetwork = vcd.put(hardwareHref, options); OutputStream os = null; try { javax.xml.bind.Marshaller marshaller = jaxbContexts.createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); os = new ByteArrayOutputStream(); // Marshal the object via JAXB to XML marshaller.marshal(hardwareSection, os); } catch (JAXBException e) { throw new RuntimeException("Problem marshalling VirtualHardwareSection", e); } // Set the Content-Type header for VirtualHardwareSection ContentType contentType = ContentType .create("application/vnd.vmware.vcloud.virtualHardwareSection+xml", "ISO-8859-1"); StringEntity update = new StringEntity(os.toString(), contentType); updateVmNetwork.setEntity(update); // Invoke the HttoPut to update the VirtualHardwareSection of the Vm response = HttpUtils.httpInvoke(updateVmNetwork); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_ACCEPTED) { // Update was good, return the TaskType TaskType taskType = HttpUtils.unmarshal(response.getEntity(), TaskType.class); return taskType; } break; } } } throw new RuntimeException("Could not update Vm VirtualHardwareSection"); }