use of javax.xml.soap.SOAPEnvelope in project cxf by apache.
the class NBProviderClientServerTest method encodeRequest.
private SOAPMessage encodeRequest(MessageFactory factory, String value) throws SOAPException {
SOAPMessage request = factory.createMessage();
SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
request.setProperty("soapaction", "");
if (value != null) {
request.getSOAPBody().addBodyElement(envelope.createName(value, "ns1", sayHi.getNamespaceURI()));
}
return request;
}
use of javax.xml.soap.SOAPEnvelope in project Payara by payara.
the class BaseAuthConfig method getName.
private static Name getName(SOAPMessage message) {
Name rvalue = null;
SOAPPart soap = message.getSOAPPart();
if (soap != null) {
try {
SOAPEnvelope envelope = soap.getEnvelope();
if (envelope != null) {
SOAPBody body = envelope.getBody();
if (body != null) {
Iterator it = body.getChildElements();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof SOAPElement) {
rvalue = ((SOAPElement) o).getElementName();
break;
}
}
}
}
} catch (SOAPException se) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "WSS: Unable to get SOAP envelope", se);
}
}
}
return rvalue;
}
use of javax.xml.soap.SOAPEnvelope in project jaffa-framework by jaffa-projects.
the class WebServiceInvoker method createSOAPMessage.
/**
* Generate SOAPMessage based on the input arguments.
* <p>
* For example:
* <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:j="http://product1.mirotechnologies.com/material/core/StockBalanceFinder">
* <SOAP-ENV:Header/>
* <SOAP-ENV:Body>
* <j:performInquiry>
* <arg0>
* <part><operator>Equals</operator><values>P1000</values></part>
* </arg0>
* </j:performInquiry>
* </SOAP-ENV:Body>
* </SOAP-ENV:Envelope>
* @param arguments the arguments for the WebService.
* @return a SOAPMessage.
* @throws SOAPException if any SOAP error occurs.
* @throws JAXBException if any XML (un)marshalling error occurs.
*/
protected SOAPMessage createSOAPMessage(Object... arguments) throws SOAPException, JAXBException {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPPart messagePart = message.getSOAPPart();
SOAPEnvelope envelope = messagePart.getEnvelope();
String tns = this.obtainTargetNamespace();
if (tns != null) {
envelope.addNamespaceDeclaration(CUSTOM_PREFIX, tns);
}
SOAPBody body = message.getSOAPBody();
SOAPElement operationElement = tns != null ? body.addBodyElement(envelope.createQName(getOperationName(), CUSTOM_PREFIX)) : body.addBodyElement(envelope.createName(getOperationName()));
// Add authentication
addAuthorization(message);
// An arg{i} node will be created for each argument
if (arguments != null) {
Annotation[][] parameterAnnotations = null;
for (Method m : getWebServiceClass().getMethods()) {
if (m.getName().equals(getOperationName()) && m.getAnnotation(WebMethod.class) != null) {
parameterAnnotations = m.getParameterAnnotations();
}
}
for (int i = 0; i < arguments.length; i++) {
Object argument = arguments[i];
Class argumentClass = argument.getClass();
String webParamName = null;
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation instanceof WebParam) {
WebParam webParam = (WebParam) annotation;
webParamName = webParam.name();
if (log.isDebugEnabled()) {
log.debug("webParamName :" + webParamName);
}
}
}
}
}
if (Collection.class.isAssignableFrom(argumentClass)) {
JAXBContext jc = null;
Marshaller marshaller = null;
List list = (List) argument;
for (Object arrayElement : list) {
if (jc == null) {
jc = JAXBHelper.obtainJAXBContext(arrayElement.getClass());
marshaller = jc.createMarshaller();
}
if (webParamName != null) {
marshaller.marshal(new JAXBElement(new QName(webParamName), arrayElement.getClass(), arrayElement), operationElement);
} else {
marshaller.marshal(new JAXBElement(new QName("arg0"), arrayElement.getClass(), arrayElement), operationElement);
}
}
} else if (argumentClass.isArray()) {
argumentClass = argumentClass.getComponentType();
JAXBContext jc = JAXBHelper.obtainJAXBContext(argumentClass);
Marshaller marshaller = jc.createMarshaller();
for (int j = 0, len = Array.getLength(argument); j < len; j++) {
Object arrayElement = Array.get(argument, j);
if (webParamName != null) {
marshaller.marshal(new JAXBElement(new QName(webParamName), argumentClass, arrayElement), operationElement);
} else {
marshaller.marshal(new JAXBElement(new QName("arg0"), argumentClass, arrayElement), operationElement);
}
}
} else {
JAXBContext jc = JAXBHelper.obtainJAXBContext(argumentClass);
Marshaller marshaller = jc.createMarshaller();
if (webParamName != null) {
marshaller.marshal(new JAXBElement(new QName(webParamName), argumentClass, argument), operationElement);
} else {
marshaller.marshal(new JAXBElement(new QName("arg0"), argumentClass, argument), operationElement);
}
}
}
}
// Save all changes to the Message
message.saveChanges();
if (log.isDebugEnabled()) {
log.debug("Created SOAPMessage: " + message);
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
message.writeTo(os);
log.debug("Contents of SOAPMessage: " + os.toString());
} catch (Exception e) {
// do nothing
}
}
return message;
}
use of javax.xml.soap.SOAPEnvelope in project pentaho-platform by pentaho.
the class XMLABaseComponent method discover.
/**
* discover
*
* @param request
* @param discoverUrl
* @param restrictions
* @param properties
* @param rh
* @throws XMLAException
*/
private void discover(final String request, final URL discoverUrl, final Map restrictions, final Map properties, final Rowhandler rh) throws XMLAException {
try {
SOAPConnection connection = scf.createConnection();
SOAPMessage msg = mf.createMessage();
MimeHeaders mh = msg.getMimeHeaders();
// $NON-NLS-1$ //$NON-NLS-2$
mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Discover\"");
SOAPPart soapPart = msg.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
// $NON-NLS-1$//$NON-NLS-2$
envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
// $NON-NLS-1$ //$NON-NLS-2$
envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
SOAPBody body = envelope.getBody();
// $NON-NLS-1$//$NON-NLS-2$
Name nDiscover = envelope.createName("Discover", "", XMLABaseComponent.XMLA_URI);
SOAPElement eDiscover = body.addChildElement(nDiscover);
eDiscover.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);
// $NON-NLS-1$//$NON-NLS-2$
Name nPara = envelope.createName("RequestType", "", XMLABaseComponent.XMLA_URI);
SOAPElement eRequestType = eDiscover.addChildElement(nPara);
eRequestType.addTextNode(request);
// add the parameters
if (restrictions != null) {
addParameterList(envelope, eDiscover, "Restrictions", "RestrictionList", // $NON-NLS-1$ //$NON-NLS-2$
restrictions);
}
// $NON-NLS-1$//$NON-NLS-2$
addParameterList(envelope, eDiscover, "Properties", "PropertyList", properties);
msg.saveChanges();
debug(// $NON-NLS-1$
Messages.getInstance().getString("XMLABaseComponent.DEBUG_0006_DISCOVER_REQUEST") + request);
logSoapMsg(msg);
// run the call
SOAPMessage reply = connection.call(msg, discoverUrl);
debug(// $NON-NLS-1$
Messages.getInstance().getString("XMLABaseComponent.DEBUG_0007_DISCOVER_RESPONSE") + request);
logSoapMsg(reply);
errorCheck(reply);
SOAPElement eRoot = findDiscoverRoot(reply);
// $NON-NLS-1$ //$NON-NLS-2$
Name nRow = envelope.createName("row", "", XMLABaseComponent.ROWS_URI);
Iterator itRow = eRoot.getChildElements(nRow);
while (itRow.hasNext()) {
// RowLoop
SOAPElement eRow = (SOAPElement) itRow.next();
rh.handleRow(eRow, envelope);
}
// RowLoop
connection.close();
} catch (UnsupportedOperationException e) {
throw new XMLAException(e);
} catch (SOAPException e) {
throw new XMLAException(e);
}
}
use of javax.xml.soap.SOAPEnvelope in project pentaho-platform by pentaho.
the class XMLABaseComponent method soapFault.
/**
* check SOAP reply for Error, return fault Code
*
* @param reply the message to check
* @param aReturn ArrayList containing faultcode,faultstring,faultactor
*/
private boolean soapFault(final SOAPMessage reply, final String[] faults) throws SOAPException {
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
if (!body.hasFault()) {
return false;
}
SOAPFault fault = body.getFault();
faults[0] = fault.getFaultCode();
faults[1] = fault.getFaultString();
faults[2] = fault.getFaultActor();
// probably not neccessary with Microsoft;
Detail detail = fault.getDetail();
if (detail == null) {
return true;
}
// $NON-NLS-1$
String detailMsg = "";
Iterator it = detail.getDetailEntries();
for (; it.hasNext(); ) {
DetailEntry det = (DetailEntry) it.next();
Iterator ita = det.getAllAttributes();
for (boolean cont = false; ita.hasNext(); cont = true) {
Name name = (Name) ita.next();
if (cont) {
// $NON-NLS-1$
detailMsg += "; ";
}
detailMsg += name.getLocalName();
// $NON-NLS-1$
detailMsg += " = ";
detailMsg += det.getAttributeValue(name);
}
}
faults[3] = detailMsg;
return true;
}
Aggregations