All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.confluence.macros.AbstractHttpRetrievalMacro Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version

/**
 * Copyright (c) 2009 Pyxis Technologies inc.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA,
 * or see the FSF site: http://www.fsf.org.
 *
 * @author oaouattara
 * @version $Id: $Id
 */
package com.greenpepper.confluence.macros;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Vector;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcClient;
import org.apache.xmlrpc.XmlRpcException;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.macro.Macro.BodyType;
import com.atlassian.confluence.macro.Macro.OutputType;
import com.atlassian.confluence.renderer.v2.macros.BaseHttpRetrievalMacro;
import com.atlassian.confluence.util.http.HttpResponse;
import com.atlassian.renderer.RenderContext;
import com.atlassian.renderer.v2.macro.MacroException;
import com.greenpepper.server.GreenPepperServerErrorKey;
import com.greenpepper.server.GreenPepperServerException;
import com.greenpepper.server.domain.Repository;
import com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller;
import com.greenpepper.server.rpc.xmlrpc.XmlRpcMethodName;
import com.greenpepper.util.CollectionUtil;
import com.greenpepper.util.StringUtil;
public abstract class AbstractHttpRetrievalMacro extends BaseHttpRetrievalMacro implements Macro
{
	private final Logger log = Logger.getLogger(AbstractHttpRetrievalMacro.class);

	/**
	 * 

Constructor for AbstractHttpRetrievalMacro.

*/ public AbstractHttpRetrievalMacro() { super(); } // Macros v4 /** *

getBodyType.

* * @return a {@link com.atlassian.confluence.macro.Macro.BodyType} object. */ public BodyType getBodyType() { return BodyType.NONE; } /** *

getOutputType.

* * @return a {@link com.atlassian.confluence.macro.Macro.OutputType} object. */ public OutputType getOutputType() { return OutputType.BLOCK; } /** {@inheritDoc} */ public String execute(Map parameters, String body, ConversionContext context) throws MacroExecutionException { try { return execute(parameters, body, context.getPageContext()); } catch (MacroException e) { throw new MacroExecutionException(e); } } // End Macros V4 /** {@inheritDoc} */ public String successfulResponse(Map parameters, RenderContext context, String url, HttpResponse response) throws MacroException { // InputStream is = null; // try // { // is = response.getResponse(); // return IOUtils.toString(is); return "BYOB"; // return "
Begin Info
GreenPepper Bulk References management for ALL Versions of Project Bank (For demo)
Run all Issues References | View all Issues results | Hide all Issues results Run all Issues References | View all Issues results | Hide all Issues results
 
End Info
"; // } // catch (IOException ex) // { // throw new MacroException(ex); // } // finally // { // IOUtils.closeQuietly(is); // } } /** *

getParameter.

* * @param parameters a {@link java.util.Map} object. * @param name a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ protected String getParameter(Map parameters, String name) { String parameter = (String)parameters.get(name); return StringUtil.isBlank(parameter) ? null : parameter.trim(); } /** *

getRepository.

* * @param url a {@link java.lang.String} object. * @param handler a {@link java.lang.String} object. * @param jiraUid a {@link java.lang.String} object. * @return a {@link com.greenpepper.server.domain.Repository} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ @SuppressWarnings("unchecked") protected Repository getRepository(String url, String handler, String jiraUid) throws GreenPepperServerException { Vector response; try { Repository repository = Repository.newInstance(jiraUid); Vector params = CollectionUtil.toVector(repository.marshallize()); XmlRpcClient xmlrpc = new XmlRpcClient(url + "/rpc/xmlrpc"); String cmdLine = new StringBuffer(handler).append(".").append(XmlRpcMethodName.getRegisteredRepository).toString(); response = (Vector)xmlrpc.execute(cmdLine, params); } catch (XmlRpcException e) { log.error(e.getMessage(), e); throw new GreenPepperServerException(GreenPepperServerErrorKey.CALL_FAILED, e.getMessage()); } catch (IOException e) { log.error(e.getMessage(), e); throw new GreenPepperServerException(GreenPepperServerErrorKey.CONFIGURATION_ERROR, e.getMessage()); } XmlRpcDataMarshaller.checkForErrors(response); return XmlRpcDataMarshaller.toRepository(response); } }