use of javax.xml.soap.SOAPEnvelope in project pentaho-platform by pentaho.
the class XMLABaseComponent method executeQuery.
/**
* Execute query
*
* @param query - MDX to be executed
* @param catalog
* @param handler Callback handler
* @throws XMLAException
*/
public boolean executeQuery(final String query, final String catalog) throws XMLAException {
Object[][] columnHeaders = null;
Object[][] rowHeaders = null;
Object[][] data = null;
int columnCount = 0;
int rowCount = 0;
SOAPConnection connection = null;
SOAPMessage reply = null;
try {
connection = scf.createConnection();
SOAPMessage msg = mf.createMessage();
MimeHeaders mh = msg.getMimeHeaders();
// $NON-NLS-1$
mh.setHeader("SOAPAction", XMLABaseComponent.EXECUTE_ACTION);
SOAPPart soapPart = msg.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);
SOAPBody body = envelope.getBody();
// $NON-NLS-1$//$NON-NLS-2$
Name nEx = envelope.createName("Execute", "", XMLABaseComponent.XMLA_URI);
SOAPElement eEx = body.addChildElement(nEx);
eEx.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);
// add the parameters
// COMMAND parameter
// <Command>
// <Statement>select [Measures].members on Columns from
// Sales</Statement>
// </Command>
// $NON-NLS-1$ //$NON-NLS-2$
Name nCom = envelope.createName("Command", "", XMLABaseComponent.XMLA_URI);
SOAPElement eCommand = eEx.addChildElement(nCom);
// $NON-NLS-1$ //$NON-NLS-2$
Name nSta = envelope.createName("Statement", "", XMLABaseComponent.XMLA_URI);
SOAPElement eStatement = eCommand.addChildElement(nSta);
eStatement.addTextNode(query);
// <Properties>
// <PropertyList>
// <DataSourceInfo>Provider=MSOLAP;Data
// Source=local</DataSourceInfo>
// <Catalog>Foodmart 2000</Catalog>
// <Format>Multidimensional</Format>
// <AxisFormat>TupleFormat</AxisFormat> oder "ClusterFormat"
// </PropertyList>
// </Properties>
Map paraList = new HashMap();
// $NON-NLS-1$
paraList.put("DataSourceInfo", dataSource);
// $NON-NLS-1$
paraList.put("Catalog", catalog);
// $NON-NLS-1$ //$NON-NLS-2$
paraList.put("Format", "Multidimensional");
// $NON-NLS-1$ //$NON-NLS-2$
paraList.put("AxisFormat", "TupleFormat");
// $NON-NLS-1$ //$NON-NLS-2$
addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
msg.saveChanges();
// $NON-NLS-1$
debug("Request for Execute");
logSoapMsg(msg);
// run the call
reply = connection.call(msg, url);
// $NON-NLS-1$
debug("Reply from Execute");
logSoapMsg(reply);
// error check
errorCheck(reply);
// process the reply
SOAPElement eRoot = findExecRoot(reply);
// for each axis, get the positions (tuples)
// $NON-NLS-1$ //$NON-NLS-2$
Name name = envelope.createName("Axes", "", XMLABaseComponent.MDD_URI);
SOAPElement eAxes = selectSingleNode(eRoot, name);
if (eAxes == null) {
// $NON-NLS-1$
throw new XMLAException("Excecute result has no Axes element");
}
// $NON-NLS-1$ //$NON-NLS-2$
name = envelope.createName("Axis", "", XMLABaseComponent.MDD_URI);
Iterator itAxis = eAxes.getChildElements(name);
AxisLoop: for (int iOrdinal = 0; itAxis.hasNext(); ) {
SOAPElement eAxis = (SOAPElement) itAxis.next();
// $NON-NLS-1$
name = envelope.createName("name");
String axisName = eAxis.getAttributeValue(name);
int axisOrdinal;
if (axisName.equals("SlicerAxis")) {
// $NON-NLS-1$
continue;
} else {
axisOrdinal = iOrdinal++;
}
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("Tuples", "", XMLABaseComponent.MDD_URI);
SOAPElement eTuples = selectSingleNode(eAxis, name);
if (eTuples == null) {
// what else?
continue AxisLoop;
}
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("Tuple", "", XMLABaseComponent.MDD_URI);
Iterator itTuple = eTuples.getChildElements(name);
// loop over tuples
int positionOrdinal = 0;
while (itTuple.hasNext()) {
// TupleLoop
SOAPElement eTuple = (SOAPElement) itTuple.next();
if ((axisOrdinal == XMLABaseComponent.AXIS_COLUMNS) && (columnHeaders == null)) {
// $NON-NLS-1$
columnCount = getChildCount(envelope, eTuples, "Tuple");
// $NON-NLS-1$
columnHeaders = new Object[getChildCount(envelope, eTuple, "Member")][columnCount];
} else if ((axisOrdinal == XMLABaseComponent.AXIS_ROWS) && (rowHeaders == null)) {
// $NON-NLS-1$
rowCount = getChildCount(envelope, eTuples, "Tuple");
// $NON-NLS-1$
rowHeaders = new Object[rowCount][getChildCount(envelope, eTuple, "Member")];
}
int index = 0;
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("Member", "", XMLABaseComponent.MDD_URI);
Iterator itMember = eTuple.getChildElements(name);
while (itMember.hasNext()) {
// MemberLoop
SOAPElement eMem = (SOAPElement) itMember.next();
// loop over children nodes
String caption = null;
Iterator it = eMem.getChildElements();
InnerLoop: while (it.hasNext()) {
Node n = (Node) it.next();
if (!(n instanceof SOAPElement)) {
continue InnerLoop;
}
SOAPElement el = (SOAPElement) n;
String enam = el.getElementName().getLocalName();
if (enam.equals("Caption")) {
// $NON-NLS-1$
caption = el.getValue();
}
}
if (axisOrdinal == XMLABaseComponent.AXIS_COLUMNS) {
columnHeaders[index][positionOrdinal] = caption;
} else if (axisOrdinal == XMLABaseComponent.AXIS_ROWS) {
rowHeaders[positionOrdinal][index] = caption;
}
++index;
}
// MemberLoop
++positionOrdinal;
}
// TupleLoop
}
// AxisLoop
data = new Object[rowCount][columnCount];
// loop over cells in result set
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("CellData", "", XMLABaseComponent.MDD_URI);
SOAPElement eCellData = selectSingleNode(eRoot, name);
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("Cell", "", XMLABaseComponent.MDD_URI);
Iterator itSoapCell = eCellData.getChildElements(name);
while (itSoapCell.hasNext()) {
// CellLoop
SOAPElement eCell = (SOAPElement) itSoapCell.next();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
name = envelope.createName("CellOrdinal", "", "");
String cellOrdinal = eCell.getAttributeValue(name);
int ordinal = Integer.parseInt(cellOrdinal);
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("Value", "", XMLABaseComponent.MDD_URI);
Object value = selectSingleNode(eCell, name).getValue();
int rowLoc = ordinal / columnCount;
int columnLoc = ordinal % columnCount;
data[rowLoc][columnLoc] = value;
}
// CellLoop
MemoryResultSet resultSet = new MemoryResultSet();
MemoryMetaData metaData = new MemoryMetaData(columnHeaders, rowHeaders);
resultSet.setMetaData(metaData);
for (Object[] element : data) {
resultSet.addRow(element);
}
rSet = resultSet;
if (resultSet != null) {
if (getResultOutputName() != null) {
setOutputValue(getResultOutputName(), resultSet);
}
return true;
}
return false;
} catch (SOAPException se) {
throw new XMLAException(se);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SOAPException e) {
// log and ignore
// $NON-NLS-1$
error("?", e);
}
}
}
}
use of javax.xml.soap.SOAPEnvelope in project cxf by apache.
the class TestSOAPHandler method handleMessage.
public boolean handleMessage(SOAPMessageContext ctx) {
try {
SOAPMessage msg = ctx.getMessage();
/*
* System.out.println("-----------soap---------");
* msg.writeTo(System.out);
* System.out.println("-----------soap---------");
*/
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPBody body = env.getBody();
Iterator<?> it = body.getChildElements();
while (it.hasNext()) {
Object elem = it.next();
if (elem instanceof SOAPElement) {
Iterator<?> it2 = ((SOAPElement) elem).getChildElements();
while (it2.hasNext()) {
Object elem2 = it2.next();
if (elem2 instanceof SOAPElement) {
String value = ((SOAPElement) elem2).getValue();
if (value != null && (value.indexOf("Milestone-0") >= 0 || value.indexOf("TestGreetMeResponseServerLogicalHandler") >= 0)) {
value = value + "ServerSOAPHandler";
((SOAPElement) elem2).setValue(value);
}
}
}
}
}
msg.saveChanges();
/*
* System.out.println("-----------soapaf---------");
* msg.writeTo(System.out);
* System.out.println("-----------soapaf---------");
*/
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
use of javax.xml.soap.SOAPEnvelope in project cxf by apache.
the class TestMtomProviderImpl method invoke.
public SOAPMessage invoke(final SOAPMessage request) {
try {
System.out.println("=== Received client request ===");
// create the SOAPMessage
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPBodyElement testResponse = body.addBodyElement(envelope.createName("testXopResponse", null, "http://cxf.apache.org/mime/types"));
SOAPElement name = testResponse.addChildElement("name", null, "http://cxf.apache.org/mime/types");
name.setTextContent("return detail + call detail");
SOAPElement attachinfo = testResponse.addChildElement("attachinfo", null, "http://cxf.apache.org/mime/types");
SOAPElement include = attachinfo.addChildElement("Include", "xop", "http://www.w3.org/2004/08/xop/include");
int fileSize = 0;
try (InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl")) {
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
}
int count = 50;
byte[] data = new byte[fileSize * count];
for (int x = 0; x < count; x++) {
this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
}
DataHandler dh = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
// create the image attachment
AttachmentPart attachment = message.createAttachmentPart(dh);
attachment.setContentId("mtom_xop.wsdl");
message.addAttachmentPart(attachment);
System.out.println("Adding attachment: " + attachment.getContentId() + ":" + attachment.getSize());
// add the reference to the image attachment
include.addAttribute(envelope.createName("href"), "cid:" + attachment.getContentId());
return message;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.
the class InstanceIdentifierHandler method handleMessageOutbound.
/**
* check for an arjuna context attached to the message context and, if found, install its identifier as the value
* of a soap message header element
* @param context
* @return
* @throws ProtocolException
*/
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
try {
ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(context);
if (arjunaContext != null) {
InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
// insert a header into the current message containing the instance identifier as a text element
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader == null) {
soapHeader = soapEnvelope.addHeader();
}
final SOAPHeaderElement headerElement = soapHeader.addHeaderElement(ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME);
headerElement.setValue(instanceIdentifier.getInstanceIdentifier());
headerElement.setMustUnderstand(true);
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.soap.SOAPEnvelope in project narayana by jbosstm.
the class JaxBaseHeaderContextProcessor method handleOutboundMessage.
/**
* Handle the request.
*
* @param soapMessage The current message context.
* @param mustUnderstand Value of MustUnderstand attribute.
* @return whether the message was handled
*/
public boolean handleOutboundMessage(final SOAPMessage soapMessage, boolean mustUnderstand) {
if (soapMessage == null) {
return true;
}
try {
/*
* There should either be an Atomic Transaction *or* a Business Activity
* associated with the thread.
*/
final TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
final com.arjuna.mw.wst11.BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager();
final Context atContext;
if (transactionManager != null) {
final TxContextImple txContext = (TxContextImple) transactionManager.currentTransaction();
atContext = (txContext == null ? null : txContext.context());
} else {
atContext = null;
}
final Context baContext;
if (businessActivityManager != null) {
final com.arjuna.mwlabs.wst11.ba.context.TxContextImple txContext = (com.arjuna.mwlabs.wst11.ba.context.TxContextImple) businessActivityManager.currentTransaction();
baContext = (txContext == null ? null : txContext.context());
} else {
baContext = null;
}
final CoordinationContextType coordinationContext;
if (baContext != null) {
coordinationContext = baContext.getCoordinationContext();
} else if (atContext != null) {
coordinationContext = atContext.getCoordinationContext();
} else {
coordinationContext = null;
}
if (coordinationContext != null) {
final SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = env.getHeader();
if (header == null) {
header = env.addHeader();
}
final Name name = env.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
final SOAPHeaderElement headerElement = header.addHeaderElement(name);
headerElement.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
headerElement.setMustUnderstand(mustUnderstand);
CoordinationContextHelper.serialise(coordinationContext, headerElement);
}
} catch (final Throwable th) {
wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_1("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.handleRequest()", th);
}
return true;
}
Aggregations