Example usage for javax.xml.bind JAXBException JAXBException

List of usage examples for javax.xml.bind JAXBException JAXBException

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException JAXBException.

Prototype

public JAXBException(Throwable exception) 

Source Link

Document

Construct a JAXBException with a linkedException.

Usage

From source file:gov.nih.nci.caxchange.transcend.CaXchangeRequestService.java

/**
 * This method is used process the message
 * //from   w w w.  j a v a  2  s .  co m
 * @param parameters - parameters
 * @return ResponseMessage
 */
@WebResult(name = "responseMessage", targetNamespace = "http://caXchange.nci.nih.gov/caxchangerequest", partName = "parameters")
@WebMethod
public gov.nih.nci.caxchange.messaging.ResponseMessage processRequest(
        @WebParam(partName = "parameters", name = "message", targetNamespace = "http://caXchange.nci.nih.gov/caxchangerequest") Message parameters) {
    LOG.debug("Executing operation processRequest");

    final Long caXchangeId = Calendar.getInstance().getTimeInMillis();
    // setting this value as String, but inside the app is expecting a long value
    parameters.getMetadata().setCaXchangeIdentifier(String.valueOf(caXchangeId));

    final gov.nih.nci.caxchange.messaging.ResponseMessage respMessage = new ResponseMessage();
    final ResponseMetadata rm = new ResponseMetadata();
    rm.setExternalIdentifier(parameters.getMetadata().getExternalIdentifier());
    rm.setCaXchangeIdentifier(parameters.getMetadata().getCaXchangeIdentifier());
    respMessage.setResponseMetadata(rm);

    try {
        final String reqstr = getCaXchangeRequestxml(parameters);
        if (StringUtils.isEmpty(reqstr)) {
            final ErrorDetails errorDetails = new ErrorDetails();
            errorDetails.setErrorCode(String.valueOf(IntegrationError._1050));
            errorDetails.setErrorDescription(IntegrationError._1050.getMessage((Object) null));

            final Response response = new Response();
            response.setCaXchangeError(errorDetails);
            response.setResponseStatus(Statuses.FAILURE);
            respMessage.setResponse(response);
            return respMessage;
        }

        String mcResponse = webServiceMessageReceiver.processData(reqstr);

        if (LOG.isDebugEnabled()) {
            LOG.debug("CaXchangeRequestService..MC RESPONSE:" + mcResponse);
        }

        if (StringUtils.isEmpty(mcResponse)) {
            throw new JAXBException("No proper response from iHub");
        }

        if ((mcResponse.indexOf("Error") > -1 || mcResponse.indexOf("Exception") > -1
                || mcResponse.indexOf("ERROR") > -1 || mcResponse.indexOf("error") > -1)) {
            mcResponse = StringUtils.remove(mcResponse, "SUCCESS:");
            mcResponse = StringUtils.remove(mcResponse, "FAILURE:");
            final Response response = new Response();
            response.setCaXchangeError(getErrorDetailsFromCaXchangeError(mcResponse));
            response.setResponseStatus(Statuses.FAILURE);
            respMessage.setResponse(response);
            return respMessage;
        }

        final Response response = new Response();
        response.setResponseStatus(Statuses.SUCCESS);
        response.getTargetResponse().add(prepareTargetResponse(parameters));
        respMessage.setResponse(response);

        return respMessage;
    } catch (JAXBException ex) {
        return getJAXBExceptionResponseMessage(respMessage, ex);
    }

}

From source file:de.xirp.profile.ProfileGenerator.java

/**
 * Generates a BOT file with the given path from the given 
 * {@link de.xirp.profile.CommunicationSpecification comm-spec} 
 * bean.//from   w  w  w  .j a va2  s  . co m
 * 
 * @param commSpec
 *          The comm-spec to generate the XML for. 
 * @param cmsFile
 *          The file to write the result to. Must be the full path.
 * 
 * @throws JAXBException if the given comm-spec was null, or something 
 *                    went wrong generating the xml.
 * @throws FileNotFoundException if something went wrong generating the xml.
 */
public static void generateCMS(CommunicationSpecification commSpec, File cmsFile)
        throws JAXBException, FileNotFoundException {

    if (commSpec == null) {
        throw new JAXBException(I18n.getString("ProfileGenerator.exception.comSpecNull")); //$NON-NLS-1$
    }

    String fileName = FilenameUtils.getBaseName(cmsFile.getName());

    JAXBContext jc = JAXBContext.newInstance(CommunicationSpecification.class);
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(commSpec, new FileOutputStream(
            Constants.CONF_COMMSPECS_DIR + File.separator + fileName + Constants.COMM_SPEC_POSTFIX));
}

From source file:org.javelin.sws.ext.bind.SweJaxbMarshaller.java

@Override
public void marshal(Object jaxbElement, File output) throws JAXBException {
    try {//from  w  w w  .  ja  v a 2 s  .  c  o  m
        this.marshal(jaxbElement, new BufferedOutputStream(new FileOutputStream(output)));
    } catch (FileNotFoundException e) {
        throw new JAXBException(e);
    }
}

From source file:com.wso2telco.PremiumInfoScopeTest.java

/**
 * Read scopes config.//  w  w  w  .  java2s  .  c o  m
 *
 * @return the scope configs
 * @throws JAXBException the JAXB exception
 */
private ScopeConfigs readScopesConfig() throws JAXBException {
    Unmarshaller um = null;
    ScopeConfigs userClaims = null;
    String configPath = "config" + File.separator + "scope-config.xml";
    File file = new File(getClass().getClassLoader().getResource(configPath).getFile());
    try {
        JAXBContext ctx = JAXBContext.newInstance(ScopeConfigs.class);
        um = ctx.createUnmarshaller();
        userClaims = (ScopeConfigs) um.unmarshal(file);
    } catch (JAXBException e) {
        throw new JAXBException("Error unmarshalling file :" + configPath);
    }
    return userClaims;
}

From source file:com.tomtom.speedtools.services.lbs.route.implementation.TomTomLbsRouteEngineRouteEngineActorImpl.java

/**
 * Do the heavy lifting of binding the input stream to the JAX-B annotated objects.
 *
 * @param stream Stream to read from.// w w  w . j  a v a2  s  . c o m
 * @return Valid route response object or null on error.
 * @throws JAXBException Thrown if unmarshalling fails.
 */
@Nonnull
private static TomTomLbsRouteEngineResponse unmarshalRouterResponseBody(@Nonnull final InputStream stream)
        throws JAXBException {
    assert stream != null;
    final JAXBContext context = JAXBContext.newInstance(TomTomLbsRouteEngineResponse.class);
    final Unmarshaller unmarshaller = context.createUnmarshaller();
    final TomTomLbsRouteEngineResponse response = (TomTomLbsRouteEngineResponse) unmarshaller.unmarshal(stream);
    if (response == null) {
        throw new JAXBException("Response cannot be unmarshalled");
    }
    return response;
}

From source file:cz.cas.lib.proarc.common.workflow.profile.WorkflowProfiles.java

private void read() throws JAXBException {
    long currentTime = file.lastModified();
    if (currentTime == lastModified) {
        return;//from w  w  w . j  a  va 2 s.  co  m
    }
    Unmarshaller unmarshaller = getUnmarshaller();
    ValidationEventCollector errors = (ValidationEventCollector) unmarshaller.getEventHandler();
    WorkflowDefinition fetchedWf = null;
    try {
        WorkflowDefinition wf = (WorkflowDefinition) unmarshaller.unmarshal(file);
        if (!errors.hasEvents()) {
            readCaches(wf);
            fetchedWf = wf;
        }
    } catch (UnmarshalException ex) {
        if (!errors.hasEvents()) {
            throw ex;
        }
    } finally {
        setProfiles(fetchedWf, currentTime);
    }
    if (errors.hasEvents()) {
        StringBuilder err = new StringBuilder();
        for (ValidationEvent event : errors.getEvents()) {
            err.append(event).append('\n');
        }
        throw new JAXBException(err.toString());
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.jaxb.JAXBUtil.java

/**
 * Performs the same function as {@link JAXBUtil#getJAXBIntrospector(String)}, but uses a JAXB
 * generated class object to retrieve the JAXB package name.
 *
 * @param jaxbClass - the {@link Class} object that the represents a JAXB generated class
 * @return an instance of {@link JAXBIntrospector} that corresponds to the JAXB package name
 * @throws JAXBException if an error occurs while creating a JAXB context
 *//*from w ww .  j  a  v  a  2 s .co  m*/
public static JAXBIntrospector getJAXBIntrospector(final Class<?> jaxbClass) throws JAXBException {

    if (jaxbClass != null) {
        return getJAXBIntrospector(jaxbClass.getPackage().getName());
    } else {
        throw new JAXBException(
                "Could not instantiate JAXB introspector because the JAXB class object was null");
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.jaxb.JAXBUtil.java

/**
 * Convenience method for retrieving and instance of {@link JAXBIntrospector} for JAXB generated
 * objects from a specific JAXB package name.
 *
 * @param jaxbPackageName - a string representing the package name of JAXB generated objects
 * @return an instance of {@link JAXBIntrospector} that corresponds to the JAXB package name
 * @throws JAXBException if an error occurs while creating a JAXB context
 *///from w w  w.  ja va 2s  .  c o  m
public static JAXBIntrospector getJAXBIntrospector(final String jaxbPackageName) throws JAXBException {

    if (jaxbPackageName != null) {
        final JAXBContext context = JAXBContext.newInstance(jaxbPackageName);
        return context.createJAXBIntrospector();
    } else {
        throw new JAXBException(
                "Could not instantiate JAXB introspector because the JAXB package namespace was null");
    }
}

From source file:org.dasein.cloud.azure.tests.compute.AzureAffinityGroupSupportTests.java

@Test(expected = InternalException.class)
public void modifyShouldThrowExceptionIfParsingRequestEntityFailed() throws InternalException, CloudException {
    new MockUp<AzureMethod>() {
        @Mock//from ww w  .ja v a 2s  .  c  om
        <T> String put(String resource, T object) throws JAXBException, CloudException, InternalException {
            throw new JAXBException("parsing object failed");
        }
    };
    AffinityGroupCreateOptions options = AffinityGroupCreateOptions.getInstance(AFFINITY_GROUP_ID,
            AFFINITY_GROUP_ID, REGION);
    new AzureAffinityGroupSupport(azureMock).modify(AFFINITY_GROUP_ID, options);
}

From source file:org.opennms.netmgt.ackd.readers.HypericAckProcessor.java

/**
 * <p>parseHypericAlerts</p>
 *
 * @param reader a {@link java.io.Reader} object.
 * @return a {@link java.util.List} object.
 * @throws javax.xml.bind.JAXBException if any.
 * @throws javax.xml.stream.XMLStreamException if any.
 *//*from  w ww .j  a  v a 2s .  c o  m*/
public static List<HypericAlertStatus> parseHypericAlerts(Reader reader)
        throws JAXBException, XMLStreamException {
    List<HypericAlertStatus> retval = new ArrayList<HypericAlertStatus>();

    // Instantiate a JAXB context to parse the alert status
    JAXBContext context = JAXBContext
            .newInstance(new Class[] { HypericAlertStatuses.class, HypericAlertStatus.class });
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLEventReader xmler = xmlif.createXMLEventReader(reader);
    EventFilter filter = new EventFilter() {
        @Override
        public boolean accept(XMLEvent event) {
            return event.isStartElement();
        }
    };
    XMLEventReader xmlfer = xmlif.createFilteredReader(xmler, filter);
    // Read up until the beginning of the root element
    StartElement startElement = (StartElement) xmlfer.nextEvent();
    // Fetch the root element name for {@link HypericAlertStatus} objects
    String rootElementName = context.createJAXBIntrospector().getElementName(new HypericAlertStatuses())
            .getLocalPart();
    if (rootElementName.equals(startElement.getName().getLocalPart())) {
        Unmarshaller unmarshaller = context.createUnmarshaller();
        // Use StAX to pull parse the incoming alert statuses
        while (xmlfer.peek() != null) {
            Object object = unmarshaller.unmarshal(xmler);
            if (object instanceof HypericAlertStatus) {
                HypericAlertStatus alertStatus = (HypericAlertStatus) object;
                retval.add(alertStatus);
            }
        }
    } else {
        // Try to pull in the HTTP response to give the user a better idea of what went wrong
        StringBuffer errorContent = new StringBuffer();
        LineNumberReader lineReader = new LineNumberReader(reader);
        try {
            String line;
            while (true) {
                line = lineReader.readLine();
                if (line == null) {
                    break;
                } else {
                    errorContent.append(line.trim());
                }
            }
        } catch (IOException e) {
            errorContent.append("Exception while trying to print out message content: " + e.getMessage());
        }

        // Throw an exception and include the erroneous HTTP response in the exception text
        throw new JAXBException("Found wrong root element in Hyperic XML document, expected: \""
                + rootElementName + "\", found \"" + startElement.getName().getLocalPart() + "\"\n"
                + errorContent.toString());
    }
    return retval;
}