/*=============================================================================*
* 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.pubsub;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.pubsub.emitter.EmitterTask;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
/**
* DOCUMENT_ME
*
* @version $Revision: 1.8 $
* @author $author$
*/
public class Publisher
implements org.apache.ws.pubsub.Publisher
{
private String m_url = "http://localhost:7070/axis/services/NotificationPort";
/**
* Creates a new {@link Publisher} object.
*
* @param url DOCUMENT_ME
*/
public Publisher( String url )
{
m_url = url;
}
/**
* DOCUMENT_ME
*
* @param msg DOCUMENT_ME
* @param t DOCUMENT_ME
*/
public void publish( Object msg,
org.apache.ws.notification.topics.Topic t )
{
try
{
publish( m_url, (String) msg );
}
catch ( Exception e )
{
e.printStackTrace( );
}
}
private static SOAPMessage buildMessage( EndpointReference epr,
Document dom )
throws Exception
{
//build soap mesage
SOAPMessage soapMsg = MessageFactory.newInstance( ).createMessage( );
SOAPHeader soapHeader = soapMsg.getSOAPHeader( );
//TODO !!! set the wsa headers
SOAPBody soapBody = soapMsg.getSOAPBody( );
//TODO doubt this will work...but lets give it a try using a Document type "notifyDoc"
soapBody.addDocument( dom );
return soapMsg;
}
private static void publish( String url,
String s )
throws Exception
{
DocumentBuilder builder = DocumentBuilderFactory.newInstance( ).newDocumentBuilder( );
Document dom = builder.parse( new java.io.ByteArrayInputStream( s.getBytes( ) ) );
publish( url,
buildMessage( null, dom ) );
}
private static void publish( String url,
SOAPMessage soapMsg )
throws Exception
{
EmitterTask et = EmitterTask.createEmitterTask( soapMsg,
new java.net.URL( url ) );
et.run( );
}
/*
* This Method publishes for a special Subscription, cause it has a
* ResourcePropertie in his EPR
*/
private static void publish( EndpointReference epr,
String s )
throws Exception
{
DocumentBuilder builder = DocumentBuilderFactory.newInstance( ).newDocumentBuilder( );
Document dom = builder.parse( new java.io.ByteArrayInputStream( s.getBytes( ) ) );
publish( epr, dom );
}
private static void publish( EndpointReference epr,
Document dom )
throws Exception
{
publish( epr.getAddress( ).toString( ),
buildMessage( epr, dom ) );
}
//TODO setupaddressingHeaders
/*
private static AddressingHeaders setUpAddressing() throws Exception {
AddressingHeaders headers = new AddressingHeaders();
Action a = new Action(new URI("urn:action2"));
headers.setAction(a);
EndpointReference epr = new EndpointReference("http://www.apache.org");
headers.setFaultTo(epr);
return headers;
}
*/
}