WSO2 ESB v3.0.1
Java 1.6
Generar y importar un .jar
__________________________
Generate and import a .jar
import java.io.InputStream;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.builder.Builder;
import org.apache.axis2.context.MessageContext;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
/**
* @author Juan Carlos Hdez.
* UrlencodedBuilder: adaptador de peticiones con formato application/x-www-form-urlencoded al ESB de WSO2
* formatted requests adapter application / x-www-form-urlencoded the WSO2 ESB
*
*/
public class UrlencodedBuilder implements Builder{
/**
* sgapValidator
*/
private static final String tag = "_urlencoded";
/**
* @return Returns the document element.
*/
public OMElement processDocument(InputStream inputStream, String contentType,
MessageContext messageContext)
throws AxisFault {
SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
if (inputStream != null) {
try {
java.io.Reader buff = new java.io.BufferedReader(new java.io.InputStreamReader(inputStream, "UTF-8"));
java.io.Writer writer = new java.io.StringWriter();
int n;
char[] buffer = new char[1024];
while ((n = buff.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
String bodyReq=writer.toString();
soapEnvelope=genSOAPEnvelope(soapFactory,bodyReq);
messageContext.setProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE,"application/xml");
} catch (Exception e) {
//error("UrlencodedBuilder Error generating body:"+e);
}
}
else
{
//error("UrlencodedBuilder InputStreamRequest null");
}
return soapEnvelope;
}
/**
* Funcion interna para generar el body del envelope como consideremos oportuno
* Internal function to generate the body of the envelope as it sees fit
*
* @param soapFactory
* @param messageContext
* @param bodyReq
* @return
*/
private SOAPEnvelope genSOAPEnvelope(SOAPFactory soapFactory,String bodyReq)
{
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
SOAPBody body = soapEnvelope.getBody();
OMElement bodyFirstChild = soapFactory.createOMElement(new QName(tag), body);
bodyFirstChild.setText(bodyReq);
return soapEnvelope;
}
}