Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
JUDDI-987 no commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
spyhunter99 committed Nov 11, 2017
1 parent 4541dee commit 248b39c
Show file tree
Hide file tree
Showing 26 changed files with 721 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.xml.bind.JAXB;

import org.apache.juddi.v3.client.cryptor.DigSigUtil;
import org.apache.juddi.v3.client.cryptor.XmlUtils;
import org.uddi.api_v3.*;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public void fire(String fileIn, String fileOut, UddiType type) {
expectedType = TModel.class;
break;
}
Object be = JAXB.unmarshal(fis, expectedType);
Object be = XmlUtils.unmarshal(fis, expectedType);
fis.close();
fis = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2017 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.juddi.v3.client.cryptor;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.InputSource;

/**
*
* @since 3.3.5
* @author Alex O'Ree
*/
public class XmlUtils {

private static final Log log = LogFactory.getLog(XmlUtils.class);

public static Object unmarshal(Reader reader, Class...clazz) {

try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
spf.setNamespaceAware(true);

Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(reader));
JAXBContext jc = JAXBContext.newInstance(clazz);
Unmarshaller um = jc.createUnmarshaller();
return um.unmarshal(xmlSource);
} catch (Exception ex) {
log.warn("Failed to unmarshall object. Increase logging to debug for additional information. 1" + ex.getMessage());
log.debug(ex.getMessage(), ex);
}
return null;

}

public static Object unmarshal(InputStream reader, Class clazz) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
spf.setNamespaceAware(true);
Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(reader));
JAXBContext jc = JAXBContext.newInstance(clazz);
Unmarshaller um = jc.createUnmarshaller();
return um.unmarshal(xmlSource);
} catch (Exception ex) {
log.warn("Failed to unmarshall object. Increase logging to debug for additional information. 2" + ex.getMessage());
log.debug(ex.getMessage(), ex);
}
return null;

}

public static Object unmarshal(Reader reader, String packageName) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
spf.setNamespaceAware(true);
Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(reader));
JAXBContext jc = JAXBContext.newInstance(packageName);

Unmarshaller um = jc.createUnmarshaller();
return ((javax.xml.bind.JAXBElement)um.unmarshal(xmlSource)).getValue();
} catch (Exception ex) {
log.warn("Failed to unmarshall object. Increase logging to debug for additional information. 3" + ex.getMessage());
log.debug(ex.getMessage(), ex);
}
return null;

}

public static Object unmarshal(URL url, Class clazz) {
InputStream openStream = null;
Object obj = null;
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
spf.setNamespaceAware(true);
openStream = url.openStream();
Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(openStream));
JAXBContext jc = JAXBContext.newInstance(clazz);
Unmarshaller um = jc.createUnmarshaller();
obj = um.unmarshal(xmlSource);
} catch (Exception ex) {
log.warn("Failed to unmarshall object. Increase logging to debug for additional information. 4" + ex.getMessage());
log.debug(ex.getMessage(), ex);
} finally {
if (openStream != null) {
try {
openStream.close();
} catch (IOException ex) {
log.debug(ex.getMessage(), ex);
}
}
}
return obj;
}

public static Object unmarshal(File file, Class clazz) {
try {
return unmarshal(file.toURI().toURL(), clazz);
} catch (Exception ex) {
log.warn("Failed to unmarshall object. Increase logging to debug for additional information. 5" + ex.getMessage());
log.debug(ex.getMessage(), ex);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.juddi.v3.client.config.Property;
import org.apache.juddi.v3.client.config.UDDIClerk;
import org.apache.juddi.v3.client.config.UDDIKeyConvention;
import org.apache.juddi.v3.client.cryptor.XmlUtils;
import org.apache.juddi.v3.client.mapping.Common2UDDI;
import org.apache.juddi.v3.client.mapping.MockSSLSocketFactory;
import org.apache.juddi.v3.client.mapping.URLLocalizer;
Expand Down Expand Up @@ -408,7 +409,7 @@ protected BindingTemplate createWADLBinding(QName serviceQName, String portName,
* @return Application instance (WADL FILE)
*/
public static Application parseWadl(InputStream stream) {
Application unmarshal = JAXB.unmarshal(stream, Application.class);
Application unmarshal = (Application) XmlUtils.unmarshal(stream, Application.class);
return unmarshal;
}
public static final String PACKAGE = "org.apache.juddi.v3.client.mapping.wadl";
Expand Down Expand Up @@ -484,8 +485,8 @@ public static Application parseWadl(URL weburl, String username, String password
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String handleResponse = responseHandler.handleResponse(response1);
StringReader sr = new StringReader(handleResponse);
unmarshal = JAXB.unmarshal(sr, Application.class);

unmarshal = (Application) XmlUtils.unmarshal(sr, Application.class);
sr.close();

} finally {
httpGet.releaseConnection();
Expand All @@ -503,7 +504,7 @@ public static Application parseWadl(URL weburl, String username, String password
}

public static Application parseWadl(File file) throws FileNotFoundException, IOException {
Application unmarshal = JAXB.unmarshal(file, Application.class);
Application unmarshal = (Application) XmlUtils.unmarshal(file, Application.class);
return unmarshal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.reflect.Method;
import java.rmi.Remote;
import java.util.List;
import javax.xml.XMLConstants;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -115,6 +116,8 @@ public String getVersion(Element uddiReq, String operation) throws Exception {
public static synchronized String getText(Element element) throws TransformerException {
if (transFactory == null) {
transFactory = TransformerFactory.newInstance();
transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
}
Transformer trans = transFactory.newTransformer();
StringWriter sw = new StringWriter();
Expand Down Expand Up @@ -225,6 +228,7 @@ private synchronized DocumentBuilder createDocumentBuilder() {

try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setNamespaceAware(true);
//factory.setValidating(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.util.HashMap;
import javax.xml.XMLConstants;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Transformer;
Expand Down Expand Up @@ -117,6 +118,7 @@ public Node inquire(Element uddiReq, String nodeName, String clientName) throws
public String inquire(UDDIInquiryPortType inquiry, String request) throws Exception {
java.io.InputStream sbis = new ByteArrayInputStream(request.getBytes());
javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setNamespaceAware(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Expand All @@ -138,7 +140,11 @@ public String inquire(UDDIInquiryPortType inquiry, String request) throws Except
Node n = requestHandler.invoke(reqElem);

StringWriter sw = new StringWriter();
Transformer t = TransformerFactory.newInstance().newTransformer();
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
Transformer t = factory.newTransformer();

t.transform(new DOMSource(n), new StreamResult(sw));
return sw.toString();
}
Expand Down
30 changes: 21 additions & 9 deletions juddi-core/src/main/java/org/apache/juddi/config/Install.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
Expand All @@ -40,6 +42,9 @@
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.configuration.Configuration;
Expand All @@ -56,6 +61,7 @@
import org.apache.juddi.model.ReplicationConfiguration;
import org.apache.juddi.model.UddiEntityPublisher;
import org.apache.juddi.replication.ReplicationNotifier;
import org.apache.juddi.v3.client.cryptor.XmlUtils;
import org.apache.juddi.v3.error.ErrorMessage;
import org.apache.juddi.v3.error.FatalErrorException;
import org.apache.juddi.v3.error.InvalidKeyPassedException;
Expand Down Expand Up @@ -90,7 +96,7 @@ public class Install {
public static final String FILE_REPLICATION_CONFIG = "_replicationConfiguration.xml";
public static final Log log = LogFactory.getLog(Install.class);

protected static void install(Configuration config) throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException {
protected static void install(Configuration config) throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException, XMLStreamException {

EntityManager em = PersistenceManager.getEntityManager();
EntityTransaction tx = em.getTransaction();
Expand Down Expand Up @@ -166,7 +172,11 @@ protected static void install(Configuration config) throws JAXBException, Dispos
log.error(ie.getMessage(), ie);
tx.rollback();
throw ie;
} finally {
} catch (XMLStreamException ex) {
log.error(ex.getMessage(), ex);
tx.rollback();
throw ex;
} finally {
if (tx.isActive()) {
tx.rollback();
}
Expand Down Expand Up @@ -650,10 +660,13 @@ private static Object buildInstallEntityAlt(final String fileName, Class outputt
}
log.debug("inserting: " + xml.toString());
StringReader reader = new StringReader(xml.toString());
return JAXB.unmarshal(reader, outputtype);

Object obj= XmlUtils.unmarshal(reader, outputtype);
reader.close();
return obj;
}

private static Object buildInstallEntity(final String fileName, String packageName, Configuration config) throws JAXBException, IOException, ConfigurationException {
private static Object buildInstallEntity(final String fileName, String packageName, Configuration config) throws JAXBException, IOException, ConfigurationException, XMLStreamException {
InputStream resourceStream = null;

// First try the custom install directory
Expand Down Expand Up @@ -687,9 +700,8 @@ private static Object buildInstallEntity(final String fileName, String packageNa
log.debug("inserting: " + xml.toString());
StringReader reader = new StringReader(xml.toString());

JAXBContext jc = JAXBContext.newInstance(packageName);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Object obj = ((JAXBElement<?>) unmarshaller.unmarshal(new StreamSource(reader))).getValue();
Object obj= XmlUtils.unmarshal(reader, packageName);
reader.close();
return obj;
}

Expand Down Expand Up @@ -733,7 +745,7 @@ public static org.uddi.api_v3.BusinessEntity getNodeBusinessEntity(String busine
* @throws ConfigurationException
*/
public static void installSaveTModel(EntityManager em, String fileName, UddiEntityPublisher publisher, String nodeId, Configuration config)
throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException {
throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException, XMLStreamException {

SaveTModel apiSaveTModel = (SaveTModel) buildInstallEntity(fileName, "org.uddi.api_v3", config);
if (apiSaveTModel != null) {
Expand All @@ -754,7 +766,7 @@ public static void installSaveTModel(EntityManager em, String fileName, UddiEnti
* @throws ConfigurationException
*/
public static UddiEntityPublisher installPublisher(EntityManager em, String fileName, Configuration config)
throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException {
throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException, XMLStreamException {

org.apache.juddi.api_v3.Publisher apiPub = (org.apache.juddi.api_v3.Publisher) buildInstallEntity(fileName, "org.apache.juddi.api_v3", config);
if (apiPub == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.apache.juddi.model.Signature;
import org.apache.juddi.model.SignatureTransformDataValue;
import org.apache.juddi.subscription.TypeConvertor;
import org.apache.juddi.v3.client.cryptor.XmlUtils;
import org.apache.juddi.v3.error.ErrorMessage;
import org.apache.juddi.v3.error.FatalErrorException;
import org.uddi.api_v3.BusinessEntity;
Expand Down Expand Up @@ -1205,9 +1206,11 @@ private static Object convertDataToTransformContent(String type, byte[] xformByt
transformObject = xformBytes;
} else if (type.equals(Element.class.getCanonicalName())) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setXIncludeAware(true);
try {
try {
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setNamespaceAware(true);
dbf.setXIncludeAware(true);

DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(xformBytes));
transformObject = doc.getDocumentElement();
Expand Down Expand Up @@ -1348,7 +1351,7 @@ public static ChangeRecord mapChangeRecord(org.apache.juddi.model.ChangeRecord c
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(MappingModelToApi.class.getName()).log(Level.SEVERE, null, ex);
}
ret = JAXB.unmarshal(sr, ChangeRecord.class);
ret = (ChangeRecord) XmlUtils.unmarshal(sr, ChangeRecord.class);
//secret sauce here, if this is -1, that means that the record originated at this node and needs to be populated with the databases record id
if (cr.getOriginatingUSN() == null || cr.getOriginatingUSN() == -1L) {
ret.setChangeID(new ChangeRecordIDType(cr.getNodeID(), cr.getId()));
Expand Down
Loading

0 comments on commit 248b39c

Please sign in to comment.