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 * SOAP is a data format which uses JAXB2 and JAX-WS annotations to marshal and 030 * unmarshal SOAP payloads. 031 */ 032@Metadata(firstVersion = "2.3.0", label = "dataformat,transformation,xml", title = "SOAP") 033@XmlRootElement(name = "soapjaxb") 034@XmlAccessorType(XmlAccessType.FIELD) 035public class SoapJaxbDataFormat extends DataFormatDefinition { 036 @XmlAttribute(required = true) 037 private String contextPath; 038 @XmlAttribute 039 private String encoding; 040 @XmlAttribute 041 private String elementNameStrategyRef; 042 @XmlTransient 043 private Object elementNameStrategy; 044 @XmlAttribute 045 @Metadata(defaultValue = "1.1") 046 private String version; 047 @XmlAttribute 048 private String namespacePrefixRef; 049 @XmlAttribute 050 private String schema; 051 052 public SoapJaxbDataFormat() { 053 super("soapjaxb"); 054 } 055 056 public SoapJaxbDataFormat(String contextPath) { 057 this(); 058 setContextPath(contextPath); 059 } 060 061 public SoapJaxbDataFormat(String contextPath, String elementNameStrategyRef) { 062 this(); 063 setContextPath(contextPath); 064 setElementNameStrategyRef(elementNameStrategyRef); 065 } 066 067 public SoapJaxbDataFormat(String contextPath, Object elementNameStrategy) { 068 this(); 069 setContextPath(contextPath); 070 setElementNameStrategy(elementNameStrategy); 071 } 072 073 /** 074 * Package name where your JAXB classes are located. 075 */ 076 public void setContextPath(String contextPath) { 077 this.contextPath = contextPath; 078 } 079 080 public String getContextPath() { 081 return contextPath; 082 } 083 084 /** 085 * To overrule and use a specific encoding 086 */ 087 public void setEncoding(String encoding) { 088 this.encoding = encoding; 089 } 090 091 public String getEncoding() { 092 return encoding; 093 } 094 095 /** 096 * Refers to an element strategy to lookup from the registry. 097 * <p/> 098 * An element name strategy is used for two purposes. The first is to find a 099 * xml element name for a given object and soap action when marshaling the 100 * object into a SOAP message. The second is to find an Exception class for 101 * a given soap fault name. 102 * <p/> 103 * The following three element strategy class name is provided out of the 104 * box. QNameStrategy - Uses a fixed qName that is configured on 105 * instantiation. Exception lookup is not supported TypeNameStrategy - Uses 106 * the name and namespace from the @XMLType annotation of the given type. If 107 * no namespace is set then package-info is used. Exception lookup is not 108 * supported ServiceInterfaceStrategy - Uses information from a webservice 109 * interface to determine the type name and to find the exception class for 110 * a SOAP fault 111 * <p/> 112 * All three classes is located in the package name 113 * org.apache.camel.dataformat.soap.name 114 * <p/> 115 * If you have generated the web service stub code with cxf-codegen or a 116 * similar tool then you probably will want to use the 117 * ServiceInterfaceStrategy. In the case you have no annotated service 118 * interface you should use QNameStrategy or TypeNameStrategy. 119 */ 120 public void setElementNameStrategyRef(String elementNameStrategyRef) { 121 this.elementNameStrategyRef = elementNameStrategyRef; 122 } 123 124 public String getElementNameStrategyRef() { 125 return elementNameStrategyRef; 126 } 127 128 public String getVersion() { 129 return version; 130 } 131 132 /** 133 * SOAP version should either be 1.1 or 1.2. 134 * <p/> 135 * Is by default 1.1 136 */ 137 public void setVersion(String version) { 138 this.version = version; 139 } 140 141 /** 142 * Sets an element strategy instance to use. 143 * <p/> 144 * An element name strategy is used for two purposes. The first is to find a 145 * xml element name for a given object and soap action when marshaling the 146 * object into a SOAP message. The second is to find an Exception class for 147 * a given soap fault name. 148 * <p/> 149 * The following three element strategy class name is provided out of the 150 * box. QNameStrategy - Uses a fixed qName that is configured on 151 * instantiation. Exception lookup is not supported TypeNameStrategy - Uses 152 * the name and namespace from the @XMLType annotation of the given type. If 153 * no namespace is set then package-info is used. Exception lookup is not 154 * supported ServiceInterfaceStrategy - Uses information from a webservice 155 * interface to determine the type name and to find the exception class for 156 * a SOAP fault 157 * <p/> 158 * All three classes is located in the package name 159 * org.apache.camel.dataformat.soap.name 160 * <p/> 161 * If you have generated the web service stub code with cxf-codegen or a 162 * similar tool then you probably will want to use the 163 * ServiceInterfaceStrategy. In the case you have no annotated service 164 * interface you should use QNameStrategy or TypeNameStrategy. 165 */ 166 public void setElementNameStrategy(Object elementNameStrategy) { 167 this.elementNameStrategy = elementNameStrategy; 168 } 169 170 public Object getElementNameStrategy() { 171 return elementNameStrategy; 172 } 173 174 public String getNamespacePrefixRef() { 175 return namespacePrefixRef; 176 } 177 178 /** 179 * When marshalling using JAXB or SOAP then the JAXB implementation will 180 * automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To 181 * control this mapping, Camel allows you to refer to a map which contains 182 * the desired mapping. 183 */ 184 public void setNamespacePrefixRef(String namespacePrefixRef) { 185 this.namespacePrefixRef = namespacePrefixRef; 186 } 187 188 public String getSchema() { 189 return schema; 190 } 191 192 /** 193 * To validate against an existing schema. Your can use the prefix 194 * classpath:, file:* or *http: to specify how the resource should by 195 * resolved. You can separate multiple schema files by using the ',' 196 * character. 197 */ 198 public void setSchema(String schema) { 199 this.schema = schema; 200 } 201 202}