/*=============================================================================*
* 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.eventing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.pubsub.wsaSOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
/**
* DOCUMENT_ME
*
* @version $Revision: 1.8 $
* @author $author$
*/
public class ForwardConsumer
implements org.apache.ws.pubsub.NotificationConsumer
{
private static final Log LOG = LogFactory.getLog( ForwardConsumer.class.getName( ) );
/** DOCUMENT_ME */
public EndpointReference epr;
/**
* Creates a new {@link ForwardConsumer} object.
*
* @param epr DOCUMENT_ME
*/
public ForwardConsumer( EndpointReference epr )
{
this.epr = epr;
}
/**
* DOCUMENT_ME
*
* @param epr DOCUMENT_ME
*/
public void setEPR( EndpointReference epr )
{
this.epr = epr;
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public EndpointReference getEPR( )
{
return this.epr;
}
/**
* DOCUMENT_ME
*
* @param subscription DOCUMENT_ME
* @param message DOCUMENT_ME
*/
public void notify( org.apache.ws.pubsub.Subscription subscription,
Object message )
{
LOG.info( "ForwardConsumer :" + this.epr.getAddress( ) );
try
{
//now call
wsaSOAPConnection sconn = wsaSOAPConnection.newInstance( );
MessageFactory mf = MessageFactory.newInstance( );
SOAPMessage soapm = mf.createMessage( );
//DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//org.w3c.dom.Document dom = builder.parse(new java.io.ByteArrayInputStream(((String) message).getBytes()));
//put Message into SOAPBody
if ( subscription.getUseNotify( ) == true )
{
SOAPElement se =
soapm.getSOAPBody( ).addChildElement( "http://schemas.xmlsoap.org/ws/2004/08/eventing", "Notify" );
se.addChildElement( (SOAPElement) ( (org.apache.axis.message.SOAPBody) message ).getChildElements( )
.next( ) );
}
else
{
soapm.getSOAPBody( ).addChildElement( (SOAPElement) ( (org.apache.axis.message.SOAPBody) message ).getChildElements( )
.next( ) );
}
sconn.call( soapm, epr );
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
}