Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement for character escape handling #1109

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.camel.converter.jaxb;

/**
* Constants used by Camel Jaxb module
*
*
*/
public interface JaxbConstants {

/** Key to identify marshaller properties in the exchange specific to JAX-RI implementation */
String JAXB_PROVIDER_PROPERTIES = "CamelJaxbProviderCustomProperties";

}
Expand Up @@ -26,8 +26,10 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
Expand All @@ -46,8 +48,6 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.SAXException;

import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
Expand All @@ -61,9 +61,11 @@
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ResourceHelper;
import org.xml.sax.SAXException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* A <a href="http://camel.apache.org/data-format.html">data format</a> ({@link DataFormat})
* using JAXB2 to marshal to and from XML
Expand Down Expand Up @@ -101,6 +103,7 @@ public class JaxbDataFormat extends ServiceSupport implements DataFormat, DataFo
private JaxbXmlStreamWriterWrapper xmlStreamWriterWrapper;
private TypeConverter typeConverter;
private Schema cachedSchema;
private Map<String, Object> jaxbProviderPropertiesMap;

public JaxbDataFormat() {
}
Expand Down Expand Up @@ -146,7 +149,16 @@ public void marshal(Exchange exchange, Object graph, OutputStream stream) throws
if (namespacePrefixMapper != null) {
marshaller.setProperty(namespacePrefixMapper.getRegistrationKey(), namespacePrefixMapper);
}

// Inject any JAX-RI custom properties from the exchange or from the instance into the marshaller
Map<String, Object> jaxbProviderPropertiesMap = exchange.getProperty(JaxbConstants.JAXB_PROVIDER_PROPERTIES, Map.class);
if(jaxbProviderPropertiesMap == null) {
jaxbProviderPropertiesMap = getJaxbProviderPropertiesMap();
}
if(jaxbProviderPropertiesMap != null) {
for(Entry<String, Object> property : jaxbProviderPropertiesMap.entrySet()) {
marshaller.setProperty(property.getKey(), property.getValue());
}
}
marshal(exchange, graph, stream, marshaller);

} catch (Exception e) {
Expand Down Expand Up @@ -536,4 +548,13 @@ private void returnSchemaFactory(SchemaFactory factory) {
SCHEMA_FACTORY_POOL.offer(factory);
}
}

public Map<String, Object> getJaxbProviderPropertiesMap() {
return jaxbProviderPropertiesMap;
}

public void setJaxbProviderPropertiesMap(Map<String, Object> jaxbProviderPropertiesMap) {
this.jaxbProviderPropertiesMap = jaxbProviderPropertiesMap;
}

}