Example usage for javax.xml.bind JAXB unmarshal

List of usage examples for javax.xml.bind JAXB unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind JAXB unmarshal.

Prototype

public static <T> T unmarshal(Source xml, Class<T> type) 

Source Link

Document

Reads in a Java object tree from the given XML input.

Usage

From source file:org.apache.juddi.adminconsole.hub.UddiAdminHub.java

private String save_ClientSubscriptionInfo(HttpServletRequest parameters) {
    StringBuilder ret = new StringBuilder();
    SaveClientSubscriptionInfo sb = new SaveClientSubscriptionInfo();

    if (parameters.getParameter("ClientSubscriptionInfoDetailXML") == null)
        return "No input!";
    ClientSubscriptionInfoDetail d = null;
    try {/*from w ww .  j a  va2s  .  c o m*/
        StringReader sr = new StringReader(parameters.getParameter("ClientSubscriptionInfoDetailXML").trim());
        sb = (JAXB.unmarshal(sr, SaveClientSubscriptionInfo.class));
        sb.setAuthInfo(GetToken());
        d = juddi.saveClientSubscriptionInfo(sb);
    } catch (Exception ex) {
        if (ex instanceof DispositionReportFaultMessage) {
            DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex;
            if (f.getFaultInfo().countainsErrorCode(DispositionReport.E_AUTH_TOKEN_EXPIRED)) {
                token = null;
                sb.setAuthInfo(GetToken());
                try {
                    d = juddi.saveClientSubscriptionInfo(sb);
                } catch (Exception ex1) {
                    return HandleException(ex);
                }
            }
        } else {
            return HandleException(ex);
        }
    }
    if (d != null) {
        ret.append("<pre>");
        StringWriter sw = new StringWriter();
        JAXB.marshal(d, sw);
        sw.append(PrettyPrintXML(sw.toString()));
        ret.append("</pre>");
    } else {
        ret.append("No data returned");
    }
    return ret.toString();
}

From source file:org.apache.juddi.config.InstallTest.java

/**
 * Test of applyReplicationTokenChanges method, of class Install.
 *///  www .j av a2s.co  m
@Test
public void testApplyReplicationTokenChanges() throws Exception {
    System.out.println("applyReplicationTokenChanges");
    InputStream fis = getClass().getClassLoader()
            .getResourceAsStream("juddi_install_data/root_replicationConfiguration.xml");

    ReplicationConfiguration replicationCfg = JAXB.unmarshal(fis, ReplicationConfiguration.class);
    Properties props = new Properties();
    props.put(Property.JUDDI_NODE_ID, "uddi:a_custom_node");
    props.put(Property.JUDDI_BASE_URL, "http://juddi.apache.org");
    props.put(Property.JUDDI_BASE_URL_SECURE, "https://juddi.apache.org");

    Configuration config = new MapConfiguration(props);
    String thisnode = "uddi:a_custom_node";

    ReplicationConfiguration result = Install.applyReplicationTokenChanges(replicationCfg, config, thisnode);
    StringWriter sw = new StringWriter();
    JAXB.marshal(result, sw);
    Assert.assertFalse(sw.toString().contains("${juddi.nodeId}"));
    Assert.assertFalse(sw.toString().contains("${juddi.server.baseurlsecure}"));
    Assert.assertFalse(sw.toString().contains("${juddi.server.baseurl}"));

}

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/* w  w 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 ww . j  av  a  2 s .co 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.tck.TckBusiness.java

private <T> T signJAXBObject(T jaxbObj) {
    DOMResult domResult = new DOMResult();
    JAXB.marshal(jaxbObj, domResult);
    Document doc = ((Document) domResult.getNode());
    Element docElement = doc.getDocumentElement();

    try {//  ww w . j  a va  2  s .c  o m
        KeyStore ks = KeyStore.getInstance(SIGNATURE_KEYSTORE_TYPE);
        URL url = Thread.currentThread().getContextClassLoader().getResource(SIGNATURE_KEYSTORE);
        ks.load(url.openStream(), SIGNATURE_KEYSTORE_PASSWORD.toCharArray());
        KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(SIGNATURE_KEYSTORE_ALIAS,
                new KeyStore.PasswordProtection(SIGNATURE_KEYSTORE_PASSWORD.toCharArray()));
        PrivateKey privateKey = keyEntry.getPrivateKey();
        Certificate origCert = keyEntry.getCertificate();
        PublicKey validatingKey = origCert.getPublicKey();
        TckSigningUtil.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.webconsole.hub.UddiHub.java

/**
 *
 * @param tokenxml/* w  ww .j  ava 2 s  .  co m*/
 * @return The discard_transferToken API is a client API used to discard
 * a transferToken obtained through the get_transferToken API at the
 * same node. This API accepts either a transferToken or a keyBag as
 * parameters to remove the permission to transfer data associated with
 * a particular transferToken. If a keyBag is provided, all tokens
 * corresponding to the keys in the keyBag will be discarded and will no
 * longer be valid for custody or ownership transfer after the
 * discard_transferToken is processed, irrespective of whether the keys
 * match any known business or tmodelKey values. In the event that the
 * keyBag represents a subset of the keyBag for one or more
 * transferToken elements, the transferToken is discarded and will no
 * longer be valid for transferring any entity. If the token passed in
 * the transferToken argument does not match an existing token known to
 * the system, no action is taken and success is reported. Keys in the
 * keyBag argument that do not have a corresponding token are ignored.
 */
public String DiscardToken(String tokenxml) {
    DiscardTransferToken r = new DiscardTransferToken();
    r.setAuthInfo(GetToken());
    r.setTransferToken(JAXB.unmarshal(new StringReader(tokenxml), TransferToken.class));

    try {
        try {
            custody.discardTransferToken(r);
        } catch (Exception ex) {
            if (isExceptionExpiration(ex)) {
                token = null;
                r.setAuthInfo(GetToken());
                custody.discardTransferToken(r);

            } else {
                throw ex;
            }
        }
    } catch (Exception ex) {
        return HandleException(ex);
    }
    return null;//"Success";

}

From source file:org.apache.juddi.webconsole.hub.UddiHub.java

/**
 * Accepts a transfer token and transfers the entities.
 *
 * @param tokenXML//w  ww.  j  ava  2s .co m
 * @param keyBagXML
 * @return status msg
 */
public String AcceptCustodyTranferToken(String tokenXML, String keyBagXML) {
    try {
        TransferEntities te = new TransferEntities();
        te.setAuthInfo(GetToken());
        StringReader sr = new StringReader(tokenXML.trim());
        te.setTransferToken(JAXB.unmarshal(sr, TransferToken.class));
        sr = new StringReader(keyBagXML.trim());
        te.setKeyBag(JAXB.unmarshal(sr, org.uddi.custody_v3.KeyBag.class));

        try {
            custody.transferEntities(te);
        } catch (Exception ex) {
            if (isExceptionExpiration(ex)) {
                token = null;
                te.setAuthInfo(GetToken());
                custody.transferEntities(te);

            } else {
                throw ex;
            }
        }
    } catch (Exception ex) {
        return HandleException(ex);
    }
    return null;//"Success";

}

From source file:org.csstudio.opibuilder.validation.Application.java

/**
 * Checks the file and all its children for .project files and linked resources defined in those files.
 *
 * @param links the map to receive the links and should also be returned
 * @param file the base file to start the check with
 * @return the map containing all linked resources; key is the .project file, value is the array of links defined in
 *         that .project file//from  w  w  w . ja  v a 2 s . c  om
 */
private static Map<File, Link[]> gatherLinkedResources(Map<File, Link[]> links, File file) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (File f : files) {
                if (f.isDirectory()) {
                    gatherLinkedResources(links, f);
                } else if (PROJECT_FILE.equalsIgnoreCase(f.getName())) {
                    ArrayList<Link> linkList = new ArrayList<>();
                    ProjectDescription pd = JAXB.unmarshal(f, ProjectDescription.class);
                    Variable[] variables = pd.getVariables().toArray(new Variable[pd.getVariables().size()]);
                    for (Link l : pd.getLinks()) {
                        String locURI = l.getLocationURI();
                        String loc = l.getLocation();
                        for (Variable v : variables) {
                            if (locURI != null && locURI.contains(v.getName())) {
                                locURI = locURI.replace(v.getName(), v.getValue());
                            }
                            if (loc != null && loc.contains(v.getName())) {
                                loc = loc.replace(v.getName(), v.getValue());
                            }
                        }
                        l.setLocationURI(locURI);
                        l.setLocation(loc);
                        linkList.add(l);
                    }
                    if (!linkList.isEmpty()) {
                        links.put(f, linkList.toArray(new Link[linkList.size()]));
                    }
                }
            }
        }
    }
    return links;
}

From source file:org.ebayopensource.turmeric.services.monitoringservice.junit.AbstractSOAQueryMetricsTest.java

/**
 * Test get metrics metadata./*from   w w w.ja v  a2 s. c  o m*/
 * 
 * @param requestXmlPath
 *            the request xml path
 * @param respXmlPath
 *            the resp xml path
 * @throws Exception
 *             the exception
 */
public void testGetMetricsMetadata(String requestXmlPath, String respXmlPath) throws Exception {
    init();
    ClassLoader cl = AbstractSOAQueryMetricsTest.class.getClassLoader();
    InputStreamReader requestis = new InputStreamReader(cl.getResourceAsStream(requestXmlPath));
    InputStreamReader responseis = new InputStreamReader(cl.getResourceAsStream(respXmlPath));

    GetMetricsMetadataRequest req = JAXB.unmarshal(requestis, GetMetricsMetadataRequest.class);

    GetMetricsMetadataResponse resp = consumer.getMetricsMetadata(req);

    ByteArrayOutputStream xmlResp = new ByteArrayOutputStream();
    JAXB.marshal(resp, xmlResp);
    StringReader str = new StringReader(xmlResp.toString());
    System.out.println(xmlResp.toString());
    assertXMLEqual(responseis, str);
}

From source file:org.ebayopensource.turmeric.services.monitoringservice.junit.AbstractSOAQueryMetricsTest.java

/**
 * Test get metric value.//from  w ww  . j a  v  a  2s.  c o m
 * 
 * @param requestXmlPath
 *            the request xml path
 * @param respXmlPath
 *            the resp xml path
 * @throws Exception
 *             the exception
 */
public void testGetMetricValue(String requestXmlPath, String respXmlPath) throws Exception {
    ClassLoader cl = AbstractSOAQueryMetricsTest.class.getClassLoader();
    InputStreamReader requestis = new InputStreamReader(cl.getResourceAsStream(requestXmlPath));
    InputStreamReader responseis = new InputStreamReader(cl.getResourceAsStream(respXmlPath));

    GetMetricValueRequest req = JAXB.unmarshal(requestis, GetMetricValueRequest.class);

    GetMetricValueResponse resp = consumer.getMetricValue(req);
    ByteArrayOutputStream xmlResp = new ByteArrayOutputStream();
    JAXB.marshal(resp, xmlResp);
    StringReader str = new StringReader(xmlResp.toString());
    System.out.println(xmlResp.toString());
    assertXMLEqual(responseis, str);
}