/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and others contributors as indicated
* by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* (C) 2005-2009
*/
package org.jboss.soa.esb.actions.soap.proxy;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Properties;
import org.jboss.internal.soa.esb.publish.ContractInfo;
import org.jboss.internal.soa.esb.publish.ContractProvider;
import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.helpers.ConfigTree;
/**
* SOAPProxy wsdl contract publisher.
*
* @author dward at jboss.org
*/
public class SOAPProxyWsdlContractPublisher extends AuthBASICWsdlContractPublisher implements ContractProvider
{
@Override
public String getWsdl(String wsdlAddress) throws IOException
{
String wsdl;
Properties properties = getActionProperties();
ConfigTree config = new ConfigTree("config");
for ( Object key : properties.keySet() )
{
String name = (String)key;
String value = properties.getProperty(name);
config.setAttribute(name, value);
}
SOAPProxyWsdlLoader loader = SOAPProxyWsdlLoader.newLoader(config);
InputStream is = null;
try
{
is = new BufferedInputStream( loader.getURL().openStream() );
wsdl = StreamUtils.readStreamString(is, "UTF-8");
}
finally
{
try { if (is != null) is.close(); } catch (Throwable t) {}
loader.cleanup();
}
return wsdl;
}
public void setContractProperties(Properties contractProperties)
{
setActionProperties(contractProperties);
}
public ContractInfo provideContract() throws IOException
{
return provideContract(null);
}
public ContractInfo provideContract(String endpointAddressOverride) throws IOException
{
ContractInfo contract;
if (endpointAddressOverride != null)
{
try
{
initializeTransformer();
}
catch (ConfigurationException ce)
{
throw new IOException( ce.getMessage() );
}
contract = getContractInfo( new EPR(URI.create(endpointAddressOverride)) );
}
else
{
contract = new ContractInfo( "text/xml", getWsdl(getWsdlAddress()) );
}
return contract;
}
}
|