Java Code Examples for javax.xml.bind.JAXBException#getLinkedException()

The following examples show how to use javax.xml.bind.JAXBException#getLinkedException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppManagementConfigurationManagerTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
private void validateMalformedConfig(File malformedConfig) {
	try {
		JAXBContext ctx = JAXBContext.newInstance(AppManagementConfig.class);
		Unmarshaller um = ctx.createUnmarshaller();
		um.setSchema(this.getSchema());
		um.unmarshal(malformedConfig);
		Assert.assertTrue(false);
	} catch (JAXBException e) {
		Throwable linkedException = e.getLinkedException();
		if (!(linkedException instanceof SAXParseException)) {
			log.error("Unexpected error occurred while unmarshalling app management config", e);
			Assert.assertTrue(false);
		}
		log.error("JAXB parser occurred while unmarsharlling app management config", e);
		Assert.assertTrue(true);
	}
}
 
Example 2
Source File: DeviceManagementConfigTests.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
private void validateMalformedConfig(File malformedConfig) {
    try {
        JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
        Unmarshaller um = ctx.createUnmarshaller();
        um.setSchema(this.getSchema());
        um.unmarshal(malformedConfig);
        Assert.assertTrue(false);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (!(linkedException instanceof SAXParseException)) {
            log.error("Unexpected error occurred while unmarshalling device management config", e);
            Assert.assertTrue(false);
        }
        log.error("JAXB parser occurred while unmarsharlling device management config", e);
        Assert.assertTrue(true);
    }
}
 
Example 3
Source File: ChangeSetMapper.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public ChangeSet mapChangeSet(com.navercorp.pinpoint.hbase.schema.definition.xml.ChangeSet changeSet) {
    try {
        StringWriter stringWriter = new StringWriter(); // no need to close StringWriter
        createMarshaller().marshal(changeSet, stringWriter);
        String value = stringWriter.toString();

        List<TableChange> tableChangeList = mapTableChanges(changeSet.getModifyTable(), changeSet.getCreateTable());
        return new ChangeSet(changeSet.getId(), value, tableChangeList);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (linkedException == null) {
            throw new IllegalStateException("JAXB error", e);
        }
        throw new HbaseSchemaParseException("Error computing md5 for change set id : " + changeSet.getId(), linkedException);
    }
}
 
Example 4
Source File: AbstractJAXBProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void handleJAXBException(JAXBException e, boolean read) {
    StringBuilder sb = handleExceptionStart(e);
    Throwable linked = e.getLinkedException();
    if (linked != null && linked.getMessage() != null) {
        Throwable cause = linked;
        while (read && cause != null) {
            if (cause instanceof XMLStreamException && cause.getMessage().startsWith("Maximum Number")) {
                throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413));
            }
            if (cause instanceof DepthExceededStaxException) {
                throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413));
            }
            cause = cause.getCause();
        }
        String msg = linked.getMessage();
        if (sb.lastIndexOf(msg) == -1) {
            sb.append(msg).append(". ");
        }
    }
    Throwable t = linked != null ? linked : e.getCause() != null ? e.getCause() : e;
    String message = new org.apache.cxf.common.i18n.Message("JAXB_EXCEPTION",
                         BUNDLE, sb.toString()).toString();
    handleExceptionEnd(t, message, read);
}
 
Example 5
Source File: JaxContextCentralizer.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private String processJAXBException(JAXBException e) {
   String message = null;
   if (e.getLinkedException() != null) {
      message = e.getLinkedException().getMessage();
   } else {
      message = e.getLocalizedMessage();
   }

   return message;
}
 
Example 6
Source File: JaxContextCentralizer.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private String processJAXBException(JAXBException e) {
   String message = null;
   if (e.getLinkedException() != null) {
      message = e.getLinkedException().getMessage();
   } else {
      message = e.getLocalizedMessage();
   }

   return message;
}
 
Example 7
Source File: XmlHbaseSchemaParser.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
XmlHbaseSchemaParseResult parseSchema(InputSource inputSource) {
    try {
        Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
        unmarshaller.setSchema(SCHEMA);
        HbaseSchema hbaseSchema = (HbaseSchema) unmarshaller.unmarshal(inputSource);
        return mapper.map(hbaseSchema);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (linkedException == null) {
            throw new IllegalStateException("JAXB error", e);
        }
        throw new HbaseSchemaParseException(linkedException.getMessage(), linkedException);
    }
}
 
Example 8
Source File: LgTvInteractor.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
public String getallchannels() {
    String message = "";
    message = "";
    String answer = "#notpaired";

    if (ispaired()) {
        answer = sendtotv("GET", "udap/api/data?target=channel_list", message);

        try {
            channelset.loadchannels(answer);
            int i = channelset.getsize();
            String s = String.valueOf(i);
            answer = s;
            if (this.xmldatafiles.length() > 0) {

                String filename = this.xmldatafiles + lgip + "_lgtvallchannels.xml";
                logger.debug("xmldatafiles is set - writing file=" + filename);
                channelset.savetofile(filename);

            }

        } catch (JAXBException e) {

            logger.error("exception in getallchannels: ", e);
            org.xml.sax.SAXParseException f = (org.xml.sax.SAXParseException) e.getLinkedException();
            logger.error("parse exception e=" + e.toString() + " line=" + f.getLineNumber() + " columns="
                    + f.getColumnNumber() + " local=" + f.getLocalizedMessage());
        }
    }

    return new String(answer);
}
 
Example 9
Source File: LgTvInteractor.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
public String getallapps() {
    String message = "";
    message = "";
    String answer = "#notpaired";
    if (ispaired()) {
        answer = sendtotv("GET", "udap/api/data?target=applist_get&type=1&index=1&number=1024", message);

        logger.debug("answer: " + answer);
        try {
            appset.loadapps(answer);
            int i = appset.getsize();
            String s = String.valueOf(i);
            answer = s;

            if (this.xmldatafiles.length() > 0) {

                String filename = this.xmldatafiles + lgip + "_lgtvallapps.xml";
                logger.debug("xmldatafiles is set - writing file=" + filename);
                appset.savetofile(filename);

            }

        } catch (JAXBException e) {

            logger.error("error in getallapps", e);
            org.xml.sax.SAXParseException f = (org.xml.sax.SAXParseException) e.getLinkedException();
            logger.error("parse exception e=" + e.toString() + " line=" + f.getLineNumber() + " columns="
                    + f.getColumnNumber() + " local=" + f.getLocalizedMessage());
        }

    }
    return new String(answer);
}
 
Example 10
Source File: AbstractAtdl4jUserMessageHandler.java    From atdl4j with MIT License 5 votes vote down vote up
/**
 * Extracts the "message" value from Throwable.  Handles JAXBException.getLinkedException().getMessage().
 * 
 * @param e
 * @return
 */
public static String extractExceptionMessage( Throwable e )
{
	if ( e instanceof ValidationException )
	{
		ValidationException tempValidationException = (ValidationException) e;
		if ( tempValidationException.getMessage() != null )
		{
			// -- Add new lines after sentence (eg before "Rule Tested: [______]") --
			return tempValidationException.getMessage().replace( ".  ", ".\n\n" );
		}
		else
		{
			return tempValidationException.getMessage();
		}
	}
		// e.getMessage() is null if there is a JAXB parse error 
	else if (e.getMessage() != null)
	{
		return e.getMessage();
	}
	else if ( e instanceof JAXBException )
	{
		JAXBException tempJAXBException = (JAXBException) e;
		
		if ( ( tempJAXBException.getLinkedException() != null ) &&
			  ( tempJAXBException.getLinkedException().getMessage() != null ) )
		{ 
			return tempJAXBException.getLinkedException().getMessage();
		}
	}
	
		
	return e.toString();
}
 
Example 11
Source File: WkfService.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setMetaView(String defaultValue) {
  try {
    MetaView existingMetaView = workflow.getMetaView();

    ObjectViews formViews = XMLViews.fromXML(existingMetaView.getXml());
    FormView existingFormView = (FormView) formViews.getViews().get(0);
    String oldOnNew = existingFormView.getOnNew();

    String newOnNew = this.createAction(oldOnNew, defaultValue);

    FormView formView = existingFormView;
    formView.setExtends(addExtendItems(newOnNew));
    formView.setXmlId("studio-" + viewName);
    formView.setExtension(true);
    formView.setItems(null);
    formView.setMenubar(null);
    formView.setToolbar(null);

    MetaView newView =
        metaViewRepo
            .all()
            .filter(
                "self.name = ?1 AND self.model = ?2 AND self.type = ?3 AND self.xmlId = ?4",
                viewName,
                workflow.getModel(),
                "form",
                "studio-" + viewName)
            .fetchOne();

    if (newView == null) {
      newView = new MetaView();
      newView.setName(viewName);
      newView.setType(formView.getType());
      newView.setTitle(formView.getTitle());
      newView.setModel(formView.getModel());
      newView.setModule("axelor-studio");
    }
    newView.setXmlId(formView.getXmlId());
    newView.setExtension(true);
    newView.setXml(XMLViews.toXml(formView, true));
    saveMetaView(newView);

  } catch (JAXBException e) {
    String message = I18n.get("Invalid XML.");
    Throwable ex = e.getLinkedException();
    if (ex != null) {
      message = ex.getMessage().replaceFirst("[^:]+\\:(.*)", "$1");
    }
    throw new IllegalArgumentException(message);
  }
}
 
Example 12
Source File: SrsPanel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void exportReferenceSystems() {		
	try {
		setSettings();

		if (config.getProject().getDatabase().getReferenceSystems().isEmpty()) {
			log.error("There are no user-defined reference systems to be exported.");
			return;
		}

		viewController.clearConsole();
		viewController.setStatusText(Language.I18N.getString("main.status.database.srs.export.label"));

		String fileName = fileText.getText().trim();
		if (fileName.length() == 0) {
			log.error("Please specify the export file for the reference systems.");
			viewController.errorMessage(Language.I18N.getString("common.dialog.error.io.title"), Language.I18N.getString("pref.db.srs.error.write.msg"));
			return;
		}

		if ((!fileName.contains("."))) {
			fileName += ".xml";
			fileText.setText(fileName);
		}

		File file = new File(fileName);
		log.info("Writing reference systems to file '" + file.getAbsolutePath() + "'.");

		DatabaseSrsList refSys = new DatabaseSrsList();
		for (DatabaseSrs tmp : config.getProject().getDatabase().getReferenceSystems()) {
			DatabaseSrs copy = new DatabaseSrs(tmp);
			copy.setId(null);				
			refSys.addItem(copy);

			log.info("Writing reference system '" + tmp.getDescription() + "' (SRID: " + tmp.getSrid() + ").");
		}

		ConfigUtil.marshal(refSys, file, getJAXBContext());			
		log.info("Reference systems successfully written to file '" + file.getAbsolutePath() + "'.");
	} catch (JAXBException jaxb) {
		String msg = jaxb.getMessage();
		if (msg == null && jaxb.getLinkedException() != null)
			msg = jaxb.getLinkedException().getMessage();

		log.error("Failed to write file: " + msg);
		viewController.errorMessage(Language.I18N.getString("common.dialog.error.io.title"), 
				MessageFormat.format(Language.I18N.getString("common.dialog.file.write.error"), msg));
	} finally {
		viewController.setStatusText(Language.I18N.getString("main.status.ready.label"));
	}
}