List of usage examples for javax.xml.bind JAXB unmarshal
public static <T> T unmarshal(Source xml, Class<T> type)
From source file:cz.cas.lib.proarc.common.fedora.RemoteStorageTest.java
@Test(expected = DigitalObjectConcurrentModificationException.class) public void testXmlWriteConcurrent() throws Exception { String dsId = "testId"; LocalObject local = new LocalStorage().create(); local.setLabel(test.getMethodName()); XmlStreamEditor leditor = local.getEditor(FoxmlUtils.inlineProfile(dsId, "testns", "label")); EditorResult editorResult = leditor.createResult(); TestXml content = new TestXml("test content"); JAXB.marshal(content, editorResult); leditor.write(editorResult, 0, null); RemoteStorage fedora = new RemoteStorage(client); fedora.ingest(local, "junit"); RemoteObject remote = fedora.find(local.getPid()); RemoteXmlStreamEditor editor = new RemoteXmlStreamEditor(remote, dsId); Source src = editor.read();// w w w .j a v a 2s . com assertNotNull(src); TestXml resultContent = JAXB.unmarshal(src, TestXml.class); // concurrent write RemoteObject concurrentRemote = fedora.find(local.getPid()); RemoteXmlStreamEditor concurrentEditor = new RemoteXmlStreamEditor(concurrentRemote, dsId); TestXml concurrentContent = JAXB.unmarshal(concurrentEditor.read(), TestXml.class); concurrentContent.data = "concurrent change"; EditorResult concurrentResult = concurrentEditor.createResult(); JAXB.marshal(concurrentContent, concurrentResult); concurrentEditor.write(concurrentResult, editor.getLastModified(), null); concurrentRemote.flush(); // write out of date modification String expectedContent = "changed test content"; resultContent.data = expectedContent; editorResult = editor.createResult(); JAXB.marshal(resultContent, editorResult); long lastModified = editor.getLastModified(); editor.write(editorResult, lastModified, null); remote.flush(); }
From source file:eu.fthevenet.binjr.sources.jrds.adapters.JrdsDataAdapter.java
private Graphdesc getGraphDescriptor(String id) throws DataAdapterException { URI requestUri = craftRequestUri("/graphdesc", new BasicNameValuePair("id", id)); return doHttpGet(requestUri, response -> { StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 404) { // This is probably an older version of JRDS that doesn't provide the graphdesc service, // so we're falling back to recovering the datastore name from the csv file provided by // the download service. logger.warn("Cannot found graphdesc service; falling back to legacy mode."); try { return getGraphDescriptorLegacy(id); } catch (Exception e) { throw new IOException("", e); }/*from w w w . j a v a 2 s . co m*/ } HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } if (entity != null) { try { return JAXB.unmarshal(XmlUtils.toNonValidatingSAXSource(entity.getContent()), Graphdesc.class); } catch (Exception e) { throw new IOException("Failed to unmarshall graphdesc response", e); } } return null; }); }
From source file:com.biomeris.i2b2.export.ws.ExportService.java
private boolean validateUser(Network network) throws JAXBException, IOException, TransformerException { boolean output = false; String pmRequest = MessageBuilder.buildPMGetServiceRequest(network); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(network.getProxyAddress()); StringEntity entity1A = new StringEntity(pmRequest, Consts.UTF_8); entity1A.setContentType("text/xml"); entity1A.setChunked(true);/*from www. j a v a2 s.c o m*/ httpPost.setEntity(entity1A); CloseableHttpResponse response = null; try { response = httpclient.execute(httpPost); log.debug("Proxy: " + network.getProxyAddress()); } catch (HttpHostConnectException hhce) { try { if (network.getStaticProxyAddress() != null) { httpPost = new HttpPost(network.getStaticProxyAddress()); httpPost.setEntity(entity1A); response = httpclient.execute(httpPost); log.debug("Proxy: " + network.getStaticProxyAddress()); } } catch (HttpHostConnectException e) { throw e; } } try { HttpEntity entity1R = response.getEntity(); String responseString = EntityUtils.toString(entity1R); ResponseMessageType rmt = JAXB.unmarshal(new StringReader(responseString), ResponseMessageType.class); ResponseHeaderType responseHeader = rmt.getResponseHeader(); ResultStatusType responseStatus = responseHeader.getResultStatus(); if (responseStatus.getStatus().getType().equals("ERROR")) { return false; } BodyType body = rmt.getMessageBody(); ElementNSImpl bodyEl = (ElementNSImpl) body.getAny().get(0); String bodyStr = elementToString(bodyEl); ConfigureType configureType = JAXB.unmarshal(new StringReader(bodyStr), ConfigureType.class); UserType userType = configureType.getUser(); if (userType.isIsAdmin()) { output = true; } else { List<ProjectType> userProjects = userType.getProject(); for (ProjectType pt : userProjects) { if (pt.getId().equals(network.getProject())) { if (userAccessLevel(pt.getRole()) >= authLevel) { output = true; } } } } EntityUtils.consume(entity1R); } finally { response.close(); } return output; }
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
/** * parses a wadl from stream/*from w ww . j av a2 s . c om*/ * @param stream * @return Application instance (WADL FILE) */ public static Application parseWadl(InputStream stream) { Application unmarshal = JAXB.unmarshal(stream, Application.class); return unmarshal; }
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
/** * parses a wadl from a URL or file//from w w w .j a v a2 s. c om * @param file * @return Application instance (WADL FILE) */ public static Application parseWadl(URL file) { Application unmarshal = JAXB.unmarshal(file, Application.class); return unmarshal; }
From source file:org.perfrepo.client.PerfRepoClient.java
/** * Get metric by id./*from ww w .ja v a 2 s. co m*/ * * @param id * @return The metric * @throws Exception */ public Metric getMetric(Long id) throws Exception { HttpGet get = createBasicGet("metric/%s", id); HttpResponse resp = httpClient.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { Metric metric = JAXB.unmarshal(resp.getEntity().getContent(), Metric.class); EntityUtils.consume(resp.getEntity()); return metric; } else if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { EntityUtils.consume(resp.getEntity()); return null; } else { logHttpError("Error while getting metric", get, resp); EntityUtils.consume(resp.getEntity()); return null; } }
From source file:ca.uhn.hl7v2.testpanel.controller.Prefs.java
private void initFromJavaPrefs() { myOpenTableFiles = new ArrayList<String>(); String savedValsSplit = ourPrefs.get(GET_OPEN_TABLE_FILES, ""); String[] savedVals = defaultString(savedValsSplit).split("\\n"); for (String string : savedVals) { if (StringUtils.isNotBlank(string)) { myOpenTableFiles.add(string); }//from ww w . j a va 2 s. co m } myOutboundConnectionList = ourPrefs.get(GET_OUTBOUND_CONNECTION_LIST, null); myOpenPathConformanceProfile = ourPrefs.get(GET_OPEN_PATH_CONFORMANCE_PROFILE, "."); myOpenPathMessages = ourPrefs.get(GET_OPEN_PATH_MESSAGES, "."); myInterfaceHohSecurityKeystoreDirectory = ourPrefs.get(GET_INTERFACE_HOH_SECURITY_KEYSTORE_DIRECTORY, null); myMostRecentlySelectedItemId = ourPrefs.get(GET_MOST_RECENTLY_SELECTED_ITEM_ID, ""); myOpenOrSaveCharset = ourPrefs.get(GET_OPENSAVE_CHARSET, Charset.defaultCharset().name()); myHl7V2SortInputFile = ourPrefs.get(GET_HL7V2_SORT_INPUT, ""); myHl7V2SortOverwriteMode = ourPrefs.get(GET_HL7V2_SORT_OVERWRITE_MODE, ""); myInboundConnectionList = ourPrefs.get(GET_INBOUND_CONNECTION_LIST, null); myHl7V2SortOutputFile = ourPrefs.get(GET_HL7V2_SORT_OUTPUT, ""); myHl7V2DiffStopOnFirstError = ourPrefs.getBoolean(GET_HL7V2_DIFF_STOP_ON_FIRST_ERROR, false); myExportProfileGroupDirectory = ourPrefs.get(GET_EXPORT_PROFILE_GROUP_DIRECTORY, ""); myHl7V2DiffShowWholeMessageOnError = ourPrefs.getBoolean(GET_HL7V2_DIFF_SHOW_WHOLE_MESSAGE_ON_ERROR, false); myHl7V2SortBy = ourPrefs.get(GET_HL7V2_SORT_BY, ""); myMostRecentConnectionCharset = ourPrefs.get(GET_MOST_RECENT_CONNECTION_CHARSET, CharsetUtils.DEFAULT_CONNECTION_CHARSET.displayName()); myHl7EditorSplit = (int) (ourPrefs.getDouble(GET_HL7_EDITOR_SPLIT, 0.4) * 100.0); myHl7V2DiffFile1 = ourPrefs.get(GET_HL7V2_DIFF_FILE1, ""); myHl7V2DiffFile2 = ourPrefs.get(GET_HL7V2_DIFF_FILE2, ""); mySavePathMessages = ourPrefs.get(GET_SAVE_PATH_MESSAGES, "."); String recentMessageXmlFiles = ourPrefs.get(GET_RECENT_MESSAGE_FILES, ""); ArrayList<String> recentMessageXmlFilesSplit = new ArrayList<String>( Arrays.asList(defaultString(recentMessageXmlFiles).split("\\n"))); myRecentMessageXmlFiles = new ArrayList<Hl7V2MessageCollection.XmlFormat>(); for (String string : recentMessageXmlFilesSplit) { try { myRecentMessageXmlFiles .add(JAXB.unmarshal(new StringReader(string), Hl7V2MessageCollection.XmlFormat.class)); } catch (Exception e) { ourLog.error("Failed to restore file \"" + string + "\": " + e.getMessage(), e); } } mySaveLineEndings = ourPrefs.get(GET_SAVE_LINE_ENDINGS, LineEndingsEnum.HL7.name()); mySaveStripComments = ourPrefs.getBoolean(GET_SAVE_STRIP_COMMENTS, false); myWindowMaximized = ourPrefs.getBoolean(GET_WINDOW_MAXIMIZED, false); myWindowPositionX = ourPrefs.getInt(GET_WINDOW_POSITIONX, -1); myWindowPositionY = ourPrefs.getInt(GET_WINDOW_POSITIONY, -1); myWindowPositionW = ourPrefs.getInt(GET_WINDOW_POSITIONW, 0); myWindowPositionH = ourPrefs.getInt(GET_WINDOW_POSITIONH, 0); myShowLogConsole = ourPrefs.getBoolean(GET_SHOW_LOG_CONSOLE, false); }
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
/** * Parses a web accessible WADL file//from ww w . j a v a2 s .c o m * @param weburl * @param username * @param password * @param ignoreSSLErrors if true, SSL errors are ignored * @return a non-null "Application" object, represeting a WADL's application root XML * Sample code:<br> * <pre> * Application app = WADL2UDDI.parseWadl(new URL("http://server/wsdl.wsdl"), "username", "password", * clerkManager.getClientConfig().isX_To_Wsdl_Ignore_SSL_Errors() ); * </pre> */ public static Application parseWadl(URL weburl, String username, String password, boolean ignoreSSLErrors) { DefaultHttpClient httpclient = null; Application unmarshal = null; try { String url = weburl.toString(); if (!url.toLowerCase().startsWith("http")) { return parseWadl(weburl); } boolean usessl = false; int port = 80; if (url.toLowerCase().startsWith("https://")) { port = 443; usessl = true; } if (weburl.getPort() > 0) { port = weburl.getPort(); } if (ignoreSSLErrors && usessl) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", port, new MockSSLSocketFactory())); ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry); httpclient = new DefaultHttpClient(cm); } else { httpclient = new DefaultHttpClient(); } if (username != null && username.length() > 0 && password != null && password.length() > 0) { httpclient.getCredentialsProvider().setCredentials(new AuthScope(weburl.getHost(), port), new UsernamePasswordCredentials(username, password)); } HttpGet httpGet = new HttpGet(url); try { HttpResponse response1 = httpclient.execute(httpGet); //System.out.println(response1.getStatusLine()); // HttpEntity entity1 = response1.getEntity(); // do something useful with the response body // and ensure it is fully consumed ResponseHandler<String> responseHandler = new BasicResponseHandler(); String handleResponse = responseHandler.handleResponse(response1); StringReader sr = new StringReader(handleResponse); unmarshal = JAXB.unmarshal(sr, Application.class); } finally { httpGet.releaseConnection(); } } catch (Exception e) { log.error(e.getMessage(), e); } finally { if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } } return unmarshal; }
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
public static Application parseWadl(File file) throws FileNotFoundException, IOException { Application unmarshal = JAXB.unmarshal(file, Application.class); return unmarshal; }
From source file:com.fujitsu.dc.test.jersey.box.ServiceSchmaTest.java
$metadata_$metadata() { TResponse res = Http.request("box/$metadata-$metadata-get.txt") .with("path", "\\$metadata/\\$metadata") .with("col", "setodata") .with("accept", "application/xml") .with("token", DcCoreConfig.getMasterToken()) .returns()//w ww . j av a2 s . co m .statusCode(HttpStatus.SC_OK) .debug(); // ??? String str = res.getBody(); Edmx edmx = JAXB.unmarshal(new StringReader(str), Edmx.class); Edmx checkBody = getRightEdmx(); assertTrue(checkBody.equals(edmx)); }