List of usage examples for javax.xml.stream XMLStreamException printStackTrace
public void printStackTrace()
From source file:fr.openwide.talendalfresco.rest.client.RestAuthenticationTest.java
public void testRestLogin() { // create client and configure it HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); // instantiating a new method and configuring it GetMethod method = new GetMethod(restCommandUrlPrefix + "login"); method.setFollowRedirects(true); // ? // Provide custom retry handler is necessary (?) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); NameValuePair[] params = new NameValuePair[] { new NameValuePair("username", "admin"), new NameValuePair("password", "admin") }; method.setQueryString(params);// www . ja va 2 s.c o m try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); // TODO rm HashSet<String> defaultElementSet = new HashSet<String>( Arrays.asList(new String[] { RestConstants.TAG_COMMAND, RestConstants.TAG_CODE, RestConstants.TAG_CONTENT, RestConstants.TAG_ERROR, RestConstants.TAG_MESSAGE })); HashMap<String, String> elementValueMap = new HashMap<String, String>(6); try { XMLEventReader xmlReader = XmlHelper.getXMLInputFactory() .createXMLEventReader(new ByteArrayInputStream(responseBody)); StringBuffer singleLevelTextBuf = null; while (xmlReader.hasNext()) { XMLEvent event = xmlReader.nextEvent(); switch (event.getEventType()) { case XMLEvent.CHARACTERS: case XMLEvent.CDATA: if (singleLevelTextBuf != null) { singleLevelTextBuf.append(event.asCharacters().getData()); } // else element not meaningful break; case XMLEvent.START_ELEMENT: StartElement startElement = event.asStartElement(); String elementName = startElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName) // TODO another command specific level || "ticket".equals(elementName)) { // reinit buffer at start of meaningful elements singleLevelTextBuf = new StringBuffer(); } else { singleLevelTextBuf = null; // not useful } break; case XMLEvent.END_ELEMENT: if (singleLevelTextBuf == null) { break; // element not meaningful } // TODO or merely put it in the map since the element has been tested at start EndElement endElement = event.asEndElement(); elementName = endElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName)) { String value = singleLevelTextBuf.toString(); elementValueMap.put(elementName, value); // TODO test if it is code and it is not OK, break to error handling } // TODO another command specific level else if ("ticket".equals(elementName)) { ticket = singleLevelTextBuf.toString(); } // singleLevelTextBuf = new StringBuffer(); // no ! in start break; } } } catch (XMLStreamException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Throwable t) { // TODO Auto-generated catch block t.printStackTrace(); //throw t; } String code = elementValueMap.get(RestConstants.TAG_CODE); assertTrue(RestConstants.CODE_OK.equals(code)); System.out.println("got ticket " + ticket); } catch (HttpException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:eu.interedition.collatex.tools.CollationServer.java
public void service(Request request, Response response) throws Exception { final Deque<String> path = path(request); if (path.isEmpty() || !"collate".equals(path.pop())) { response.sendError(404);//from w ww . j a va2s. c om return; } final SimpleCollation collation = JsonProcessor.read(request.getInputStream()); if (maxCollationSize > 0) { for (SimpleWitness witness : collation.getWitnesses()) { final int witnessLength = witness.getTokens().stream().filter(t -> t instanceof SimpleToken) .map(t -> (SimpleToken) t).mapToInt(t -> t.getContent().length()).sum(); if (witnessLength > maxCollationSize) { response.sendError(413, "Request Entity Too Large"); return; } } } response.suspend(60, TimeUnit.SECONDS, new EmptyCompletionHandler<>()); collationThreads.submit(() -> { try { final VariantGraph graph = new VariantGraph(); collation.collate(graph); // CORS support response.setHeader("Access-Control-Allow-Origin", Optional.ofNullable(request.getHeader("Origin")).orElse("*")); response.setHeader("Access-Control-Allow-Methods", Optional.ofNullable(request.getHeader("Access-Control-Request-Method")) .orElse("GET, POST, HEAD, OPTIONS")); response.setHeader("Access-Control-Allow-Headers", Optional.ofNullable(request.getHeader("Access-Control-Request-Headers")) .orElse("Content-Type, Accept, X-Requested-With")); response.setHeader("Access-Control-Max-Age", "86400"); response.setHeader("Access-Control-Allow-Credentials", "true"); final String clientAccepts = Optional.ofNullable(request.getHeader(Header.Accept)).orElse(""); if (clientAccepts.contains("text/plain")) { response.setContentType("text/plain"); response.setCharacterEncoding("utf-8"); try (final Writer out = response.getWriter()) { new SimpleVariantGraphSerializer(graph).toDot(out); } response.resume(); } else if (clientAccepts.contains("application/tei+xml")) { XMLStreamWriter xml = null; try { response.setContentType("application/tei+xml"); try (OutputStream responseStream = response.getOutputStream()) { xml = XMLOutputFactory.newInstance().createXMLStreamWriter(responseStream); xml.writeStartDocument(); new SimpleVariantGraphSerializer(graph).toTEI(xml); xml.writeEndDocument(); } finally { if (xml != null) { xml.close(); } } response.resume(); } catch (XMLStreamException e) { e.printStackTrace(); } } else if (clientAccepts.contains("application/graphml+xml")) { XMLStreamWriter xml = null; try { response.setContentType("application/graphml+xml"); try (OutputStream responseStream = response.getOutputStream()) { xml = XMLOutputFactory.newInstance().createXMLStreamWriter(responseStream); xml.writeStartDocument(); new SimpleVariantGraphSerializer(graph).toGraphML(xml); xml.writeEndDocument(); } finally { if (xml != null) { xml.close(); } } response.resume(); } catch (XMLStreamException e) { e.printStackTrace(); } } else if (clientAccepts.contains("image/svg+xml")) { if (dotPath == null) { response.sendError(204); response.resume(); } else { final StringWriter dot = new StringWriter(); new SimpleVariantGraphSerializer(graph).toDot(dot); final Process dotProc = new ProcessBuilder(dotPath, "-Grankdir=LR", "-Gid=VariantGraph", "-Tsvg").start(); final StringWriter errors = new StringWriter(); CompletableFuture.allOf(CompletableFuture.runAsync(() -> { final char[] buf = new char[8192]; try (final Reader errorStream = new InputStreamReader(dotProc.getErrorStream())) { int len; while ((len = errorStream.read(buf)) >= 0) { errors.write(buf, 0, len); } } catch (IOException e) { throw new CompletionException(e); } }, processThreads), CompletableFuture.runAsync(() -> { try (final Writer dotProcStream = new OutputStreamWriter(dotProc.getOutputStream(), "UTF-8")) { dotProcStream.write(dot.toString()); } catch (IOException e) { throw new CompletionException(e); } }, processThreads), CompletableFuture.runAsync(() -> { response.setContentType("image/svg+xml"); final byte[] buf = new byte[8192]; try (final InputStream in = dotProc.getInputStream(); final OutputStream out = response.getOutputStream()) { int len; while ((len = in.read(buf)) >= 0) { out.write(buf, 0, len); } } catch (IOException e) { throw new CompletionException(e); } }, processThreads), CompletableFuture.runAsync(() -> { try { if (!dotProc.waitFor(60, TimeUnit.SECONDS)) { throw new CompletionException(new RuntimeException( "dot processing took longer than 60 seconds, process was timed out.")); } if (dotProc.exitValue() != 0) { throw new CompletionException(new IllegalStateException(errors.toString())); } } catch (InterruptedException e) { throw new CompletionException(e); } }, processThreads)).exceptionally(t -> { t.printStackTrace(); return null; }).thenRunAsync(response::resume, processThreads); } } else { response.setContentType("application/json"); try (final OutputStream responseStream = response.getOutputStream()) { JsonProcessor.write(graph, responseStream); } response.resume(); } } catch (IOException e) { // FIXME: ignored } }); }
From source file:fr.openwide.talendalfresco.rest.client.importer.RestImportFileTest.java
public void login() { // create client and configure it HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); // instantiating a new method and configuring it GetMethod method = new GetMethod(restCommandUrlPrefix + "login"); method.setFollowRedirects(true); // ? // Provide custom retry handler is necessary (?) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); NameValuePair[] params = new NameValuePair[] { new NameValuePair("username", "admin"), new NameValuePair("password", "admin") }; method.setQueryString(params);/*from w w w. j a v a 2s. c om*/ try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); // TODO rm HashSet<String> defaultElementSet = new HashSet<String>( Arrays.asList(new String[] { RestConstants.TAG_COMMAND, RestConstants.TAG_CODE, RestConstants.TAG_CONTENT, RestConstants.TAG_ERROR, RestConstants.TAG_MESSAGE })); HashMap<String, String> elementValueMap = new HashMap<String, String>(6); try { XMLEventReader xmlReader = XmlHelper.getXMLInputFactory() .createXMLEventReader(new ByteArrayInputStream(responseBody)); StringBuffer singleLevelTextBuf = null; while (xmlReader.hasNext()) { XMLEvent event = xmlReader.nextEvent(); switch (event.getEventType()) { case XMLEvent.CHARACTERS: case XMLEvent.CDATA: if (singleLevelTextBuf != null) { singleLevelTextBuf.append(event.asCharacters().getData()); } // else element not meaningful break; case XMLEvent.START_ELEMENT: StartElement startElement = event.asStartElement(); String elementName = startElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName) // TODO another command specific level || "ticket".equals(elementName)) { // reinit buffer at start of meaningful elements singleLevelTextBuf = new StringBuffer(); } else { singleLevelTextBuf = null; // not useful } break; case XMLEvent.END_ELEMENT: if (singleLevelTextBuf == null) { break; // element not meaningful } // TODO or merely put it in the map since the element has been tested at start EndElement endElement = event.asEndElement(); elementName = endElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName)) { String value = singleLevelTextBuf.toString(); elementValueMap.put(elementName, value); // TODO test if it is code and it is not OK, break to error handling } // TODO another command specific level else if ("ticket".equals(elementName)) { ticket = singleLevelTextBuf.toString(); } // singleLevelTextBuf = new StringBuffer(); // no ! in start break; } } } catch (XMLStreamException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Throwable t) { // TODO Auto-generated catch block t.printStackTrace(); //throw t; } String code = elementValueMap.get(RestConstants.TAG_CODE); assertTrue(RestConstants.CODE_OK.equals(code)); System.out.println("got ticket " + ticket); } catch (HttpException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:edu.jhu.pha.vospace.node.Node.java
public String getXmlMetadata(Detail detail) { StringWriter jobWriter = new StringWriter(); try {/*from w ww . j ava 2 s. co m*/ XMLStreamWriter xsw = XMLOutputFactory.newInstance().createXMLStreamWriter(jobWriter); xsw.writeStartDocument(); xsw.setDefaultNamespace(VOS_NAMESPACE); xsw.writeStartElement("node"); xsw.writeNamespace("xsi", XSI_NAMESPACE); xsw.writeNamespace(null, VOS_NAMESPACE); xsw.writeAttribute("xsi:type", this.getType().getTypeName()); xsw.writeAttribute("uri", this.getUri().toString()); if (detail == Detail.max) { xsw.writeStartElement("properties"); Map<String, String> properties = this.getMetastore().getProperties(this.getUri()); properties.put(LENGTH_PROPERTY, Long.toString(getNodeInfo().getSize())); properties.put(DATE_PROPERTY, dropboxDateFormat.format(getNodeInfo().getMtime())); if (this.getType() == NodeType.DATA_NODE || this.getType() == NodeType.STRUCTURED_DATA_NODE || this.getType() == NodeType.UNSTRUCTURED_DATA_NODE) { properties.put(CONTENTTYPE_PROPERTY, getNodeInfo().getContentType()); } for (String propUri : properties.keySet()) { xsw.writeStartElement("property"); xsw.writeAttribute("uri", propUri); xsw.writeCharacters(properties.get(propUri)); xsw.writeEndElement(); } xsw.writeEndElement(); xsw.writeStartElement("accepts"); xsw.writeEndElement(); xsw.writeStartElement("provides"); xsw.writeEndElement(); xsw.writeStartElement("capabilities"); xsw.writeEndElement(); if (this.getType() == NodeType.CONTAINER_NODE) { NodesList childrenList = ((ContainerNode) this).getDirectChildren(false, 0, -1); List<Node> children = childrenList.getNodesList(); xsw.writeStartElement("nodes"); for (Node childNode : children) { xsw.writeStartElement("node"); xsw.writeAttribute("uri", childNode.getUri().getId().toString()); xsw.writeEndElement(); } xsw.writeEndElement(); } } xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); } catch (XMLStreamException e) { e.printStackTrace(); throw new InternalServerErrorException(e); } return jobWriter.getBuffer().toString(); }
From source file:fr.openwide.talendalfresco.rest.client.importer.RestImportFileTest.java
public void testSingleFileImport() { // create client and configure it HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); // instantiating a new method and configuring it PostMethod method = new PostMethod(restCommandUrlPrefix + "import"); // Provide custom retry handler is necessary (?) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); NameValuePair[] params = new NameValuePair[] { new NameValuePair("path", "/app:company_home"), new NameValuePair("ticket", ticket) }; method.setQueryString(params);//from ww w. j a v a 2 s. co m try { //method.setRequestBody(new NameValuePair[] { // new NameValuePair("path", "/app:company_home") }); FileInputStream acpXmlIs = new FileInputStream(SAMPLE_SINGLE_FILE_PATH); InputStreamRequestEntity entity = new InputStreamRequestEntity(acpXmlIs); //InputStreamRequestEntity entity = new InputStreamRequestEntity(acpXmlIs, "text/xml; charset=ISO-8859-1"); method.setRequestEntity(entity); } catch (IOException ioex) { fail("ACP XML file not found " + ioex.getMessage()); } try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); // TODO rm HashSet<String> defaultElementSet = new HashSet<String>( Arrays.asList(new String[] { RestConstants.TAG_COMMAND, RestConstants.TAG_CODE, RestConstants.TAG_CONTENT, RestConstants.TAG_ERROR, RestConstants.TAG_MESSAGE })); HashMap<String, String> elementValueMap = new HashMap<String, String>(6); try { XMLEventReader xmlReader = XmlHelper.getXMLInputFactory() .createXMLEventReader(new ByteArrayInputStream(responseBody)); StringBuffer singleLevelTextBuf = null; while (xmlReader.hasNext()) { XMLEvent event = xmlReader.nextEvent(); switch (event.getEventType()) { case XMLEvent.CHARACTERS: case XMLEvent.CDATA: if (singleLevelTextBuf != null) { singleLevelTextBuf.append(event.asCharacters().getData()); } // else element not meaningful break; case XMLEvent.START_ELEMENT: StartElement startElement = event.asStartElement(); String elementName = startElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName) // TODO another command specific level || "ticket".equals(elementName)) { // reinit buffer at start of meaningful elements singleLevelTextBuf = new StringBuffer(); } else { singleLevelTextBuf = null; // not useful } break; case XMLEvent.END_ELEMENT: if (singleLevelTextBuf == null) { break; // element not meaningful } // TODO or merely put it in the map since the element has been tested at start EndElement endElement = event.asEndElement(); elementName = endElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName)) { String value = singleLevelTextBuf.toString(); elementValueMap.put(elementName, value); // TODO test if it is code and it is not OK, break to error handling } // TODO another command specific level else if ("ticket".equals(elementName)) { ticket = singleLevelTextBuf.toString(); } // singleLevelTextBuf = new StringBuffer(); // no ! in start break; } } } catch (XMLStreamException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Throwable t) { // TODO Auto-generated catch block t.printStackTrace(); //throw t; } String code = elementValueMap.get(RestConstants.TAG_CODE); assertTrue(RestConstants.CODE_OK.equals(code)); System.out.println("got ticket " + ticket); } catch (HttpException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:com.biomeris.i2b2.export.ws.ExportService.java
public OMElement testSession(OMElement inputElement) throws I2B2Exception, JsonSyntaxException { Assert.notNull(inputElement, "Export Cell: Incoming request is null"); MessageHeaderType messageHeaderType = MessageManager.extractReqMess(inputElement).getMessageHeader(); String requestJsonStr = MessageManager.extractObsBlob(inputElement); Gson gson = new Gson(); TestSessionRequest request = gson.fromJson(requestJsonStr, TestSessionRequest.class); TestSessionResponse response = new TestSessionResponse(); WSession wSession = sessionManager.getSession(request.getSessionId()); if (wSession != null) { response.setValid(true);//from w w w . j a va 2 s . co m } else { response.setValid(false); } response.setLifeSpan(sessionLifespan); String tsrString = new GsonBuilder().create().toJson(response); ObservationSet observationSet = new ObservationSet(); ObservationType observationType = new ObservationType(); BlobType blobType = new BlobType(); blobType.getContent().add(tsrString); observationType.setObservationBlob(blobType); observationSet.getObservation().add(observationType); ResponseMessageType responseMessageType = MessageFactory.createBuildResponse(messageHeaderType, observationSet); String rmtString = MessageFactory.convertToXMLString(responseMessageType); OMElement out = null; try { out = MessageFactory.createResponseOMElementFromString(rmtString); } catch (XMLStreamException e) { e.printStackTrace(); } log.debug(rmtString); return out; }
From source file:com.biomeris.i2b2.export.ws.ExportService.java
public OMElement openNewSession(OMElement inputElement) throws I2B2Exception, JsonSyntaxException { Assert.notNull(inputElement, "Export Cell: Incoming request is null"); MessageHeaderType messageHeaderType = MessageManager.extractReqMess(inputElement).getMessageHeader(); String requestJsonStr = MessageManager.extractObsBlob(inputElement); Gson gson = new Gson(); OpenNewSessionRequest request = gson.fromJson(requestJsonStr, OpenNewSessionRequest.class); boolean validUser = false; if (authStrategy > 0) { try {//ww w. ja va 2s . c o m validUser = validateUser(request.getNetwork()); } catch (JAXBException | IOException | TransformerException e1) { // do nothing } } else { validUser = true; } OpenNewSessionResponse response = new OpenNewSessionResponse(); if (!validUser) { String error = "You are not allowed to use export functions"; response.setError(error); } else { WSession wSession = sessionManager.createNewSession(); wSession.setNetwork(request.getNetwork()); Session session = new Session(); session.setId(wSession.getId()); response.setSession(session); } String onsrString = new GsonBuilder().create().toJson(response); ObservationSet observationSet = new ObservationSet(); ObservationType observationType = new ObservationType(); BlobType blobType = new BlobType(); blobType.getContent().add(onsrString); observationType.setObservationBlob(blobType); observationSet.getObservation().add(observationType); ResponseMessageType responseMessageType = MessageFactory.createBuildResponse(messageHeaderType, observationSet); String rmtString = MessageFactory.convertToXMLString(responseMessageType); OMElement out = null; try { out = MessageFactory.createResponseOMElementFromString(rmtString); } catch (XMLStreamException e) { e.printStackTrace(); } log.debug(rmtString); return out; }
From source file:net.cloudkit.toolkit.DownloadTest.java
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @Transactional/*from w ww.j a v a 2 s . com*/ @Test public void test() throws Exception { Map<String, Object> cdl = new HashMap<>(); Map<String, String> cdlBillHead = null; Map<String, String> cdlBillList = null; List<Map<String, String>> cdlBillLists = new ArrayList<>(); Map<String, String> cdlBillDoc = null; List<Map<String, String>> cdlBillDocs = new ArrayList<>(); // MESSAGE_CONFIG // InputStream InputStream in = null; try { // StAX? XMLInputFactory xif = XMLInputFactory.newInstance(); // ? XMLStreamReader reader = xif .createXMLStreamReader(new FileInputStream(new File("D:\\temp\\bill\\CDL100000006531646.xml"))); // while (reader.hasNext()) { // ? int event = reader.next(); // // if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) { if (event == XMLStreamReader.START_ELEMENT) { // CdlBill/CdlBillHead if ("CdlBillHead".equals(reader.getLocalName())) { cdlBillHead = new LinkedHashMap<>(); } { // BillSeq if ("BillSeq".equals(reader.getLocalName())) { cdlBillHead.put("BillSeq", reader.getElementText()); } // ListNo if ("ListNo".equals(reader.getLocalName())) { cdlBillHead.put("ListNo", reader.getElementText()); } // IEFlag if ("IEFlag".equals(reader.getLocalName())) { cdlBillHead.put("IEFlag", reader.getElementText()); } // IEPort if ("IEPort".equals(reader.getLocalName())) { cdlBillHead.put("IEPort", reader.getElementText()); } // IEDate if ("IEDate".equals(reader.getLocalName())) { cdlBillHead.put("IEDate", reader.getElementText()); } // RecordsNo if ("RecordsNo".equals(reader.getLocalName())) { cdlBillHead.put("RecordsNo", reader.getElementText()); } // TradeCode if ("TradeCode".equals(reader.getLocalName())) { cdlBillHead.put("TradeCode", reader.getElementText()); } // TradeName if ("TradeName".equals(reader.getLocalName())) { cdlBillHead.put("TradeName", reader.getElementText()); } // OwnerCode if ("OwnerCode".equals(reader.getLocalName())) { cdlBillHead.put("OwnerCode", reader.getElementText()); } // OwnerName if ("OwnerName".equals(reader.getLocalName())) { cdlBillHead.put("OwnerName", reader.getElementText()); } // TrafMode if ("TrafMode".equals(reader.getLocalName())) { cdlBillHead.put("TrafMode", reader.getElementText()); } // ShipName if ("ShipName".equals(reader.getLocalName())) { cdlBillHead.put("ShipName", reader.getElementText()); } // VoyageNo if ("VoyageNo".equals(reader.getLocalName())) { cdlBillHead.put("VoyageNo", reader.getElementText()); } // BillNo if ("BillNo".equals(reader.getLocalName())) { cdlBillHead.put("BillNo", reader.getElementText()); } // TradeMode if ("TradeMode".equals(reader.getLocalName())) { cdlBillHead.put("TradeMode", reader.getElementText()); } // TradeCountry if ("TradeCountry".equals(reader.getLocalName())) { cdlBillHead.put("TradeCountry", reader.getElementText()); } // DestinationPort if ("DestinationPort".equals(reader.getLocalName())) { cdlBillHead.put("DestinationPort", reader.getElementText()); } // DistrictCode if ("DistrictCode".equals(reader.getLocalName())) { cdlBillHead.put("DistrictCode", reader.getElementText()); } // PackNum if ("PackNum".equals(reader.getLocalName())) { cdlBillHead.put("PackNum", reader.getElementText()); } // WrapType if ("WrapType".equals(reader.getLocalName())) { cdlBillHead.put("WrapType", reader.getElementText()); } // GrossWt if ("GrossWt".equals(reader.getLocalName())) { cdlBillHead.put("GrossWt", reader.getElementText()); } // NetWt if ("NetWt".equals(reader.getLocalName())) { cdlBillHead.put("NetWt", reader.getElementText()); } // ListType if ("ListType".equals(reader.getLocalName())) { cdlBillHead.put("ListType", reader.getElementText()); } // ListStat if ("ListStat".equals(reader.getLocalName())) { cdlBillHead.put("ListStat", reader.getElementText()); } // DocuCodeCom if ("DocuCodeCom".equals(reader.getLocalName())) { cdlBillHead.put("DocuCodeCom", reader.getElementText()); } // AgentCode if ("AgentCode".equals(reader.getLocalName())) { cdlBillHead.put("AgentCode", reader.getElementText()); } // AgentName if ("AgentName".equals(reader.getLocalName())) { cdlBillHead.put("AgentName", reader.getElementText()); } // DeclCustom if ("DeclCustom".equals(reader.getLocalName())) { cdlBillHead.put("DeclCustom", reader.getElementText()); } // DeclDate if ("DeclDate".equals(reader.getLocalName())) { cdlBillHead.put("DeclDate", reader.getElementText()); } // GType if ("GType".equals(reader.getLocalName())) { cdlBillHead.put("GType", reader.getElementText()); } } // CdlBill/CdlBillLists/CdlBillList if ("CdlBillList".equals(reader.getLocalName())) { cdlBillList = new LinkedHashMap<>(); } { // GNo if ("GNo".equals(reader.getLocalName())) { cdlBillList.put("GNo", reader.getElementText()); } // ItemNo if ("ItemNo".equals(reader.getLocalName())) { cdlBillList.put("ItemNo", reader.getElementText()); } // CodeTs if ("CodeTs".equals(reader.getLocalName())) { cdlBillList.put("CodeTs", reader.getElementText()); } // GName if ("GName".equals(reader.getLocalName())) { cdlBillList.put("GName", reader.getElementText()); } // GModel if ("GModel".equals(reader.getLocalName())) { cdlBillList.put("GModel", reader.getElementText()); } // GQty if ("GQty".equals(reader.getLocalName())) { cdlBillList.put("GQty", reader.getElementText()); } // GUnit if ("GUnit".equals(reader.getLocalName())) { cdlBillList.put("GUnit", reader.getElementText()); } // DeclPrice if ("DeclPrice".equals(reader.getLocalName())) { cdlBillList.put("DeclPrice", reader.getElementText()); } // DeclTotal if ("DeclTotal".equals(reader.getLocalName())) { cdlBillList.put("DeclTotal", reader.getElementText()); } // TradeCurr if ("TradeCurr".equals(reader.getLocalName())) { cdlBillList.put("TradeCurr", reader.getElementText()); } // OriginalalCountry if ("OriginalalCountry".equals(reader.getLocalName())) { cdlBillList.put("OriginalalCountry", reader.getElementText()); } // DutyMode if ("DutyMode".equals(reader.getLocalName())) { cdlBillList.put("DutyMode", reader.getElementText()); } // Unit1 if ("Unit1".equals(reader.getLocalName())) { cdlBillList.put("Unit1", reader.getElementText()); } // Unit2 if ("Unit2".equals(reader.getLocalName())) { cdlBillList.put("Unit2", reader.getElementText()); } } // CdlBill/CdlBillDocs/CdlBillDoc if ("CdlBillDoc".equals(reader.getLocalName())) { cdlBillDoc = new LinkedHashMap<>(); } { // DocCode if ("DocCode".equals(reader.getLocalName())) { cdlBillDoc.put("DocCode", reader.getElementText()); } // CertNo if ("CertNo".equals(reader.getLocalName())) { cdlBillDoc.put("CertNo", reader.getElementText()); } } } if (event == XMLStreamReader.END_ELEMENT) { // CdlBill/CdlBillHead if ("CdlBillHead".equals(reader.getLocalName())) { } // CdlBill/CdlBillLists/CdlBillList if ("CdlBillList".equals(reader.getLocalName())) { cdlBillLists.add(cdlBillList); } // CdlBill/CdlBillDocs/CdlBillDoc if ("CdlBillDoc".equals(reader.getLocalName())) { cdlBillDocs.add(cdlBillDoc); } } } } catch (XMLStreamException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } cdl.put("CdlBillHead", cdlBillHead); cdl.put("CdlBillLists", cdlBillLists); cdl.put("CdlBillDocs", cdlBillDocs); System.out.println(cdlBillLists.size() + " " + cdlBillDocs.size()); persistentRepositoryService.save(cdl); }
From source file:cysbml.SBMLGraphReader.java
/** Reading the SBML and creating cytoscape network. */ @Override/*from www.ja v a2 s . co m*/ public void read() throws IOException { InputStream instream; if ((fileURL == null) && (fileName != null)) instream = new FileInputStream(fileName); else if ((fileURL != null) && (fileName == null)) instream = fileURL.openStream(); else if ((fileURL == null) && (fileName == null) && (sbmlStream != null)) instream = sbmlStream; else throw new IOException("No file to open!"); // Read SBML document if valid SBML SBMLReader reader = new SBMLReader(); try { document = reader.readSBMLFromStream(instream); createCytoscapeGraphFromSBMLDocument(); } catch (XMLStreamException e) { e.printStackTrace(); document = null; } }
From source file:com.biomeris.i2b2.export.ws.ExportService.java
public OMElement export(OMElement inputElement) throws I2B2Exception, JsonSyntaxException, ExportCellException { Assert.notNull(inputElement, "Export Cell: Incoming request is null"); OMElement returnElement = null;//from w ww.j av a2 s. com MessageHeaderType messageHeaderType = MessageManager.extractReqMess(inputElement).getMessageHeader(); String requestJsonStr = MessageManager.extractObsBlob(inputElement); Gson gson = new Gson(); ExportRequest request = gson.fromJson(requestJsonStr, ExportRequest.class); String sessionId = request.getSessionId(); WSession wSession = sessionManager.getSession(sessionId); if (wSession == null) { throw new ExportCellException("Session does not exist"); } if (request.getNewPassword() != null) { wSession.getNetwork().setPassword(request.getNewPassword()); } else { if (authStrategy > 1) { throw new ExportCellException("Password not provided."); } } boolean validUser = false; if (authStrategy > 1) { try { validUser = validateUser(wSession.getNetwork()); } catch (JAXBException | IOException | TransformerException e1) { // do nothing } } else { validUser = true; } ExportResponse response = new ExportResponse(); if (validUser) { response.setSessionId(sessionId); WExport wExport = null; wExport = wSession.addNewExport(request.getName()); wExport.setExportParams(request.getExportParams()); wExport.setConcepts(request.getConcepts()); wExport.setPatSetId(request.getPatientSetId()); wExport.setPatSetName(request.getPatientSetName()); response.setExportId(wExport.getId()); ExportRunnable erun = new ExportRunnable(wSession, wExport); Thread t = new Thread(erun); t.start(); } else { String error = "You're not allowed to use export functions"; response.setError(error); } String jsonRespStr = new GsonBuilder().create().toJson(response); ObservationSet observationSet = new ObservationSet(); ObservationType observationType = new ObservationType(); BlobType blobType = new BlobType(); blobType.getContent().add(jsonRespStr); observationType.setObservationBlob(blobType); observationSet.getObservation().add(observationType); ResponseMessageType responseMessageType = MessageFactory.createBuildResponse(messageHeaderType, observationSet); String rmtStr = MessageFactory.convertToXMLString(responseMessageType); try { returnElement = MessageFactory.createResponseOMElementFromString(rmtStr); } catch (XMLStreamException e) { e.printStackTrace(); } log.debug(rmtStr); return returnElement; }