001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.soap; 014 015import java.util.*; 016import java.util.concurrent.*; 017 018import org.apache.juneau.*; 019import org.apache.juneau.annotation.*; 020import org.apache.juneau.serializer.*; 021import org.apache.juneau.xml.*; 022 023/** 024 * Serializes POJOs to HTTP responses as XML+SOAP. 025 * 026 * <h5 class='topic'>Media types</h5> 027 * 028 * Handles <c>Accept</c> types: <bc>text/xml+soap</bc> 029 * <p> 030 * Produces <c>Content-Type</c> types: <bc>text/xml+soap</bc> 031 * 032 * <h5 class='topic'>Description</h5> 033 * 034 * Essentially the same output as {@link XmlDocSerializer}, except wrapped in a standard SOAP envelope. 035 */ 036@ConfigurableContext 037public final class SoapXmlSerializer extends XmlSerializer implements SoapXmlMetaProvider,SoapXmlCommon { 038 039 //------------------------------------------------------------------------------------------------------------------- 040 // Configurable properties 041 //------------------------------------------------------------------------------------------------------------------- 042 043 static final String PREFIX = "SoapXmlSerializer"; 044 045 /** 046 * Configuration property: The <c>SOAPAction</c> HTTP header value to set on responses. 047 * 048 * <h5 class='section'>Property:</h5> 049 * <ul class='spaced-list'> 050 * <li><b>ID:</b> {@link org.apache.juneau.soap.SoapXmlSerializer#SOAPXML_SOAPAction SOAPXML_SOAPAction} 051 * <li><b>Name:</b> <js>"SoapXmlSerializer.SOAPAction.s"</js> 052 * <li><b>Data type:</b> <c>String</c> 053 * <li><b>System property:</b> <c>SoapXmlSerializer.SOAPAction</c> 054 * <li><b>Environment variable:</b> <c>SOAPXMLSERIALIZER_SOAPACTION</c> 055 * <li><b>Default:</b> <js>"http://www.w3.org/2003/05/soap-envelope"</js> 056 * <li><b>Annotations:</b> 057 * <ul> 058 * <li class='ja'>{@link org.apache.juneau.soap.annotation.SoapXmlConfig#soapAction()} 059 * </ul> 060 * <li><b>Methods:</b> 061 * <ul> 062 * <li class='jm'>{@link org.apache.juneau.soap.SoapXmlSerializerBuilder#soapAction(String)} 063 * </ul> 064 * </ul> 065 */ 066 public static final String SOAPXML_SOAPAction = PREFIX + ".SOAPAction.s"; 067 068 069 //------------------------------------------------------------------------------------------------------------------- 070 // Instance 071 //------------------------------------------------------------------------------------------------------------------- 072 073 final String soapAction; 074 private final Map<ClassMeta<?>,SoapXmlClassMeta> soapXmlClassMetas = new ConcurrentHashMap<>(); 075 private final Map<BeanPropertyMeta,SoapXmlBeanPropertyMeta> soapXmlBeanPropertyMetas = new ConcurrentHashMap<>(); 076 077 /** 078 * Constructor. 079 * 080 * @param ps The property store containing all the settings for this object. 081 */ 082 public SoapXmlSerializer(PropertyStore ps) { 083 super(ps, "text/xml", "text/xml+soap"); 084 soapAction = getStringProperty(SOAPXML_SOAPAction, "http://www.w3.org/2003/05/soap-envelope"); 085 } 086 087 @Override /* Context */ 088 public SoapXmlSerializerBuilder builder() { 089 return new SoapXmlSerializerBuilder(getPropertyStore()); 090 } 091 092 /** 093 * Instantiates a new clean-slate {@link SoapXmlSerializerBuilder} object. 094 * 095 * <p> 096 * This is equivalent to simply calling <code><jk>new</jk> SoapXmlSerializerBuilder()</code>. 097 * 098 * <p> 099 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 100 * the settings of the object called on. 101 * 102 * @return A new {@link SoapXmlSerializerBuilder} object. 103 */ 104 public static SoapXmlSerializerBuilder create() { 105 return new SoapXmlSerializerBuilder(); 106 } 107 108 @Override /* Serializer */ 109 public SoapXmlSerializerSession createSession() { 110 return createSession(createDefaultSessionArgs()); 111 } 112 113 @Override /* Serializer */ 114 public SoapXmlSerializerSession createSession(SerializerSessionArgs args) { 115 return new SoapXmlSerializerSession(this, args); 116 } 117 118 //----------------------------------------------------------------------------------------------------------------- 119 // Extended metadata 120 //----------------------------------------------------------------------------------------------------------------- 121 122 @Override /* SoapXmlMetaProvider */ 123 public SoapXmlClassMeta getSoapXmlClassMeta(ClassMeta<?> cm) { 124 SoapXmlClassMeta m = soapXmlClassMetas.get(cm); 125 if (m == null) { 126 m = new SoapXmlClassMeta(cm, this); 127 soapXmlClassMetas.put(cm, m); 128 } 129 return m; 130 } 131 132 @Override /* SoapXmlMetaProvider */ 133 public SoapXmlBeanPropertyMeta getSoapXmlBeanPropertyMeta(BeanPropertyMeta bpm) { 134 if (bpm == null) 135 return SoapXmlBeanPropertyMeta.DEFAULT; 136 SoapXmlBeanPropertyMeta m = soapXmlBeanPropertyMetas.get(bpm); 137 if (m == null) { 138 m = new SoapXmlBeanPropertyMeta(bpm.getDelegateFor(), this); 139 soapXmlBeanPropertyMetas.put(bpm, m); 140 } 141 return m; 142 } 143 144 //----------------------------------------------------------------------------------------------------------------- 145 // Properties 146 //----------------------------------------------------------------------------------------------------------------- 147 148 /** 149 * Configuration property: The SOAPAction HTTP header value to set on responses. 150 * 151 * @see #SOAPXML_SOAPAction 152 * @return 153 * The SOAPAction HTTP header value to set on responses. 154 */ 155 public String getSoapAction() { 156 return soapAction; 157 } 158 159 //----------------------------------------------------------------------------------------------------------------- 160 // Other methods 161 //----------------------------------------------------------------------------------------------------------------- 162 163 @Override /* Context */ 164 public ObjectMap toMap() { 165 return super.toMap() 166 .append("SoapXmlSerializer", new DefaultFilteringObjectMap() 167 .append("soapAction", soapAction) 168 ); 169 } 170}