001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.model.DataFormatDefinition; 026import org.apache.camel.spi.Metadata; 027 028/** 029 * Marshal Java objects to SOAP messages and back. 030 */ 031@Metadata(firstVersion = "2.3.0", label = "dataformat,transformation,xml", title = "SOAP") 032@XmlRootElement(name = "soapjaxb") 033@XmlAccessorType(XmlAccessType.FIELD) 034public class SoapJaxbDataFormat extends DataFormatDefinition { 035 @XmlAttribute(required = true) 036 private String contextPath; 037 @XmlAttribute 038 private String encoding; 039 @XmlAttribute 040 private String elementNameStrategyRef; 041 @XmlTransient 042 private Object elementNameStrategy; 043 @XmlAttribute 044 @Metadata(defaultValue = "1.1") 045 private String version; 046 @XmlAttribute 047 private String namespacePrefixRef; 048 @XmlAttribute 049 private String schema; 050 051 public SoapJaxbDataFormat() { 052 super("soapjaxb"); 053 } 054 055 public SoapJaxbDataFormat(String contextPath) { 056 this(); 057 setContextPath(contextPath); 058 } 059 060 public SoapJaxbDataFormat(String contextPath, String elementNameStrategyRef) { 061 this(); 062 setContextPath(contextPath); 063 setElementNameStrategyRef(elementNameStrategyRef); 064 } 065 066 public SoapJaxbDataFormat(String contextPath, Object elementNameStrategy) { 067 this(); 068 setContextPath(contextPath); 069 setElementNameStrategy(elementNameStrategy); 070 } 071 072 /** 073 * Package name where your JAXB classes are located. 074 */ 075 public void setContextPath(String contextPath) { 076 this.contextPath = contextPath; 077 } 078 079 public String getContextPath() { 080 return contextPath; 081 } 082 083 /** 084 * To overrule and use a specific encoding 085 */ 086 public void setEncoding(String encoding) { 087 this.encoding = encoding; 088 } 089 090 public String getEncoding() { 091 return encoding; 092 } 093 094 /** 095 * Refers to an element strategy to lookup from the registry. 096 * <p/> 097 * An element name strategy is used for two purposes. The first is to find a 098 * xml element name for a given object and soap action when marshaling the 099 * object into a SOAP message. The second is to find an Exception class for 100 * a given soap fault name. 101 * <p/> 102 * The following three element strategy class name is provided out of the 103 * box. QNameStrategy - Uses a fixed qName that is configured on 104 * instantiation. Exception lookup is not supported TypeNameStrategy - Uses 105 * the name and namespace from the @XMLType annotation of the given type. If 106 * no namespace is set then package-info is used. Exception lookup is not 107 * supported ServiceInterfaceStrategy - Uses information from a webservice 108 * interface to determine the type name and to find the exception class for 109 * a SOAP fault 110 * <p/> 111 * All three classes is located in the package name 112 * org.apache.camel.dataformat.soap.name 113 * <p/> 114 * If you have generated the web service stub code with cxf-codegen or a 115 * similar tool then you probably will want to use the 116 * ServiceInterfaceStrategy. In the case you have no annotated service 117 * interface you should use QNameStrategy or TypeNameStrategy. 118 */ 119 public void setElementNameStrategyRef(String elementNameStrategyRef) { 120 this.elementNameStrategyRef = elementNameStrategyRef; 121 } 122 123 public String getElementNameStrategyRef() { 124 return elementNameStrategyRef; 125 } 126 127 public String getVersion() { 128 return version; 129 } 130 131 /** 132 * SOAP version should either be 1.1 or 1.2. 133 * <p/> 134 * Is by default 1.1 135 */ 136 public void setVersion(String version) { 137 this.version = version; 138 } 139 140 /** 141 * Sets an element strategy instance to use. 142 * <p/> 143 * An element name strategy is used for two purposes. The first is to find a 144 * xml element name for a given object and soap action when marshaling the 145 * object into a SOAP message. The second is to find an Exception class for 146 * a given soap fault name. 147 * <p/> 148 * The following three element strategy class name is provided out of the 149 * box. QNameStrategy - Uses a fixed qName that is configured on 150 * instantiation. Exception lookup is not supported TypeNameStrategy - Uses 151 * the name and namespace from the @XMLType annotation of the given type. If 152 * no namespace is set then package-info is used. Exception lookup is not 153 * supported ServiceInterfaceStrategy - Uses information from a webservice 154 * interface to determine the type name and to find the exception class for 155 * a SOAP fault 156 * <p/> 157 * All three classes is located in the package name 158 * org.apache.camel.dataformat.soap.name 159 * <p/> 160 * If you have generated the web service stub code with cxf-codegen or a 161 * similar tool then you probably will want to use the 162 * ServiceInterfaceStrategy. In the case you have no annotated service 163 * interface you should use QNameStrategy or TypeNameStrategy. 164 */ 165 public void setElementNameStrategy(Object elementNameStrategy) { 166 this.elementNameStrategy = elementNameStrategy; 167 } 168 169 public Object getElementNameStrategy() { 170 return elementNameStrategy; 171 } 172 173 public String getNamespacePrefixRef() { 174 return namespacePrefixRef; 175 } 176 177 /** 178 * When marshalling using JAXB or SOAP then the JAXB implementation will 179 * automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To 180 * control this mapping, Camel allows you to refer to a map which contains 181 * the desired mapping. 182 */ 183 public void setNamespacePrefixRef(String namespacePrefixRef) { 184 this.namespacePrefixRef = namespacePrefixRef; 185 } 186 187 public String getSchema() { 188 return schema; 189 } 190 191 /** 192 * To validate against an existing schema. Your can use the prefix 193 * classpath:, file:* or *http: to specify how the resource should by 194 * resolved. You can separate multiple schema files by using the ',' 195 * character. 196 */ 197 public void setSchema(String schema) { 198 this.schema = schema; 199 } 200 201}