use of org.apache.axiom.soap.SOAPFactory in project wso2-axis2-transports by wso2.
the class XMLMessage method getMessageElement.
public OMElement getMessageElement() {
if (type == Type.POX) {
return payload;
} else {
SOAPFactory factory;
if (type == Type.SOAP11) {
factory = OMAbstractFactory.getSOAP11Factory();
} else {
factory = OMAbstractFactory.getSOAP12Factory();
}
SOAPEnvelope envelope = factory.getDefaultEnvelope();
envelope.getBody().addChild(payload);
return envelope;
}
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-axis2-transports by wso2.
the class DefaultSMSMessageBuilderImpl method createSoapEnvelope.
private SOAPEnvelope createSoapEnvelope(MessageContext messageContext, Map params) {
SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope inEnvlope = soapFactory.getDefaultEnvelope();
SOAPBody inBody = inEnvlope.getBody();
XmlSchemaElement xmlSchemaElement;
AxisOperation axisOperation = messageContext.getAxisOperation();
if (axisOperation != null) {
AxisMessage axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
xmlSchemaElement = axisMessage.getSchemaElement();
if (xmlSchemaElement == null) {
OMElement bodyFirstChild = soapFactory.createOMElement(messageContext.getAxisOperation().getName(), inBody);
createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, params);
} else {
// first get the target namespace from the schema and the wrapping element.
// create an OMElement out of those information. We are going to extract parameters from
// url, create OMElements and add them as children to this wrapping element.
String targetNamespace = xmlSchemaElement.getQName().getNamespaceURI();
QName bodyFirstChildQName;
if (targetNamespace != null && !"".equals(targetNamespace)) {
bodyFirstChildQName = new QName(targetNamespace, xmlSchemaElement.getName());
} else {
bodyFirstChildQName = new QName(xmlSchemaElement.getName());
}
OMElement bodyFirstChild = soapFactory.createOMElement(bodyFirstChildQName, inBody);
// Schema should adhere to the IRI style in this. So assume IRI style and dive in to
// schema
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
if (schemaType instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
XmlSchemaParticle particle = complexType.getParticle();
if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();
while (iterator.hasNext()) {
XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
QName qName = innerElement.getQName();
if (qName == null && innerElement.getSchemaTypeName().equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, params);
break;
}
long minOccurs = innerElement.getMinOccurs();
boolean nillable = innerElement.isNillable();
String name = qName != null ? qName.getLocalPart() : innerElement.getName();
Object value;
OMNamespace ns = (qName == null || qName.getNamespaceURI() == null || qName.getNamespaceURI().length() == 0) ? null : soapFactory.createOMNamespace(qName.getNamespaceURI(), null);
// FIXME changed
if ((value = params.get(name)) != null) {
addRequestParameter(soapFactory, bodyFirstChild, ns, name, value);
minOccurs--;
}
if (minOccurs > 0) {
if (nillable) {
OMNamespace xsi = soapFactory.createOMNamespace(Constants.URI_DEFAULT_SCHEMA_XSI, Constants.NS_PREFIX_SCHEMA_XSI);
OMAttribute omAttribute = soapFactory.createOMAttribute("nil", xsi, "true");
soapFactory.createOMElement(name, ns, bodyFirstChild).addAttribute(omAttribute);
} else {
// throw new AxisFault("Required element " + qName +
// " defined in the schema can not be" +
// " found in the request");
}
}
}
}
}
}
}
return inEnvlope;
}
use of org.apache.axiom.soap.SOAPFactory in project webservices-axiom by apache.
the class OMXMLBuilderFactory method createSOAPModelBuilder.
/**
* Create an MTOM aware model builder from the provided {@link MultipartBody} object using a
* particular Axiom implementation. The method will determine the SOAP version based on the
* content type information from the {@link MultipartBody} object. It will configure the
* underlying parser as specified by {@link StAXParserConfiguration#SOAP}.
*
* @param metaFactory
* the meta factory for the Axiom implementation to use
* @param message
* the MIME message
* @return the builder
* @throws OMException
* if an error occurs while processing the content type information from the
* {@link MultipartBody} object
*/
public static SOAPModelBuilder createSOAPModelBuilder(OMMetaFactory metaFactory, MultipartBody message) {
String type = message.getRootPart().getContentType().getParameter("type");
SOAPFactory soapFactory;
if ("text/xml".equalsIgnoreCase(type)) {
soapFactory = metaFactory.getSOAP11Factory();
} else if ("application/soap+xml".equalsIgnoreCase(type)) {
soapFactory = metaFactory.getSOAP12Factory();
} else {
throw new OMException("Unable to determine SOAP version");
}
SOAPModelBuilder builder = ((OMMetaFactorySPI) metaFactory).createSOAPModelBuilder(message);
if (builder.getSOAPMessage().getOMFactory() != soapFactory) {
throw new SOAPProcessingException("Invalid SOAP namespace URI. " + "Expected " + soapFactory.getSoapVersionURI(), SOAP12Constants.FAULT_CODE_SENDER);
}
return builder;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class IterateWithMultipleElementsTestCase method createRequestPayload.
private OMElement createRequestPayload() {
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
OMElement payload = fac.createOMElement("getQuotes", omNs);
for (int i = 0; i < 3; i++) {
OMElement method = fac.createOMElement("getQuote", omNs);
OMElement request = fac.createOMElement("request", omNs);
OMElement symbol = fac.createOMElement("symbol", omNs);
symbol.addChild(fac.createOMText(request, "WSO2"));
request.addChild(symbol);
method.addChild(request);
payload.addChild(method);
}
for (int i = 0; i < 3; i++) {
OMElement method = fac.createOMElement("dummy", omNs);
OMElement request = fac.createOMElement("request", omNs);
OMElement symbol = fac.createOMElement("symbol", omNs);
symbol.addChild(fac.createOMText(request, "WSO2"));
request.addChild(symbol);
method.addChild(request);
payload.addChild(method);
}
return payload;
}
use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.
the class MTOMSwASampleClient method sendUsingSWA.
public SampleClientResult sendUsingSWA(String fileName, String targetEPR) {
clientResult = new SampleClientResult();
try {
Options options = new Options();
options.setTo(new EndpointReference(targetEPR));
options.setAction("urn:uploadFileUsingSwA");
options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(configuration.getClientRepo(), configuration.getAxis2Xml());
ServiceClient sender = new ServiceClient(configContext, null);
sender.setOptions(options);
OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);
MessageContext mc = new MessageContext();
log.info("Sending file : " + fileName + " as SwA");
FileDataSource fileDataSource = new FileDataSource(new File(fileName));
DataHandler dataHandler = new DataHandler(fileDataSource);
String attachmentID = mc.addAttachment(dataHandler);
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope env = factory.getDefaultEnvelope();
OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
OMElement request = factory.createOMElement("request", ns);
OMElement imageId = factory.createOMElement("imageId", ns);
imageId.setText(attachmentID);
request.addChild(imageId);
payload.addChild(request);
env.getBody().addChild(payload);
mc.setEnvelope(env);
mepClient.addMessageContext(mc);
mepClient.execute(true);
MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
SOAPBody body = response.getEnvelope().getBody();
String imageContentId = body.getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")).getFirstChildWithName(new QName("http://services.samples", "response")).getFirstChildWithName(new QName("http://services.samples", "imageId")).getText();
Attachments attachment = response.getAttachmentMap();
dataHandler = attachment.getDataHandler(imageContentId);
File tempFile = File.createTempFile("swa-", ".gif");
FileOutputStream fos = new FileOutputStream(tempFile);
dataHandler.writeTo(fos);
fos.flush();
fos.close();
log.info("Saved response to file : " + tempFile.getAbsolutePath());
clientResult.incrementResponseCount();
} catch (Exception e) {
log.error("Error invoking service", e);
clientResult.setException(e);
}
return clientResult;
}
Aggregations