Hi all,

Here is the revised attachment of HttpClient code. But I am getting the same
error. Any help is greatly appreciated.

Regards,
Chamith

On Wed, Apr 22, 2009 at 11:27 PM, buddhika chamith
<[email protected]>wrote:

> Hi all,
>
> A JIRA for the same was raised under ODE-590 by me. Since this has been
> resolved in ODE-591 it was closed.
>
> (
> https://issues.apache.org/jira/browse/ODE-590?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> )
>
> Regards,
> Chamith
>
>
> On Wed, Apr 22, 2009 at 12:49 AM, Alexis Midon <[email protected]> wrote:
>
>> fixed by ODE-591.
>> thanks for the catch
>>
>> On Mon, Apr 20, 2009 at 2:19 PM, Alex Boisvert <[email protected]>
>> wrote:
>>
>> > On Mon, Apr 20, 2009 at 12:23 PM, buddhika chamith
>> > <[email protected]>wrote:
>> >
>> > > This code is vulnerable if a carriage return is present after the
>> <name>
>> > > tag before <package> tag. AFAIK this happens because of the behaviour
>> of
>> > > Axiom. Axiom creates an OMText node for the carriage return. So when
>> > > getNextOMSibling() is called instead of <package> element OMText is
>> > > selected. But since the OMText cannot be cast to OMElement a
>> > > ClassCastException occurs. This can be avoided by obtaining zipart
>> > OMElement
>> > > with a call to getChild() or any related method which returns an
>> > OMElement
>> > > reference. I can provide a patch for this if necessary.
>> >
>> >
>> > Good catch!  Yes, a patch would be much appreciated.
>> >
>> > alex
>> >
>>
>
>
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

public class ODERequestEntity implements RequestEntity {
	
	private static final String ODE_ELEMENT_DEPLOY="deploy";
	private static final String ODE_ELEMENT_ZIPNAME="name";
	private static final String ODE_ELEMENT_PACKAGE="package";
	private static final String ODE_ELEMENT_ZIP="zip"; 
	private static final String ODE_ELEMENT_PACKAGENAME="packageName";
	
	private static final String NS_SOAP_ENCODING= "http://schemas.xmlsoap.org/soap/encoding/";;
	private static final String NS_DEPLOY_SERVICE="http://www.apache.org/ode/deployapi";;
	private static final String NS_XML_MIME="http://www.w3.org/2005/05/xmlmime";;
	private static final String NS_PMAPI="http://www.apache.org/ode/pmapi";;

	private static final String CONTENT_TYPE_STRING="contentType";
	private static final String ZIP_CONTENT_TYPE="application/zip";
	
	private String fContent;
	
	public ODERequestEntity(File file)  throws IOException, SOAPException {
		prepareContent(file);
	}

	//implemented method
	public long getContentLength(){
		return fContent.length();
	}

	//implemented method
	public String getContentType() {
		return BPELUnitConstants.TEXT_XML_CONTENT_TYPE;
	}

	//implemented method
	public boolean isRepeatable() {
		return true;
	}

	//implemented method
	public void writeRequest(OutputStream out) throws IOException {
		out.write(fContent.toString().getBytes());
		out.flush();
	}
	
	private void prepareContent(File file) throws IOException,SOAPException{
			
		MessageFactory mFactory= MessageFactory.newInstance();
		SOAPMessage message= mFactory.createMessage();
		SOAPPart part=message.getSOAPPart();
		SOAPEnvelope envelope=part.getEnvelope();
		SOAPBody body= envelope.getBody();
			
		SOAPElement xmlDeploy= body.addChildElement(ODE_ELEMENT_DEPLOY);
		SOAPElement xmlZipFilename= xmlDeploy.addChildElement(ODE_ELEMENT_ZIPNAME);
		xmlZipFilename.setTextContent(FilenameUtils.getName(file.toString()).split("\\.")[0]);
			
		SOAPElement xmlZipContent=xmlDeploy.addChildElement(ODE_ELEMENT_PACKAGE);
		SOAPElement xmlBase64ZipFile=xmlZipContent.addChildElement(ODE_ELEMENT_ZIP);
			
		xmlBase64ZipFile.addAttribute(new QName(NS_XML_MIME,CONTENT_TYPE_STRING), ZIP_CONTENT_TYPE);
			
		StringBuilder content= new StringBuilder();
		byte[] arr= FileUtils.readFileToByteArray(file);
		byte[] encoded= Base64.encodeBase64Chunked(arr);
		for (int i= 0; i < encoded.length; i++) {
			content.append((char) encoded[i]);
		}
			
		xmlBase64ZipFile.setTextContent(content.toString());
			
		ByteArrayOutputStream b= new ByteArrayOutputStream();
		message.writeTo(b);
		fContent= b.toString();

	}

	public static void main(String args[]) throws Exception{
		File uploadingFile=new File("HelloProcess.zip");
		HttpClient client = new HttpClient();
		PostMethod method = new PostMethod(fDeploymentAdminServiceURL);

		RequestEntity re= new ODERequestEntity(uploadingFile);
		method.setRequestEntity(re);

		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
				new DefaultHttpMethodRetryHandler(1, false));

		int statusCode = client.executeMethod(method);
	}
}

Reply via email to