📄 submitrequest.java
字号:
package com.openwave.mms.mm7;import java.io.ByteArrayOutputStream;import java.util.Calendar;import java.util.Enumeration;import java.util.HashMap;import java.io.IOException;import java.io.OutputStream;import java.util.Properties;import java.io.UnsupportedEncodingException;import java.util.Vector;import java.util.List;import javax.mail.Header;import javax.mail.MessagingException;import javax.mail.internet.MimeBodyPart;import javax.mail.internet.MimeMessage;import javax.mail.internet.MimeMultipart;import javax.mail.internet.MimeUtility;import javax.mail.Session;import org.apache.log4j.Logger;import org.apache.log4j.Level;import com.openwave.mms.mm7.soap.SOAPBody;import com.openwave.mms.mm7.soap.SOAPConsts;import com.openwave.mms.mm7.soap.SOAPEnvelope;import com.openwave.mms.mm7.soap.SOAPException;import com.openwave.mms.mm7.soap.SOAPMethod;import com.openwave.mms.mm7.soap.SOAPParameter;import com.openwave.mms.mm7.soap.SOAPQName;import com.openwave.mms.mm7.util.Utils;import com.openwave.mms.mm7.util.Enum;import com.openwave.mms.content.ContentException;import com.openwave.mms.content.Factory;import com.openwave.mms.content.MultimediaContent;/** * This class encapsulates an MM7 SubmitRequest message that contains multimedia * content and which the application sends to MMSC for delivery to mobile subscribers. * <p> * To use this class: * <OL> * <LI> Create a <code>SubmitRequest</code> object. * <LI> Set the mandatory <code>Recipients</code> field using either the * <code>addRecipient</code> or <code>addRecipients</code> method, depending * on whether you want to add one or more than one recipient at a time. * <LI> Set additional data elements that you require. * <LI> Create an array of <code>javax.mail.internet.MimeBodyPart</code> objects, * using standard JavaMail classes, that define the multimedia message content * and assign it to the <code>SubmitRequest</code> object. * <LI> Use the {@link RelayConnection} class' <code>sendRequest</code> method to send the * submit request to the carrier. * </OL> * </p> * For further information about using this class to create and send submit requests * to the carrier, see the <em>Openwave MMS Library Developer's Guide</em>. */ public final class SubmitRequest extends Request { /** * This inner class encapsulates the constants that identify the message class. */ public static class MessageClass extends Enum { /** * Private constructor ensures that only values created herein are used. * * @param messageClass The message class value. */ private MessageClass( String messageClass ) { super( messageClass ); } /** * Returns the message class for this submit request as a <code>String</code> object. * * @return The message class as a <code>String</code> object. */ public static MessageClass valueOf( String messageClass ) { return ( MessageClass ) allowedValues.get( messageClass.toLowerCase() ); } /** * String constant that identifies the class of this message as personal. */ public static final MessageClass PERSONAL = new MessageClass( SOAPConsts.MM7PersonalParameterValue ); /** * String constant that identifies the class of this message as informational. */ public static final MessageClass INFORMATIONAL = new MessageClass( SOAPConsts.MM7InformationalParameterValue ); /** * String constant that identifies the class of this message as advertisement. */ public static final MessageClass ADVERTISEMENT = new MessageClass( SOAPConsts.MM7AdvertisementParameterValue ); /** * String constant that identifies the class of this message as automatic. */ public static final MessageClass AUTO = new MessageClass( SOAPConsts.MM7AutoParameterValue ); } /** * This inner class encapsulates the constants that identify the message priority. */ public static class Priority extends Enum { /** * Private constructor ensures that only values created herein are used. * * @param priority The priority value. */ private Priority( String priority ) { super( priority ); } /** * Returns a <code>Priority</code> object based on the value of the priority * <code>String</code> value supplied. * * @return <code>Priority</code> object that corresponds to a priority * <code>String</code> value. */ public static Priority valueOf( String priority ) { return ( Priority ) allowedValues.get( priority.toLowerCase() ); } /** * String constant that identifies the priority of this message as low. */ public static final Priority LOW = new Priority( SOAPConsts.MM7PriorityLowParameterValue ); /** * String constant that identifies the priority of this message as high. */ public static final Priority HIGH = new Priority( SOAPConsts.MM7PriorityHighParameterValue ); /** * String constant that identifies the priority of this message as normal. */ public static final Priority NORMAL = new Priority( SOAPConsts.MM7PriorityNormalParameterValue ); } /** * This inner class encapsulates the constants that indentify * the party charged for the message. */ public static class ChargedParty extends Enum { /** * Private constructor ensures that only values created herein are used. * * @param chargedParty The charged party value. */ private ChargedParty( String chargedParty ) { super( chargedParty ); } /** * Returns the party charged for this message as a <code>String</code> object. * * @return The party charged for the request as a <code>String</code> object. */ public static ChargedParty valueOf( String chargedParty ) { return ( ChargedParty ) allowedValues.get( chargedParty.toLowerCase() ); } /** * String constant that identifies the sender as the party charged for * this message. */ public static final ChargedParty SENDER = new ChargedParty( SOAPConsts.MM7ChargedPartySenderParameterValue ); /** * String constant that identifies the recipient as the party charged for * this message. */ public static final ChargedParty RECIPIENT = new ChargedParty( SOAPConsts.MM7ChargedPartyRecipientParameterValue ); /** * String constant that identifies both the sender and the recipient as the * parties charged for this message. */ public static final ChargedParty BOTH = new ChargedParty( SOAPConsts.MM7ChargedPartyBothParameterValue ); /** * String constant that identifies neither the sender nor the recipient is * charged for this message. */ public static final ChargedParty NEITHER = new ChargedParty( SOAPConsts.MM7ChargedPartyNeitherParameterValue ); } /** * Instantiates a <code>SubmitRequest</code> object. */ public SubmitRequest() { recipients = new Vector(); replyChargingSize = -1; deliveryReport = null; readReply = null; distributionIndicator = null; } /** * Adds a single recipient to this message. * * @param recipientType Type of recipient. Must be one of values defined by the * {@link Recipient.Type} class. * @param recipientAddressType Type of recipient address. Must be one of values defined by the * {@link AddressType} class. * @param recipientAddress Address of recipient. * @exception APIException If the value of <code>recipientType</code> or <code>recipientAddrType</code> is * not one of the defined constants, or if an error occurs when parsing the value of * <code>recipientAddr</code> when declared as type <code>AddressType.EMAIL</code>. */ public void addRecipient( Recipient.Type recipientType, AddressType recipientAddressType, String recipientAddress ) throws APIException { recipients.add( new Recipient( recipientType, recipientAddressType, recipientAddress ) ); } /** * Adds several recipients at a time to this message. * * @param recipients <code>Vector</code> of Recipient objects to add to this message. */ public void addRecipients( Vector recipients ) { this.recipients.addAll( recipients ); } /** * Sets the service code for this message to specify content-provider-specific * information for billing purposes. * <p> * MMSC stores this value in the <code>vasServiceCode</code> field of charging data * records (CDRs). You can use this value to aid the process of reconciling copies of * provider-related CDRs. * * @param serviceCode The service code for this request. */ public void setServiceCode( String serviceCode ) { this.serviceCode = serviceCode; } /** * Sets the linked message ID for this message. Specify the ID of a message * previously received and for which this message is submitted in response. * * @param linkedID The linked message ID for this request. */ public void setLinkedID( String linkedID ) { this.linkedID = linkedID; } /** * Sets the message class for this message. * * @param messageClass The message class for this request. Must be one of values defined * by the {@link SubmitRequest.MessageClass} class. */ public void setMessageClass( MessageClass messageClass ) { this.messageClass = messageClass; } /** * Sets the message priority for this message. * * @param priority The priority of the message. Must be one of values defined * by the {@link SubmitRequest.Priority} class. */ public void setPriority( Priority priority ) { this.priority = priority; } /** * Sets the charged party for this message. * * @param chargedParty The charged party for this message. Must be one of values defined * by the {@link SubmitRequest.ChargedParty} class. */ public void setChargedParty( ChargedParty chargedParty ) { this.chargedParty = chargedParty; } /** * Sets the maximum size, in bytes, of a recipient reply to this message. * This value is used only when the message uses reply-charging to charge * the content provider for replies. * * @param replyChargingSize The size of the reply message. */ public void setReplyChargingSize( int replyChargingSize ) { if( replyChargingSize > 0 ) this.replyChargingSize = replyChargingSize; } /** * Sets the deadline after which the carrier does not accept replies to this message. * This value is used only when the message uses reply-charging to charge the content * provider for replies. * * @param replyDeadline The deadline by which the recipient must reply. */ public void setReplyDeadline( Calendar replyDeadline ) { this.replyDeadline = Utils.convertDateToISO8601( replyDeadline ); } /* * Sets the earliest delivery time for a deferred delivery * message. The relay will deliver the message only after this time * has passed. * * @param earliestDeliveryTime The time after which the message can be delivered. */ public void setEarliestDeliveryTime( Calendar earliestDeliveryTime ) { this.earliestDeliveryTime = Utils.convertDateToISO8601( earliestDeliveryTime ); } /** * Sets the point in time after which the carrier does not attempt to deliver * this message. * * @param expiry The time after which the message is not delivered. */ public void setExpiry( Calendar expiry ) { this.expiry = Utils.convertDateToISO8601( expiry ); } /** * Sets whether a delivery report is requested for this message. If one is requested, * the carrier generates one and delivers it to the sender after delivering * the message to the recipient. * * @param deliveryReport A Boolean value that specifies whether a delivery report is requested. * <code>true</code> indicates that a report is requested. * The default is <code>false</code>, a report is not requested. */ public void setDeliveryReport( boolean deliveryReport ) { this.deliveryReport = new Boolean( deliveryReport ); } /** * Sets whether a read-reply report is requested for this message. If one is requested, * the recipient user agent generates one after downloading the message and * the carrier delivers the report to the sender. * * @param readReply A Boolean value that specifies whether a read-reply report is requested. * <code>true</code> indicates that a report is requested. * The default is <code>false</code>, a report is not requested. */ public void setReadReply( boolean readReply ) { this.readReply = new Boolean( readReply ); } /** * Sets whether recipients can redistribute this message. * * @param distributionIndicator A boolean value that specifies whether recipients can redistribute * this message. <code>true</code> indicates that recipients can redistribute this * message. The default is <code>false</code>, recipients cannot redistribute this * message.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -