Package org.apache.ws.pubsub.emitter.http

Source Code of org.apache.ws.pubsub.emitter.http.HttpEmitterTask

/*=============================================================================*
*  Copyright 2004 The Apache Software Foundation
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*=============================================================================*/
package org.apache.ws.pubsub.emitter.http;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.pubsub.emitter.EmitterException;
import org.apache.ws.pubsub.emitter.EmitterTask;
import org.apache.ws.pubsub.i18n.Keys;
import org.apache.ws.pubsub.i18n.MessagesImpl;
import org.apache.ws.util.i18n.Messages;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import java.net.URL;

/**
* An emitter task that sends a notification via the HTTP protocol.
*/
public class HttpEmitterTask
   extends EmitterTask
{
   /** This emitter's protocol */
   public static final String PROTOCOL = "http";

   /** object used to obtain I18N messages */
   private static final Messages MSG = MessagesImpl.getInstance(  );

   /** object used to log messages */
   private static final Log LOG = LogFactory.getLog( HttpEmitterTask.class );

   /**
    * Creates a new {@link HttpEmitterTask} object.
    *
    * @see EmitterTask(SOAPMessage, URL)
    */
   public HttpEmitterTask( SOAPMessage notif,
                           URL         url )
   {
      super( notif, url );
   }

   /**
    * Sends the notification to the destination via HTTP.
    *
    * @see EmitterTask#emit()
    */
   protected void emit(  )
   throws EmitterException
   {
      LOG.debug( MSG.getMessage( Keys.EMITTING_TO_HTTP_DEST,
                                 getDestinationUrl(  ) ) );

      try
      {
         SOAPConnection soapConn = SOAPConnectionFactory.newInstance(  ).createConnection(  );
         SOAPMessage    response = soapConn.call( getNotification(  ),
                                                  getDestinationUrl(  ).toString(  ) );
         if ( LOG.isDebugEnabled(  ) )
         {
            if ( response != null )
            {
               LOG.debug( MSG.getMessage( Keys.RESPONSE_TO_EMIT,
                                          response.toString(  ) ) );
            }
         }
      }
      catch ( SOAPException e )
      {
         throw new EmitterException( MSG.getMessage( Keys.EX_FAILED_TO_SEND_HTTP_NOTIFICATION,
                                                     getDestinationUrl(  ) ), e );
      }
   }
}
TOP

Related Classes of org.apache.ws.pubsub.emitter.http.HttpEmitterTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.