Search in sources :

Example 11 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project spring-framework by spring-projects.

the class Jaxb2RootElementHttpMessageConverter method readFromSource.

@Override
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException {
    try {
        source = processSource(source);
        Unmarshaller unmarshaller = createUnmarshaller(clazz);
        if (clazz.isAnnotationPresent(XmlRootElement.class)) {
            return unmarshaller.unmarshal(source);
        } else {
            JAXBElement<?> jaxbElement = unmarshaller.unmarshal(source, clazz);
            return jaxbElement.getValue();
        }
    } catch (NullPointerException ex) {
        if (!isSupportDtd()) {
            throw new HttpMessageNotReadableException("NPE while unmarshalling. " + "This can happen on JDK 1.6 due to the presence of DTD " + "declarations, which are disabled.", ex);
        }
        throw ex;
    } catch (UnmarshalException ex) {
        throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex);
    } catch (JAXBException ex) {
        throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
    }
}
Also used : HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) HttpMessageConversionException(org.springframework.http.converter.HttpMessageConversionException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 12 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project intellij-community by JetBrains.

the class NexusRepositoryService method getRepositories.

@NotNull
@Override
public List<MavenRepositoryInfo> getRepositories(@NotNull String url) throws IOException {
    try {
        List<RepositoryType> repos = new Endpoint.Repositories(url).getRepolistAsRepositories().getData().getRepositoriesItem();
        List<MavenRepositoryInfo> result = new ArrayList<>(repos.size());
        for (RepositoryType repo : repos) {
            if (!"maven2".equals(repo.getProvider()))
                continue;
            result.add(convertRepositoryInfo(repo));
        }
        return result;
    } catch (UnmarshalException e) {
        return Collections.emptyList();
    } catch (JAXBException e) {
        throw new IOException(e);
    }
}
Also used : UnmarshalException(javax.xml.bind.UnmarshalException) MavenRepositoryInfo(org.jetbrains.idea.maven.model.MavenRepositoryInfo) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project intellij-community by JetBrains.

the class NexusRepositoryService method findArtifacts.

@NotNull
@Override
public List<MavenArtifactInfo> findArtifacts(@NotNull String url, @NotNull MavenArtifactInfo template) throws IOException {
    try {
        final String packaging = StringUtil.notNullize(template.getPackaging());
        final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
        final SearchResults results = new Endpoint.DataIndex(url).getArtifactlistAsSearchResults(name, template.getGroupId(), template.getArtifactId(), template.getVersion(), null, template.getClassNames());
        boolean tooManyResults = results.isTooManyResults();
        final SearchResults.Data data = results.getData();
        final ArrayList<MavenArtifactInfo> result = new ArrayList<>();
        if (data != null) {
            for (ArtifactType each : data.getArtifact()) {
                if (!Comparing.equal(each.packaging, packaging))
                    continue;
                result.add(convertArtifactInfo(each));
            }
        }
        if (tooManyResults)
            result.add(null);
        return result;
    } catch (UnmarshalException e) {
        return Collections.emptyList();
    } catch (JAXBException e) {
        throw new IOException(e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) MavenArtifactInfo(org.jetbrains.idea.maven.model.MavenArtifactInfo) IOException(java.io.IOException) UnmarshalException(javax.xml.bind.UnmarshalException) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project OpenAM by OpenRock.

the class SAXUnmarshallerHandlerImpl method handleEvent.

public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException {
    ValidationEventHandler eventHandler;
    try {
        eventHandler = parent.getEventHandler();
    } catch (JAXBException e) {
        // impossible.
        throw new JAXBAssertionError();
    }
    boolean recover = eventHandler.handleEvent(event);
    // from the unmarshaller.getResult()
    if (!recover)
        aborted = true;
    if (!canRecover || !recover)
        throw new SAXException(new UnmarshalException(event.getMessage(), event.getLinkedException()));
}
Also used : ValidationEventHandler(javax.xml.bind.ValidationEventHandler) JAXBAssertionError(com.sun.xml.bind.JAXBAssertionError) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Example 15 with UnmarshalException

use of javax.xml.bind.UnmarshalException in project OpenAM by OpenRock.

the class SAXUnmarshallerHandlerImpl method handleEvent.

public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException {
    ValidationEventHandler eventHandler;
    try {
        eventHandler = parent.getEventHandler();
    } catch (JAXBException e) {
        // impossible.
        throw new JAXBAssertionError();
    }
    boolean recover = eventHandler.handleEvent(event);
    // from the unmarshaller.getResult()
    if (!recover)
        aborted = true;
    if (!canRecover || !recover)
        throw new SAXException(new UnmarshalException(event.getMessage(), event.getLinkedException()));
}
Also used : ValidationEventHandler(javax.xml.bind.ValidationEventHandler) JAXBAssertionError(com.sun.xml.bind.JAXBAssertionError) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Aggregations

UnmarshalException (javax.xml.bind.UnmarshalException)24 JAXBException (javax.xml.bind.JAXBException)15 IOException (java.io.IOException)6 JAXBAssertionError (com.sun.xml.bind.JAXBAssertionError)5 ValidationEventHandler (javax.xml.bind.ValidationEventHandler)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 Test (org.junit.Test)5 SAXException (org.xml.sax.SAXException)5 Unmarshaller (javax.xml.bind.Unmarshaller)4 File (java.io.File)3 URL (java.net.URL)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 StringReader (java.io.StringReader)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 ArrayList (java.util.ArrayList)2 BadRequestException (javax.ws.rs.BadRequestException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NoContentException (javax.ws.rs.core.NoContentException)2 JAXBContext (javax.xml.bind.JAXBContext)2 XmlType (javax.xml.bind.annotation.XmlType)2