List of usage examples for javax.xml.transform TransformerException TransformerException
public TransformerException(Throwable e)
From source file:nl.mpi.lamus.workspace.exporting.implementation.GeneralNodeExporterTest.java
@Test public void exportChangedMetadataNodeTransformerException() throws MalformedURLException, URISyntaxException, IOException, MetadataException, TransformerException, WorkspaceExportException { final String metadataExtension = "cmdi"; final int parentNodeWsID = 1; final String parentCorpusNamePathToClosestTopNode = ""; final int nodeWsID = 10; final String nodeName = "SomeNode"; final String nodeFilename = nodeName + FilenameUtils.EXTENSION_SEPARATOR_STR + metadataExtension; final URL nodeWsURL = new URL( "file:/workspace/" + workspace.getWorkspaceID() + File.separator + nodeFilename); final URI nodeArchiveURI = new URI(UUID.randomUUID().toString()); final URL nodeArchiveURL = new URL("http:/archive/location/TopNode/Corpusstructure/" + nodeFilename); final String nodeArchiveLocalPath = "file:/archive/location/TopNode/Corpusstructure/" + nodeFilename; final File nodeArchiveLocalFile = new File(URI.create(nodeArchiveLocalPath)); final boolean isNodeProtected = Boolean.FALSE; final String currentCorpusNamePathToClosestTopNode = "TopNode"; final boolean keepUnlinkedFiles = Boolean.FALSE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.SUBMIT_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.TREE_EXPORT; workspace.setTopNodeID(nodeWsID);//from w w w . j av a 2 s . co m workspace.setTopNodeArchiveURI(nodeArchiveURI); workspace.setTopNodeArchiveURL(nodeArchiveURL); final String expectedErrorMessage = "Error writing file for node " + nodeArchiveURI; final TransformerException expectedException = new TransformerException("some exception message"); checkLoggerInvocations(parentNodeWsID, nodeWsID); context.checking(new Expectations() { { oneOf(mockChildWsNode).isProtected(); will(returnValue(isNodeProtected)); oneOf(mockChildWsNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(nodeArchiveLocalFile)); oneOf(mockNodeUtil).isNodeMetadata(mockChildWsNode); will(returnValue(Boolean.TRUE)); oneOf(mockExporterHelper).getNamePathToUseForThisExporter(mockChildWsNode, mockParentWsNode, parentCorpusNamePathToClosestTopNode, Boolean.TRUE, generalNodeExporter.getClass()); will(returnValue(currentCorpusNamePathToClosestTopNode)); oneOf(mockWorkspaceTreeExporter).explore(workspace, mockChildWsNode, currentCorpusNamePathToClosestTopNode, keepUnlinkedFiles, submissionType, exportPhase); oneOf(mockChildWsNode).getWorkspaceURL(); will(returnValue(nodeWsURL)); oneOf(mockMetadataAPI).getMetadataDocument(nodeWsURL); will(returnValue(mockChildCmdiDocument)); oneOf(mockWorkspaceFileHandler).getStreamResultForNodeFile(nodeArchiveLocalFile); will(returnValue(mockStreamResult)); oneOf(mockMetadataAPI).writeMetadataDocument(mockChildCmdiDocument, mockStreamResult); will(throwException(expectedException)); //logger oneOf(mockChildWsNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); } }); try { generalNodeExporter.exportNode(workspace, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (WorkspaceExportException ex) { assertEquals("Message different from expected", expectedErrorMessage, ex.getMessage()); assertEquals("Workspace ID different from expected", workspace.getWorkspaceID(), ex.getWorkspaceID()); assertEquals("Cause different from expected", expectedException, ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.management.implementation.LamusWorkspaceNodeLinkManagerTest.java
@Test public void linkNodesTransformerException() throws MalformedURLException, URISyntaxException, IOException, MetadataException, TransformerException, WorkspaceException, ProtectedNodeException { final int workspaceID = 1; final int parentNodeID = 2; final int childNodeID = 3; final URL parentURL = new URL("file:/lamus/workspace/" + workspaceID + "/parent.cmdi"); final URI parentProfileLocation = URI.create("http:/schema/location/profile_bla_bla"); final URL childURL = new URL("file:/lamus/workspace/" + workspaceID + "/child.cmdi"); final URI childURI = childURL.toURI(); final String childMimetype = "text/x-cmdi+xml"; final boolean isInfoFile = Boolean.FALSE; final String componentPath = "collection"; final Collection<WorkspaceNode> emptyParentNodes = new ArrayList<>(); final String expectedErrorMessage = "Error creating reference in document with node ID " + parentNodeID; final TransformerException expectedException = new TransformerException("some exception message"); context.checking(new Expectations() { {//from w w w .jav a 2 s . c om allowing(mockParentNode).getWorkspaceID(); will(returnValue(workspaceID)); allowing(mockParentNode).getWorkspaceNodeID(); will(returnValue(parentNodeID)); allowing(mockChildNode).getWorkspaceNodeID(); will(returnValue(childNodeID)); allowing(mockParentNode).getWorkspaceURL(); will(returnValue(parentURL)); allowing(mockChildNode).getWorkspaceURL(); will(returnValue(childURL)); allowing(mockChildNode).getArchiveURI(); will(returnValue(null)); allowing(mockChildNode).getType(); will(returnValue(WorkspaceNodeType.METADATA)); allowing(mockParentNode).getProfileSchemaURI(); will(returnValue(parentProfileLocation)); oneOf(mockNodeUtil).isNodeMetadata(mockParentNode); will(returnValue(Boolean.TRUE)); oneOf(mockParentNode).isProtected(); will(returnValue(Boolean.FALSE)); oneOf(mockWorkspaceDao).getParentWorkspaceNodes(childNodeID); will(returnValue(emptyParentNodes)); oneOf(mockMetadataAPI).getMetadataDocument(parentURL); will(returnValue(mockParentDocument)); oneOf(mockNodeUtil).isNodeMetadata(mockChildNode); will(returnValue(Boolean.TRUE)); oneOf(mockMetadataApiBridge).isMetadataReferenceAllowedInProfile(parentProfileLocation); will(returnValue(Boolean.TRUE)); oneOf(mockChildNode).getFormat(); will(returnValue(childMimetype)); oneOf(mockParentDocument).createDocumentMetadataReference(null, childURI, childMimetype); will(returnValue(mockChildMetadataReference)); allowing(mockChildMetadataReference).getMimetype(); will(returnValue(childMimetype)); oneOf(mockMetadataApiBridge).getComponentPathForProfileAndReferenceType(parentProfileLocation, childMimetype, null, Boolean.FALSE); will(returnValue(componentPath)); oneOf(mockMetadataApiBridge).createComponentPathWithin(mockParentDocument, componentPath, mockChildNode); will(returnValue(mockCmdiContainerMetadataElement)); oneOf(mockMetadataApiBridge).addReferenceInComponent(mockCmdiContainerMetadataElement, mockChildMetadataReference); will(returnValue(mockRetrievedResourceProxy)); oneOf(mockMetadataApiBridge).saveMetadataDocument(mockParentDocument, parentURL); will(throwException(expectedException)); } }); try { nodeLinkManager.linkNodes(mockParentNode, mockChildNode, isInfoFile); fail("should have thrown exception"); } catch (WorkspaceException ex) { assertEquals("Message different from expected", expectedErrorMessage, ex.getMessage()); assertEquals("Workspace ID different from expected", workspaceID, ex.getWorkspaceID()); assertEquals("Cause different from expected", expectedException, ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.management.implementation.LamusWorkspaceNodeLinkManagerTest.java
@Test public void unlinkNodesTransformerException() throws MalformedURLException, URISyntaxException, IOException, MetadataException, TransformerException, WorkspaceException, WorkspaceException, ProtectedNodeException { final int workspaceID = 1; final int parentNodeID = 2; final URL parentURL = new URL("file:/lamus/workspace/" + workspaceID + "/parent.cmdi"); final URI parentProfileLocation = URI.create("http:/schema/location/profile_bla_bla"); final URL childURL = new URL("file:/lamus/workspace/" + workspaceID + "/child.txt"); final URI childURI = childURL.toURI(); final int childNodeID = 3; final WorkspaceNodeType childType = WorkspaceNodeType.RESOURCE_WRITTEN; final String childRefId = "ref_1234546u75645"; final String componentPath = "/lat-session/WrittenResource"; final String expectedErrorMessage = "Error removing reference in document with node ID " + childNodeID; final TransformerException expectedException = new TransformerException("some exception message"); context.checking(new Expectations() { {//from ww w .ja v a2 s . c o m allowing(mockParentNode).getWorkspaceID(); will(returnValue(workspaceID)); allowing(mockParentNode).getWorkspaceNodeID(); will(returnValue(parentNodeID)); allowing(mockParentNode).getWorkspaceURL(); will(returnValue(parentURL)); allowing(mockParentNode).isProtected(); will(returnValue(Boolean.FALSE)); allowing(mockParentNode).getProfileSchemaURI(); will(returnValue(parentProfileLocation)); allowing(mockChildNode).getWorkspaceNodeID(); will(returnValue(childNodeID)); allowing(mockChildNode).getWorkspaceURL(); will(returnValue(childURL)); allowing(mockChildNode).getType(); will(returnValue(childType)); oneOf(mockMetadataAPI).getMetadataDocument(parentURL); will(returnValue(mockParentDocument)); oneOf(mockParentDocument).getDocumentReferenceByLocation(childURI); will(returnValue(mockChildReferenceWithHandle)); oneOf(mockNodeUtil).isNodeInfoFile(mockChildNode); will(returnValue(Boolean.FALSE)); oneOf(mockChildReferenceWithHandle).getMimetype(); will(returnValue(null)); oneOf(mockMetadataApiBridge).getComponentPathForProfileAndReferenceType(parentProfileLocation, null, childType, Boolean.FALSE); will(returnValue(componentPath)); oneOf(mockChildReferenceWithHandle).getId(); will(returnValue(childRefId)); oneOf(mockMetadataApiBridge).getComponent(mockParentDocument, componentPath, childRefId); will(returnValue(mockChildComponent)); oneOf(mockMetadataApiBridge).removeComponent(mockChildComponent); oneOf(mockParentDocument).removeDocumentReference(mockChildReferenceWithHandle); will(returnValue(mockChildReferenceWithHandle)); oneOf(mockMetadataApiBridge).saveMetadataDocument(mockParentDocument, parentURL); will(throwException(expectedException)); } }); stub(method(FileUtils.class, "toFile", URL.class)).toReturn(mockParentFile); try { nodeLinkManager.unlinkNodes(mockParentNode, mockChildNode); fail("should have thrown exception"); } catch (WorkspaceException ex) { assertEquals("Message different from expected", expectedErrorMessage, ex.getMessage()); assertEquals("Workspace ID different from expeted", workspaceID, ex.getWorkspaceID()); assertEquals("Cause different from expected", expectedException, ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.management.implementation.LamusWorkspaceNodeLinkManagerTest.java
@Test public void removeArchiveUri_TransformerException_SaveChildDocument() throws WorkspaceException, MalformedURLException, URISyntaxException, IOException, MetadataException, TransformerException { final int workspaceID = 1; final int parentID = 100; final URL parentURL = new URL("file:/lamus/workspace/" + workspaceID + "/parent.cmdi"); final int childID = 200; final URL childURL = new URL("file:/lamus/workspace/" + workspaceID + "/child.cmdi"); final URI childURI = childURL.toURI(); final URI childArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final TransformerException expectedCause = new TransformerException("some exception message"); String expectedMessage = "Error when trying to remove URI of node " + childID + ", referenced in node " + parentID;/*from w ww .ja va 2 s . c om*/ context.checking(new Expectations() { { //logger oneOf(mockParentNode).getWorkspaceID(); will(returnValue(workspaceID)); oneOf(mockParentNode).getWorkspaceNodeID(); will(returnValue(parentID)); oneOf(mockChildNode).getWorkspaceNodeID(); will(returnValue(childID)); oneOf(mockChildNode).getArchiveURI(); will(returnValue(childArchiveURI)); oneOf(mockParentNode).getWorkspaceURL(); will(returnValue(parentURL)); oneOf(mockMetadataAPI).getMetadataDocument(parentURL); will(returnValue(mockParentDocument)); oneOf(mockChildNode).getArchiveURI(); will(returnValue(childArchiveURI)); oneOf(mockMetadataApiBridge).getDocumentReferenceByDoubleCheckingURI(mockParentDocument, childArchiveURI); will(returnValue(mockChildMetadataResourceProxy)); oneOf(mockChildNode).getWorkspaceURL(); will(returnValue(childURL)); oneOf(mockChildMetadataResourceProxy).setURI(childURI); oneOf(mockParentNode).getWorkspaceURL(); will(returnValue(parentURL)); oneOf(mockMetadataApiBridge).saveMetadataDocument(mockParentDocument, parentURL); oneOf(mockNodeUtil).isNodeMetadata(mockChildNode); will(returnValue(Boolean.TRUE)); //remove self handle oneOf(mockChildNode).getWorkspaceURL(); will(returnValue(childURL)); oneOf(mockMetadataAPI).getMetadataDocument(childURL); will(returnValue(mockChildCmdiDocument)); oneOf(mockChildCmdiDocument).setHandle(null); oneOf(mockChildNode).getWorkspaceURL(); will(returnValue(childURL)); oneOf(mockMetadataApiBridge).saveMetadataDocument(mockChildCmdiDocument, childURL); will(throwException(expectedCause)); //exception oneOf(mockChildNode).getWorkspaceNodeID(); will(returnValue(childID)); oneOf(mockParentNode).getWorkspaceNodeID(); will(returnValue(parentID)); oneOf(mockParentNode).getWorkspaceID(); will(returnValue(workspaceID)); } }); try { nodeLinkManager.removeArchiveUriFromChildNode(mockParentNode, mockChildNode); fail("should have thrown exception"); } catch (WorkspaceException ex) { assertEquals("Exception message different from expected", expectedMessage, ex.getMessage()); assertEquals("Exception cause different from expected", expectedCause, ex.getCause()); } }
From source file:org.alfresco.repo.template.XSLTProcessor.java
/** * @param templateSource/* w ww .j a v a 2 s . c om*/ * @param model * @param out */ private void process(TemplateSource templateSource, Object model, Writer out) { if ((model == null) || !XSLTemplateModel.class.isAssignableFrom(model.getClass())) { throw new IllegalArgumentException("\"model\" must be an XSLTemplateModel object: " + model); } XSLTemplateModel xsltModel = (XSLTemplateModel) model; System.setProperty("org.apache.xalan.extensions.bsf.BSFManager", BSFManager.class.getName()); Document xslTemplate; try { xslTemplate = XMLUtil.parse(templateSource.getReader(defaultEncoding)); } catch (IOException ex) { throw new TemplateException(MSG_UNABLE_TO_READ_TEMPLATE, new Object[] { ex.getMessage() }, ex); } catch (SAXException sax) { throw new TemplateException(MSG_UNABLE_TO_PARSE_TEMPLATE, new Object[] { sax.getMessage() }, sax); } finally { try { templateSource.close(); } catch (IOException ex) { // There's little to be done here. Log it and carry on log.warn("Error while trying to close template stream", ex); } } List<String> scriptIds = addScripts(xsltModel, xslTemplate); addParameters(xsltModel, xslTemplate); final LinkedList<TransformerException> errors = new LinkedList<TransformerException>(); final ErrorListener errorListener = new ErrorListener() { public void error(final TransformerException te) throws TransformerException { log.debug("error " + te.getMessageAndLocation()); errors.add(te); } public void fatalError(final TransformerException te) throws TransformerException { log.debug("fatalError " + te.getMessageAndLocation()); throw te; } public void warning(final TransformerException te) throws TransformerException { log.debug("warning " + te.getMessageAndLocation()); errors.add(te); } }; final TemplateSource resourceSource = templateSource; final URIResolver uriResolver = new URIResolver() { public Source resolve(final String href, String base) throws TransformerException { if (log.isDebugEnabled()) { log.debug("request to resolve href " + href + " using base " + base); } InputStream in = null; try { in = resourceSource.getResource(href); if (in == null) { throw new TransformerException("unable to resolve href " + href); } Document d = XMLUtil.parse(in); if (log.isDebugEnabled()) { log.debug("loaded " + XMLUtil.toString(d)); } return new DOMSource(d); } catch (TransformerException ex) { throw ex; } catch (Exception e) { throw new TransformerException("unable to load " + href, e); } } }; Source xmlSource = this.getXMLSource(xsltModel); Transformer t = null; try { final TransformerFactory tf = TransformerFactory.newInstance(); tf.setErrorListener(errorListener); tf.setURIResolver(uriResolver); if (log.isDebugEnabled()) { log.debug("xslTemplate: \n" + XMLUtil.toString(xslTemplate)); } t = tf.newTransformer(new DOMSource(xslTemplate)); if (errors.size() != 0) { final StringBuilder msg = new StringBuilder("errors encountered creating tranformer ... \n"); for (TransformerException te : errors) { msg.append(te.getMessageAndLocation()).append("\n"); } throw new TemplateException(msg.toString()); } t.setErrorListener(errorListener); t.setURIResolver(uriResolver); t.setParameter("versionParam", "2.0"); } catch (TransformerConfigurationException tce) { log.error(tce); throw new TemplateException(tce.getMessage(), tce); } try { t.transform(xmlSource, new StreamResult(out)); } catch (TransformerException te) { log.error(te.getMessageAndLocation()); throw new TemplateException(te.getMessageAndLocation(), te); } catch (Exception e) { log.error("unexpected error " + e); throw new TemplateException(e.getMessage(), e); } finally { //Clear out any scripts that were created for this transform if (!scriptIds.isEmpty()) { XSLTProcessorMethodInvoker.removeMethods(scriptIds); } } if (errors.size() != 0) { final StringBuilder msg = new StringBuilder("errors encountered during transformation ... \n"); for (TransformerException te : errors) { msg.append(te.getMessageAndLocation()).append("\n"); } throw new TemplateException(msg.toString()); } }
From source file:org.apache.camel.builder.xml.XsltUriResolver.java
public Source resolve(String href, String base) throws TransformerException { if (ObjectHelper.isEmpty(href)) { throw new TransformerException("include href is empty"); }/*from www .ja va 2 s. c o m*/ if (LOG.isTraceEnabled()) { LOG.trace("Resolving URI with href: " + href + " and base: " + base); } if (href.startsWith("classpath:")) { if (LOG.isDebugEnabled()) { LOG.debug("Resolving URI from classpath: " + href); } String name = ObjectHelper.after(href, ":"); InputStream is = resolver.loadResourceAsStream(name); if (is == null) { throw new TransformerException("Cannot find " + name + " in classpath"); } return new StreamSource(is); } if (href.startsWith("file:")) { if (LOG.isDebugEnabled()) { LOG.debug("Resolving URI from file: " + href); } String name = ObjectHelper.after(href, ":"); File file = new File(name); return new StreamSource(file); } // okay then its relative to the starting location from the XSLT component String path = FileUtil.onlyPath(location); if (ObjectHelper.isEmpty(path)) { // default to use classpath: location path = "classpath:" + href; return resolve(path, base); } else { // default to use classpath: location path = "classpath:" + path + File.separator + href; return resolve(path, base); } }
From source file:org.apache.cocoon.util.TraxErrorHandler.java
public void fatalError(TransformerException exception) throws TransformerException { final String message = getMessage(exception); if (this.logger != null) { this.logger.fatal(message, exception); } else {/* w w w .jav a2 s.c o m*/ System.out.println("FATAL-ERROR: " + message); } warnings.append("Fatal: "); warnings.append(message); warnings.append("\n"); try { throw new TransformerException(warnings.toString()); } finally { warnings = new StringBuffer(); } }
From source file:org.apache.maven.doxia.module.fo.FoAggregateSinkTest.java
/** * Test the FO PDF generation with some special characters in company name. *//*from www.j av a2 s . co m*/ public void testSpecialCharacters() throws IOException, TransformerException { DocumentModel model = new DocumentModel(); DocumentCover cover = new DocumentCover(); cover.setCompanyName("Partner & Friends"); cover.setCoverTitle("A Masterpice in Encoding Theory <>&"); cover.setCoverSubTitle("Some nice Encodings & <METHODS>"); cover.setProjectName("A Masterpice in Encoding Theory <>&"); cover.setAuthor("Partner & Friends"); model.setCover(cover); File foFile = File.createTempFile("fo-test", ".fo"); File pdfFile = File.createTempFile("fo-test", ".pdf"); try { sink = new FoAggregateSink(WriterFactory.newXmlWriter(foFile)); sink.setDocumentModel(model); sink.setDocumentTitle("A Masterpice in Encoding Theory <>&"); sink.beginDocument(); sink.coverPage(); // sink.toc(); sink.endDocument(); } finally { sink.close(); } try { FoUtils.convertFO2PDF(foFile, pdfFile, null, model); } catch (TransformerException e) { if ((e.getCause() != null) && (e.getCause() instanceof SAXParseException)) { SAXParseException sax = (SAXParseException) e.getCause(); StringBuffer sb = new StringBuffer(); sb.append("Error creating PDF from ").append(foFile.getAbsolutePath()).append(":") .append(sax.getLineNumber()).append(":").append(sax.getColumnNumber()).append("\n"); sb.append(e.getMessage()); throw new RuntimeException(sb.toString()); } throw new TransformerException("Error creating PDF from " + foFile + ": " + e.getMessage()); } }
From source file:org.apache.ode.utils.DOMUtils.java
public static Document toDOMDocument(Node node) throws TransformerException { // If the node is the document, just cast it if (node instanceof Document) { return (Document) node; // If the node is an element } else if (node instanceof Element) { Element elem = (Element) node; // If this is the root element, return its owner document if (elem.getOwnerDocument().getDocumentElement() == elem) { return elem.getOwnerDocument(); // else, create a new doc and copy the element inside it } else {/*from w w w . j a v a 2 s . c o m*/ Document doc = newDocument(); doc.appendChild(doc.importNode(node, true)); return doc; } // other element types are not handled } else { throw new TransformerException("Unable to convert DOM node to a Document"); } }
From source file:org.apache.servicemix.smpp.marshaler.DefaultSmppMarshaler.java
public SubmitSM fromNMS(Connection conn, MessageExchange exchange, NormalizedMessage normalizedMessage) throws TransformerException { SubmitSM sm = null;/*w ww . jav a 2 s .c o m*/ String source = null; String destination = null; String text = ""; String ton = null; String npi = null; try { // convert message content to DOM document Document doc = transformer.toDOMDocument(normalizedMessage); // normalize text representation doc.getDocumentElement().normalize(); NodeList node = doc.getElementsByTagName(TAG_SOURCE); if (node != null && node.getLength() > 0) { source = node.item(0).getChildNodes().item(0).getNodeValue(); LOG.debug(TAG_SOURCE + ": " + source); } node = doc.getElementsByTagName(TAG_DESTINATION); if (node != null && node.getLength() > 0) { destination = node.item(0).getChildNodes().item(0).getNodeValue(); LOG.debug(TAG_DESTINATION + ": " + destination); } node = doc.getElementsByTagName(TAG_TEXT); if (node != null && node.getLength() > 0) { text = node.item(0).getChildNodes().item(0).getNodeValue(); LOG.debug(TAG_TEXT + ": " + text); } node = doc.getElementsByTagName(TAG_TON); if (node != null && node.getLength() > 0) { ton = node.item(0).getChildNodes().item(0).getNodeValue(); LOG.debug(TAG_TON + ": " + ton); } node = doc.getElementsByTagName(TAG_NPI); if (node != null && node.getLength() > 0) { npi = node.item(0).getChildNodes().item(0).getNodeValue(); LOG.debug(TAG_NPI + ": " + npi); } // check for mandatory attribute "destination" if (destination == null) { throw new TransformerException("Invalid message content. Missing tag: " + TAG_DESTINATION); } // check for mandatory attribute "ton" if (ton == null) { throw new TransformerException("Invalid message content. Missing tag: " + TAG_TON); } // check for mandatory attribute "npi" if (npi == null) { throw new TransformerException("Invalid message content. Missing tag: " + TAG_NPI); } try { // create the submit sm object sm = (SubmitSM) conn.newInstance(SMPPPacket.SUBMIT_SM); // create the address Address addr = new Address(); // configure the address addr.setAddress(destination); addr.setNPI(Integer.parseInt(npi)); addr.setTON(Integer.parseInt(ton)); // configure the submit sm to use the address sm.setDestination(addr); // set the short message text sm.setMessageText(text); } catch (Exception ex) { throw new TransformerException(ex); } } catch (Exception e) { throw new TransformerException(e); } return sm; }