List of usage examples for javax.xml.bind JAXB marshal
public static void marshal(Object jaxbObject, Result xml)
From source file:org.apache.juddi.samples.JuddiAdminService.java
void dumpFailedReplicationRecords(String authtoken) throws Exception { GetFailedReplicationChangeRecordsMessageRequest req = new GetFailedReplicationChangeRecordsMessageRequest(); req.setAuthInfo(authtoken);//ww w . j a v a 2s . c o m req.setMaxRecords(20); req.setOffset(0); GetFailedReplicationChangeRecordsMessageResponse failedReplicationChangeRecords = juddi .getFailedReplicationChangeRecords(req); while (failedReplicationChangeRecords != null && failedReplicationChangeRecords.getChangeRecords() != null && !failedReplicationChangeRecords.getChangeRecords().getChangeRecord().isEmpty()) { for (int i = 0; i < failedReplicationChangeRecords.getChangeRecords().getChangeRecord().size(); i++) { JAXB.marshal(failedReplicationChangeRecords.getChangeRecords().getChangeRecord().get(i), System.out); } req.setOffset( req.getOffset() + failedReplicationChangeRecords.getChangeRecords().getChangeRecord().size()); failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req); } }
From source file:org.apache.juddi.samples.JuddiAdminService.java
void autoMagicDirectedSSL() throws Exception { //1 > 2 >3 >1 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList(); Transport transport = clerkManager.getTransport("default"); String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")) .getAuthInfo();/*from w ww .j a v a 2s.c o m*/ JUDDIApiPortType juddiApiService = transport.getJUDDIApiService(); System.out.println("fetching..."); ReplicationConfiguration replicationNodes = null; try { replicationNodes = juddiApiService.getReplicationNodes(authtoken); } catch (Exception ex) { System.out.println("Error getting replication config"); ex.printStackTrace(); replicationNodes = new ReplicationConfiguration(); } //if (replicationNodes.getCommunicationGraph() == null) { replicationNodes.setCommunicationGraph(new CommunicationGraph()); //} Operator op = new Operator(); op.setOperatorNodeID("uddi:juddi.apache.org:node1"); op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("bob", "en")); op.getContact().get(0).setUseType("admin"); replicationNodes.getOperator().clear(); replicationNodes.getOperator().add(op); op = new Operator(); op.setOperatorNodeID("uddi:another.juddi.apache.org:node2"); op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2") .getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("mary", "en")); op.getContact().get(0).setUseType("admin"); replicationNodes.getOperator().add(op); op = new Operator(); op.setOperatorNodeID("uddi:yet.another.juddi.apache.org:node3"); op.setSoapReplicationURL(clerkManager.getClientConfig() .getUDDINode("uddi:yet.another.juddi.apache.org:node3").getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("mary", "en")); op.getContact().get(0).setUseType("admin"); replicationNodes.getOperator().add(op); replicationNodes.getCommunicationGraph().getNode().clear(); replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2"); replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1"); replicationNodes.getCommunicationGraph().getNode().add("uddi:yet.another.juddi.apache.org:node3"); replicationNodes.getCommunicationGraph().getEdge().clear(); Edge e = new CommunicationGraph.Edge(); e.setMessageSender("uddi:juddi.apache.org:node1"); e.setMessageReceiver("uddi:another.juddi.apache.org:node2"); replicationNodes.getCommunicationGraph().getEdge().add(e); e = new CommunicationGraph.Edge(); e.setMessageSender("uddi:another.juddi.apache.org:node2"); e.setMessageReceiver("uddi:yet.another.juddi.apache.org:node3"); replicationNodes.getCommunicationGraph().getEdge().add(e); e = new CommunicationGraph.Edge(); e.setMessageSender("uddi:yet.another.juddi.apache.org:node3"); e.setMessageReceiver("uddi:juddi.apache.org:node1"); replicationNodes.getCommunicationGraph().getEdge().add(e); replicationNodes.setSerialNumber(0L); replicationNodes.setTimeOfConfigurationUpdate(""); replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE); replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE); if (replicationNodes.getRegistryContact().getContact() == null) { replicationNodes.getRegistryContact().setContact(new Contact()); replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null)); } JAXB.marshal(replicationNodes, System.out); juddiApiService.setReplicationNodes(authtoken, replicationNodes); System.out.println("Saved to node1"); TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken)); transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2"); authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo(); juddiApiService = transport.getJUDDIApiService(); juddiApiService.setReplicationNodes(authtoken, replicationNodes); System.out.println("Saved to node2"); TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken)); transport = clerkManager.getTransport("uddi:yet.another.juddi.apache.org:node3"); authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo(); juddiApiService = transport.getJUDDIApiService(); juddiApiService.setReplicationNodes(authtoken, replicationNodes); System.out.println("Saved to node3"); TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken)); }
From source file:org.apache.juddi.samples.UddiReplication.java
void GetChangeRecords(Long record, String sourcenode) { try {/* w w w.jav a 2 s . c o m*/ HighWaterMarkVectorType highWaterMarkVectorType = new HighWaterMarkVectorType(); highWaterMarkVectorType.getHighWaterMark().add(new ChangeRecordIDType(DoPing(), record)); GetChangeRecords req = new GetChangeRecords(); req.setRequestingNode(sourcenode); req.setChangesAlreadySeen(highWaterMarkVectorType); req.setResponseLimitCount(BigInteger.valueOf(100)); ChangeRecords res = uddiReplicationPort.getChangeRecords(req); List<ChangeRecord> changeRecords = res.getChangeRecord(); System.out.println("Success...." + changeRecords.size() + " records returned"); System.out.println("Node, USN, type"); for (int i = 0; i < changeRecords.size(); i++) { System.out.println(changeRecords.get(i).getChangeID().getNodeID() + ", " + changeRecords.get(i).getChangeID().getOriginatingUSN() + ": " + GetChangeType(changeRecords.get(i))); JAXB.marshal(changeRecords.get(i), System.out); } } catch (Exception ex) { Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.juddi.subscription.notify.USERFRIENDLYSMTPNotifier.java
static String GetChangeSummary(NotifySubscriptionListener body) { SubscriptionResultsList r = body.getSubscriptionResultsList(); StringWriter sw = new StringWriter(); if (r.getAssertionStatusReport() != null) { JAXB.marshal(r.getAssertionStatusReport(), sw); } else if (r.getBindingDetail() != null) { JAXB.marshal(r.getBindingDetail(), sw); } else if (r.getBusinessDetail() != null) { JAXB.marshal(r.getBusinessDetail(), sw); } else if (r.getBusinessList() != null) { JAXB.marshal(r.getBusinessList(), sw); } else if (r.getRelatedBusinessesList() != null) { JAXB.marshal(r.getRelatedBusinessesList(), sw); } else if (r.getServiceDetail() != null) { JAXB.marshal(r.getServiceDetail(), sw); } else if (r.getServiceList() != null) { JAXB.marshal(r.getServiceList(), sw); } else if (r.getTModelDetail() != null) { JAXB.marshal(r.getTModelDetail(), sw); } else if (r.getTModelList() != null) { JAXB.marshal(r.getTModelList(), sw); }//www . jav a 2 s . c o m return "<pre>" + StringEscapeUtils.escapeHtml(sw.toString()) + "</pre>"; }
From source file:org.apache.juddi.v2.tck.TckBusiness.java
public BusinessEntity saveBusiness(String authInfo, String businessXML, String businessKey, boolean serialize) { logger.info("attempting to save business " + businessKey + " from " + businessXML); try {/*from ww w. j av a 2 s. c om*/ SaveBusiness sb = new SaveBusiness(); sb.setGeneric("2.0"); sb.setAuthInfo(authInfo); BusinessEntity beIn = (BusinessEntity) EntityCreator.buildFromDoc(businessXML, "org.uddi.api_v2"); if (beIn == null) { throw new Exception("Unload to load source xml document from " + businessXML); } sb.getBusinessEntity().add(beIn); sb.setGeneric("2.0"); BusinessDetail saveBusiness = publication.saveBusiness(sb); logger.info("Business saved with key " + saveBusiness.getBusinessEntity().get(0).getBusinessKey()); if (serialize) { JAXB.marshal(saveBusiness, System.out); } // Now get the entity and check the values GetBusinessDetail gb = new GetBusinessDetail(); gb.setGeneric("2.0"); gb.getBusinessKey().add(businessKey); BusinessDetail bd = inquiry.getBusinessDetail(gb); List<BusinessEntity> beOutList = bd.getBusinessEntity(); BusinessEntity beOut = beOutList.get(0); if (serialize) { JAXB.marshal(beOut, new File("target/aftersave.xml")); } assertEquals(beIn.getBusinessKey(), beOut.getBusinessKey()); TckValidator.checkNames(beIn.getName(), beOut.getName()); TckValidator.checkDescriptions(beIn.getDescription(), beOut.getDescription()); TckValidator.checkDiscoveryUrls(beIn.getDiscoveryURLs(), beOut.getDiscoveryURLs()); TckValidator.checkContacts(beIn.getContacts(), beOut.getContacts()); TckValidator.checkCategories(beIn.getCategoryBag(), beOut.getCategoryBag()); return beOut; } catch (Throwable e) { logger.error(e.getMessage(), e); Assert.fail("No exception should be thrown"); } return null; }
From source file:org.apache.juddi.v2.tck.TckTModel.java
private TModel saveTModel(String authInfo, TModel tmIn, boolean force) { boolean exists = false; GetTModelDetail gt1 = new GetTModelDetail(); gt1.setGeneric("2.0"); gt1.getTModelKey().add(tmIn.getTModelKey()); try {//from w w w . ja v a 2 s . c om TModelDetail td1 = inquiry.getTModelDetail(gt1); if (td1 != null && !td1.getTModel().isEmpty()) { exists = true; } } catch (Exception ex) { } if (!exists || force) // Add the tModel { try { SaveTModel st = new SaveTModel(); st.setAuthInfo(authInfo); st.setGeneric("2.0"); st.getTModel().add(tmIn); publication.saveTModel(st); keyscreated.add(tmIn.getTModelKey()); // Now get the entity and check the values GetTModelDetail gt = new GetTModelDetail(); gt.setGeneric("2.0"); gt.getTModelKey().add(tmIn.getTModelKey()); TModelDetail td = inquiry.getTModelDetail(gt); List<org.uddi.api_v2.TModel> tmOutList = td.getTModel(); org.uddi.api_v2.TModel tmOut = tmOutList.get(0); assertEquals(tmIn.getTModelKey().toLowerCase(), tmOut.getTModelKey()); assertEquals(tmIn.getName().getLang(), tmOut.getName().getLang()); assertEquals(tmIn.getName().getValue(), tmOut.getName().getValue()); TckValidator.checkDescriptions(tmIn.getDescription(), tmOut.getDescription()); TckValidator.checkCategories(tmIn.getCategoryBag(), tmOut.getCategoryBag()); TckValidator.checkOverviewDocs(tmIn.getOverviewDoc(), tmOut.getOverviewDoc()); logger.info("The TModel " + tmIn.getTModelKey() + " saved"); if (TckCommon.isDebug()) { JAXB.marshal(tmOut, System.out); } return tmOut; } catch (Exception e) { logger.error(e.getMessage(), e); Assert.fail("No exception should be thrown"); } } else { logger.info("The TModel " + tmIn.getTModelKey() + " exists already, skipping"); } return tmIn; }
From source file:org.apache.juddi.v3.client.cli.JuddiAdminService.java
/** * gets replication high water mark values * @param transport//from ww w. j ava 2s .c om * @param authtoken * @throws Exception */ void printStatus(Transport transport, String authtoken) throws Exception { JUDDIApiPortType juddiApiService = transport.getJUDDIApiService(); System.out.println("fetching..."); ReplicationConfiguration replicationNodes = null; try { replicationNodes = juddiApiService.getReplicationNodes(authtoken); } catch (Exception ex) { System.out.println("Error getting replication config"); ex.printStackTrace(); replicationNodes = new ReplicationConfiguration(); } UDDIReplicationPortType uddiReplicationPort = new UDDIService().getUDDIReplicationPort(); for (Operator o : replicationNodes.getOperator()) { System.out.println("*******************\n\rstats for node " + o.getOperatorNodeID()); ((BindingProvider) uddiReplicationPort).getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, o.getSoapReplicationURL()); List<ChangeRecordIDType> highWaterMarks = uddiReplicationPort.getHighWaterMarks(); for (ChangeRecordIDType cr : highWaterMarks) { JAXB.marshal(cr, System.out); } } }
From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java
/** * Digital signs a UDDI entity, such as a business, service, tmodel or * binding template using the map to provide certificate key stores and * credentials<br><br> The UDDI entity MUST support XML Digital * Signatures (tModel, Business, Service, Binding Template) * * @param <T> Any UDDI entity that supports digital signatures * @param jaxbObj//ww w. j a v a 2 s. co m * @return an enveloped signed UDDI element, do not modify this object * after signing */ public <T> T signUddiEntity(T jaxbObj) { DOMResult domResult = new DOMResult(); JAXB.marshal(jaxbObj, domResult); Document doc = ((Document) domResult.getNode()); Element docElement = doc.getDocumentElement(); try { KeyStore ks = KeyStore.getInstance(map.getProperty(SIGNATURE_KEYSTORE_FILETYPE)); URL url = Thread.currentThread().getContextClassLoader() .getResource(map.getProperty(SIGNATURE_KEYSTORE_FILE)); if (url == null) { try { url = new File(map.getProperty(SIGNATURE_KEYSTORE_FILE)).toURI().toURL(); } catch (Exception x) { } } if (url == null) { try { url = this.getClass().getClassLoader().getResource(map.getProperty(SIGNATURE_KEYSTORE_FILE)); } catch (Exception x) { } } KeyStore.PrivateKeyEntry keyEntry = null; if (!map.getProperty(SIGNATURE_KEYSTORE_FILETYPE).equalsIgnoreCase("WINDOWS-MY")) { ks.load(url.openStream(), (map.getProperty(SIGNATURE_KEYSTORE_FILE_PASSWORD)).toCharArray()); if (map.getProperty(SIGNATURE_KEYSTORE_KEY_PASSWORD) == null) { keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(map.getProperty(SIGNATURE_KEYSTORE_KEY_ALIAS), new KeyStore.PasswordProtection( map.getProperty(SIGNATURE_KEYSTORE_FILE_PASSWORD).toCharArray())); } else { keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(map.getProperty(SIGNATURE_KEYSTORE_KEY_ALIAS), new KeyStore.PasswordProtection( map.getProperty(SIGNATURE_KEYSTORE_KEY_PASSWORD).toCharArray())); } } else { //Windows only ks.load(null, null); keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(map.getProperty(SIGNATURE_KEYSTORE_KEY_ALIAS), null); } PrivateKey privateKey = keyEntry.getPrivateKey(); Certificate origCert = keyEntry.getCertificate(); //PublicKey validatingKey = origCert.getPublicKey(); this.signDOM(docElement, privateKey, origCert); DOMSource domSource = new DOMSource(doc); T result = (T) JAXB.unmarshal(domSource, jaxbObj.getClass()); return result; } catch (Exception e) { throw new RuntimeException("Signature failure due to: " + e.getMessage(), e); } }
From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java
/** * Digitally signs a UDDI entity, such as a business, service, tmodel or * binding template, provided you've already done the legwork to provide * the signing keys <br><br> The UDDI entity MUST support XML Digital * Signatures (tModel, Business, Service, Binding Template) * * @param <T>/* w w w . j ava 2 s .c o m*/ * @param jaxbObj * @param publicKey * @param privateKey * @return a signed entity */ public <T> T signUddiEntity(T jaxbObj, Certificate publicKey, PrivateKey privateKey) { DOMResult domResult = new DOMResult(); JAXB.marshal(jaxbObj, domResult); Document doc = ((Document) domResult.getNode()); Element docElement = doc.getDocumentElement(); try { //PublicKey validatingKey = origCert.getPublicKey(); this.signDOM(docElement, privateKey, publicKey); DOMSource domSource = new DOMSource(doc); T result = (T) JAXB.unmarshal(domSource, jaxbObj.getClass()); return result; } catch (Exception e) { throw new RuntimeException("Signature failure due to: " + e.getMessage(), e); } }
From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java
/** * Serializes a JAXB object and prints to stdout * * @param obj//from w w w . ja v a2s . com */ public static void JAXB_ToStdOut(Object obj) { StringWriter sw = new StringWriter(); JAXB.marshal(obj, sw); System.out.println(sw.toString()); }