001/* 002 * The MIT License 003 * Copyright (c) 2012 Microsoft Corporation 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a copy 006 * of this software and associated documentation files (the "Software"), to deal 007 * in the Software without restriction, including without limitation the rights 008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 009 * copies of the Software, and to permit persons to whom the Software is 010 * furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 021 * THE SOFTWARE. 022 */ 023 024package microsoft.exchange.webservices.data.core.request; 025 026import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter; 027import microsoft.exchange.webservices.data.core.EwsUtilities; 028import microsoft.exchange.webservices.data.core.ExchangeService; 029import microsoft.exchange.webservices.data.core.XmlElementNames; 030import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling; 031import microsoft.exchange.webservices.data.core.response.ServiceResponse; 032import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion; 033import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace; 034import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException; 035import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException; 036 037import javax.xml.stream.XMLStreamException; 038 039/** 040 * The Class UnsubscribeRequest. 041 */ 042public class UnsubscribeRequest extends MultiResponseServiceRequest<ServiceResponse> { 043 044 /** 045 * The subscription id. 046 */ 047 private String subscriptionId; 048 049 /** 050 * Instantiates a new unsubscribe request. 051 * 052 * @param service the service 053 * @throws Exception 054 */ 055 public UnsubscribeRequest(ExchangeService service) 056 throws Exception { 057 super(service, ServiceErrorHandling.ThrowOnError); 058 } 059 060 /** 061 * Creates service response. 062 * 063 * @param service the service 064 * @param responseIndex the response index 065 * @return Service response. 066 */ 067 @Override 068 protected ServiceResponse createServiceResponse(ExchangeService service, 069 int responseIndex) { 070 return new ServiceResponse(); 071 } 072 073 /** 074 * Gets the expected response message count. 075 * 076 * @return Number of expected response messages. 077 */ 078 @Override 079 protected int getExpectedResponseMessageCount() { 080 return 1; 081 } 082 083 /** 084 * Gets the name of the XML element. 085 * 086 * @return Xml element name. 087 */ 088 @Override public String getXmlElementName() { 089 return XmlElementNames.Unsubscribe; 090 } 091 092 /** 093 * Gets the name of the response XML element. 094 * 095 * @return Xml element name. 096 */ 097 @Override 098 protected String getResponseXmlElementName() { 099 return XmlElementNames.UnsubscribeResponse; 100 } 101 102 /** 103 * Gets the name of the response message XML element. 104 * 105 * @return Xml element name. 106 */ 107 @Override 108 protected String getResponseMessageXmlElementName() { 109 return XmlElementNames.UnsubscribeResponseMessage; 110 } 111 112 /** 113 * Validate the request. 114 * 115 * @throws ServiceLocalException the service local exception 116 * @throws Exception the exception 117 */ 118 @Override 119 protected void validate() throws ServiceLocalException, Exception { 120 super.validate(); 121 EwsUtilities.validateNonBlankStringParam(this. 122 getSubscriptionId(), "SubscriptionId"); 123 124 } 125 126 /** 127 * Writes XML elements. 128 * 129 * @param writer the writer 130 * @throws XMLStreamException the XML stream exception 131 * @throws ServiceXmlSerializationException the service xml serialization exception 132 */ 133 @Override 134 protected void writeElementsToXml(EwsServiceXmlWriter writer) 135 throws XMLStreamException, ServiceXmlSerializationException { 136 writer.writeElementValue(XmlNamespace.Messages, 137 XmlElementNames.SubscriptionId, this.getSubscriptionId()); 138 } 139 140 /** 141 * Gets the request version. 142 * 143 * @return Earliest Exchange version in which this request is supported. 144 */ 145 @Override 146 protected ExchangeVersion getMinimumRequiredServerVersion() { 147 return ExchangeVersion.Exchange2007_SP1; 148 } 149 150 /** 151 * Gets the subscription id. 152 * 153 * @return the subscription id 154 */ 155 public String getSubscriptionId() { 156 return this.subscriptionId; 157 } 158 159 /** 160 * Sets the subscription id. 161 * 162 * @param subscriptionId the new subscription id 163 */ 164 public void setSubscriptionId(String subscriptionId) { 165 this.subscriptionId = subscriptionId; 166 } 167 @Override 168 protected HttpWebRequest buildEwsHttpWebRequest() throws Exception 169 { 170 return super.buildEwsHttpPoolingWebRequest(); 171 } 172}