List of usage examples for javax.xml.stream XMLStreamException getMessage
public String getMessage()
From source file:org.ops4j.pax.exam.karaf.container.internal.DependenciesDeployer.java
/** * Write a feature xml structure for test dependencies specified as ProvisionOption * in system to the given writer/*from w w w. ja v a2 s. co m*/ * * @param writer where to write the feature xml * @param provisionOptions dependencies */ static void writeDependenciesFeature(Writer writer, ProvisionOption<?>... provisionOptions) { XMLOutputFactory xof = XMLOutputFactory.newInstance(); xof.setProperty("javax.xml.stream.isRepairingNamespaces", true); XMLStreamWriter sw = null; try { sw = xof.createXMLStreamWriter(writer); sw.writeStartDocument("UTF-8", "1.0"); sw.setDefaultNamespace(KARAF_FEATURE_NS); sw.writeCharacters("\n"); sw.writeStartElement("features"); sw.writeAttribute("name", "test-dependencies"); sw.writeCharacters("\n"); sw.writeStartElement("feature"); sw.writeAttribute("name", "test-dependencies"); sw.writeCharacters("\n"); for (ProvisionOption<?> provisionOption : provisionOptions) { if (provisionOption.getURL().startsWith("link") || provisionOption.getURL().startsWith("scan-features")) { // well those we've already handled at another location... continue; } sw.writeStartElement("bundle"); if (provisionOption.getStartLevel() != null) { sw.writeAttribute("start-level", provisionOption.getStartLevel().toString()); } sw.writeCharacters(provisionOption.getURL()); endElement(sw); } endElement(sw); endElement(sw); sw.writeEndDocument(); } catch (XMLStreamException e) { throw new RuntimeException("Error writing feature " + e.getMessage(), e); } finally { close(sw); } }
From source file:org.osaf.cosmo.model.text.BaseXhtmlFormat.java
protected void handleXmlException(String message, XMLStreamException e) throws ParseException { message += ": " + e.getMessage(); handleException(message, e.getLocation()); }
From source file:org.sakaiproject.nakamura.auth.cas.CasAuthenticationHandler.java
private String retrieveCredentials(String responseBody) { String username = null;// www . j a v a2 s . c o m String pgtIou = null; String failureCode = null; String failureMessage = null; try { XMLInputFactory xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new StringReader(responseBody)); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); // process the event if we're starting an element if (event.isStartElement()) { StartElement startEl = event.asStartElement(); QName startElName = startEl.getName(); String startElLocalName = startElName.getLocalPart(); LOGGER.debug(responseBody); /* * Example of failure XML <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationFailure code='INVALID_REQUEST'> 'service' and 'ticket' parameters are both required </cas:authenticationFailure> </cas:serviceResponse> */ if ("authenticationFailure".equalsIgnoreCase(startElLocalName)) { // get code of the failure Attribute code = startEl.getAttributeByName(QName.valueOf("code")); failureCode = code.getValue(); // get the message of the failure event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); failureMessage = chars.getData(); break; } /* * Example of success XML <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>NetID</cas:user> </cas:authenticationSuccess> </cas:serviceResponse> */ if ("authenticationSuccess".equalsIgnoreCase(startElLocalName)) { // skip to the user tag start while (eventReader.hasNext()) { event = eventReader.nextTag(); if (event.isEndElement()) { if (eventReader.hasNext()) { event = eventReader.nextTag(); } else { break; } } assert event.isStartElement(); startEl = event.asStartElement(); startElName = startEl.getName(); startElLocalName = startElName.getLocalPart(); if (proxy && "proxyGrantingTicket".equals(startElLocalName)) { event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); pgtIou = chars.getData(); LOGGER.debug("XML parser found pgt: {}", pgtIou); } else if ("user".equals(startElLocalName)) { // move on to the body of the user tag event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); username = chars.getData(); LOGGER.debug("XML parser found user: {}", username); } else { LOGGER.error("Found unexpected element [{}] while inside 'authenticationSuccess'", startElName); break; } if (username != null && (!proxy || pgtIou != null)) { break; } } } } } } catch (XMLStreamException e) { LOGGER.error(e.getMessage(), e); } if (failureCode != null || failureMessage != null) { LOGGER.error("Error response from server code={} message={}", failureCode, failureMessage); } String pgt = pgts.get(pgtIou); if (pgt != null) { savePgt(username, pgt, pgtIou); } else { LOGGER.debug("Caching '{}' as the IOU for '{}'", pgtIou, username); pgtIOUs.put(pgtIou, username); } return username; }
From source file:org.sakaiproject.nakamura.auth.cas.CasAuthenticationHandler.java
private String getProxyTicketFromXml(String responseBody) { String ticket = null;// ww w . ja v a2 s .c om try { XMLInputFactory xmlInputFactory = new WstxInputFactory(); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(new StringReader(responseBody)); LOGGER.debug(responseBody); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); // process the event if we're starting an element if (event.isStartElement()) { StartElement startEl = event.asStartElement(); QName startElName = startEl.getName(); String startElLocalName = startElName.getLocalPart(); // Example XML // <cas:serviceResponse> // <cas:proxySuccess> // <cas:proxyTicket>PT-957-ZuucXqTZ1YcJw81T3dxf</cas:proxyTicket> // </cas:proxySuccess> // </cas:serviceResponse> if ("proxySuccess".equalsIgnoreCase(startElLocalName)) { event = eventReader.nextTag(); assert event.isStartElement(); startEl = event.asStartElement(); startElName = startEl.getName(); startElLocalName = startElName.getLocalPart(); if ("proxyTicket".equalsIgnoreCase(startElLocalName)) { event = eventReader.nextEvent(); assert event.isCharacters(); Characters chars = event.asCharacters(); ticket = chars.getData(); } else { LOGGER.error("Found unexpected element [{}] while inside 'proxySuccess'", startElName); break; } } } } } catch (XMLStreamException e) { LOGGER.error(e.getMessage(), e); } return ticket; }
From source file:org.sakaiproject.nakamura.docproxy.url.UrlRepositoryProcessor.java
public ExternalDocumentResult getDocument(Node node, String path) throws DocProxyException { try {/*from w w w.j ava 2 s .com*/ GetMethod method = new GetMethod(documentUrl + path); executeMethod(method, node); ExternalDocumentResult result = parseDocument(method.getResponseBodyAsStream()); return result; } catch (XMLStreamException e) { throw new DocProxyException(500, e.getMessage()); } catch (IOException e) { throw new DocProxyException(500, e.getMessage()); } }
From source file:org.sakaiproject.nakamura.docproxy.url.UrlRepositoryProcessor.java
public ExternalSearchResultSet search(Node node, Map<String, Object> searchProperties) throws DocProxyException { try {// w w w. ja v a 2 s. co m PostMethod method = new PostMethod(searchUrl); for (Entry<String, Object> entry : searchProperties.entrySet()) { method.addParameter(entry.getKey(), entry.getValue().toString()); } executeMethod(method, node); List<ExternalDocumentResult> results = parseSearch(method.getResponseBodyAsStream()); ExternalSearchResultSet resultSet = new ExternalSearchResultSetImpl(results.iterator(), (long) results.size()); return resultSet; } catch (XMLStreamException e) { throw new DocProxyException(500, e.getMessage()); } catch (IOException e) { throw new DocProxyException(500, e.getMessage()); } }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final XmiAssociationConnection readAssociationConnection(final XMLStreamReader reader) { try {//from w w w. java 2 s . c o m assertName(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader); final List<AssociationEnd> ends = new ArrayList<AssociationEnd>(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if (match(XmiElementName.ASSOCIATION_END, reader)) { ends.add(readAssociationEnd(reader)); } else { skipElement(reader, true); } break; } case XMLStreamConstants.END_ELEMENT: { assertName(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader); return new XmiAssociationConnection(ends.get(0), ends.get(1)); } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } } catch (final XMLStreamException e) { LOG.warn(e.getMessage()); } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final List<TaggedValue> readTaggedValueGroup(final XMLStreamReader reader) { final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>(); try {// w w w. java 2 s . co m if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) { while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if ("TaggedValue".equals(reader.getLocalName())) { taggedValues.add(assertNotNull(readTaggedValue(reader))); break; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.END_ELEMENT: { if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) { return taggedValues; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } } else { throw new AssertionError(reader.getLocalName()); } } catch (final XMLStreamException e) { LOG.warn(e.getMessage()); } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final Model readXMI(final XMLStreamReader reader) { try {/*from w ww .j a va 2 s .c o m*/ if ("XMI".equals(reader.getLocalName())) { Model model = null; while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if ("XMI.header".equals(reader.getLocalName())) { skipElement(reader, false); break; } else if ("XMI.content".equals(reader.getLocalName())) { model = readContent(reader); if (model == null) { throw new IllegalStateException(); } break; } else { throw new XmiRuntimeException("Expecting Foo element, got: " + reader.getLocalName()); } } case XMLStreamConstants.END_ELEMENT: { if ("XMI".equals(reader.getLocalName())) { if (model == null) { throw new IllegalStateException(); } return model; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } } else { throw new AssertionError(reader.getLocalName()); } } catch (final XMLStreamException e) { LOG.warn(e.getMessage()); } return null; }
From source file:org.soasecurity.is.oauth.validation.OAuth2TokenValidationServiceClient.java
public ValidationResponse validate(String accessToken) { String body = getBody(accessToken); String serverEndPoint = serverUrl + "OAuth2TokenValidationService"; ServiceClient client = null;/* w w w . j a v a2 s . c o m*/ ValidationResponse response = new ValidationResponse(false, null); try { client = new ServiceClient(configurationContext, null); Options option = client.getOptions(); option.setManageSession(true); HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); authenticator.setUsername(serverUserName); authenticator.setPassword(serverPassword); authenticator.setPreemptiveAuthentication(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator); option.setProperty(Constants.Configuration.TRANSPORT_URL, serverEndPoint); option.setAction("urn:validate"); option.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE); option.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); OMElement omElement = client.sendReceive(AXIOMUtil.stringToOM(body)); if (omElement != null && omElement.getFirstElement() != null) { omElement = omElement.getFirstElement(); if (omElement != null) { Iterator iterator = omElement.getChildElements(); while (iterator.hasNext()) { OMElement element = (OMElement) iterator.next(); if ("valid".equals(element.getLocalName())) { response.setValid(Boolean.parseBoolean(element.getText())); } if ("authorizationContextToken".equals(element.getLocalName())) { Iterator iterator2 = element.getChildElements(); while (iterator2.hasNext()) { OMElement element2 = (OMElement) iterator2.next(); if ("tokenString".equals(element2.getLocalName())) { response.setToken(element2.getText()); } } } } } } } catch (AxisFault axisFault) { log.error(axisFault.getMessage(), axisFault); } catch (XMLStreamException e) { log.error(e.getMessage(), e); } catch (Exception e) { log.error(e.getMessage(), e); } finally { if (client != null) { try { client.cleanupTransport(); client.cleanup(); } catch (AxisFault axisFault) { log.error("Error while cleaning HTTP client", axisFault); } } } return response; }