use of javax.xml.soap.SOAPEnvelope in project cxf by apache.
the class HandlerInvocationTest method testServerEndpointRemoteFault.
@Test
public void testServerEndpointRemoteFault() throws PingException {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleFault(LogicalMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
LogicalMessage msg = ctx.getMessage();
String payload = convertDOMToString(msg.getPayload());
assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
private String convertDOMToString(Source s) throws TransformerException {
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(s, streamResult);
return stringWriter.toString();
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleFault(SOAPMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
try {
handlerTest.pingWithArgs("servant throw SOAPFaultException");
fail("did not get expected Exception");
} catch (SOAPFaultException sfe) {
// expected
}
assertEquals(1, handler1.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleMessageInvoked());
assertEquals(1, soapHandler1.getHandleMessageInvoked());
assertEquals(1, soapHandler2.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleFaultInvoked());
assertEquals(1, handler1.getHandleFaultInvoked());
assertEquals(1, soapHandler1.getHandleFaultInvoked());
assertEquals(1, soapHandler2.getHandleFaultInvoked());
assertEquals(1, handler1.getCloseInvoked());
assertEquals(1, handler2.getCloseInvoked());
assertEquals(1, soapHandler1.getCloseInvoked());
assertEquals(1, soapHandler2.getCloseInvoked());
assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
use of javax.xml.soap.SOAPEnvelope in project coprhd-controller by CoprHD.
the class WinRMTarget method getSOAPFault.
protected SOAPFault getSOAPFault(String content) {
try {
Document doc = XmlUtils.parseXml(content);
SOAPEnvelope e = (SOAPEnvelope) SOAPFactory.newInstance().createElement(doc.getDocumentElement());
SOAPFault fault = e.getBody().getFault();
return fault;
} catch (Exception e) {
return null;
}
}
use of javax.xml.soap.SOAPEnvelope in project pentaho-platform by pentaho.
the class XMLABaseComponent method discoverDS.
/**
* retrieve data source properties
*
* @return Map of key/value strings
* @see DataSourceBrowser
*/
public Map discoverDS() throws XMLAException {
// Microsoft wants restrictions
HashMap rHash = new HashMap();
HashMap pHash = new HashMap();
// $NON-NLS-1$ //$NON-NLS-2$
pHash.put("Content", "Data");
final Map resultMap = new HashMap();
Rowhandler rh = new Rowhandler() {
public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {
/*
* <row><DataSourceName>SAP_BW</DataSourceName> <DataSourceDescription>SAP BW Release 3.0A XML f. Analysis
* Service</DataSourceDescription> <URL>http://155.56.49.46:83/SAP/BW/XML/SOAP/XMLA</URL>
* <DataSourceInfo>default</DataSourceInfo> <ProviderName>SAP BW</ProviderName> <ProviderType>MDP</ProviderType>
* <AuthenticationMode>Integrated</AuthenticationMode></row>
*/
Iterator it = eRow.getChildElements();
while (it.hasNext()) {
Object o = it.next();
if (!(o instanceof SOAPElement)) {
// bypass text nodes
continue;
}
SOAPElement e = (SOAPElement) o;
String name = e.getElementName().getLocalName();
String value = e.getValue();
resultMap.put(name, value);
}
}
};
// $NON-NLS-1$
discover("DISCOVER_DATASOURCES", url, rHash, pHash, rh);
debug(Messages.getInstance().getString("XMLABaseComponent.DEBUG_0005_DISCOVER_DATASOURCE_FOUND") + resultMap.size());
return resultMap;
}
use of javax.xml.soap.SOAPEnvelope in project pentaho-platform by pentaho.
the class XMLABaseComponent method findDiscoverRoot.
/**
* locate "root" in DisoverResponse
*/
private SOAPElement findDiscoverRoot(final SOAPMessage reply) throws SOAPException, XMLAException {
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
Name childName;
SOAPElement eResponse = null;
if (provider == 0) {
// unknown provider - recognize by prefix of DiscoverResponse
Iterator itBody = body.getChildElements();
while (itBody.hasNext()) {
Node n = (Node) itBody.next();
if (!(n instanceof SOAPElement)) {
continue;
}
Name name = ((SOAPElement) n).getElementName();
if (name.getLocalName().equals("DiscoverResponse")) {
// $NON-NLS-1$
eResponse = (SOAPElement) n;
provider = getProviderFromDiscoverResponse(envelope, eResponse);
break;
}
}
if (eResponse == null) {
throw new XMLAException(// $NON-NLS-1$
Messages.getInstance().getString("XMLABaseComponent.ERROR_0013_NO_DISCOVER_RESPONSE"));
}
} else {
if ((provider == XMLABaseComponent.PROVIDER_MICROSOFT) || (provider == XMLABaseComponent.PROVIDER_ESSBASE)) {
// Microsoft
// or
// Essbase
childName = // $NON-NLS-1$ //$NON-NLS-2$
envelope.createName("DiscoverResponse", "m", XMLABaseComponent.XMLA_URI);
} else if ((provider == XMLABaseComponent.PROVIDER_SAP) || (provider == XMLABaseComponent.PROVIDER_MONDRIAN)) {
// SAP
// or
// Mondrian
childName = // $NON-NLS-1$ //$NON-NLS-2$
envelope.createName("DiscoverResponse", "", XMLABaseComponent.XMLA_URI);
} else {
throw new IllegalArgumentException(Messages.getInstance().getString(// $NON-NLS-1$
"XMLABaseComponent.ERROR_0014_NO_PROVIDER_SPEC"));
}
eResponse = selectSingleNode(body, childName);
if (eResponse == null) {
throw new XMLAException(Messages.getInstance().getString(// $NON-NLS-1$
"XMLABaseComponent.ERROR_0015_NO_DISCOVER_RESPONSE_ELEMENT"));
}
}
SOAPElement eReturn = getDiscoverReturn(envelope, eResponse);
if (eReturn == null) {
throw new XMLAException(Messages.getInstance().getString(// $NON-NLS-1$
"XMLABaseComponent.ERROR_0016_NO_RESULT_RETURN_ELEMENT"));
}
SOAPElement eRoot = getDiscoverRoot(envelope, eReturn);
if (eRoot == null) {
throw new XMLAException(// $NON-NLS-1$
Messages.getInstance().getString("XMLABaseComponent.ERROR_0017_NO_RESULT_ROOT_ELEMENT"));
}
return eRoot;
}
use of javax.xml.soap.SOAPEnvelope in project pentaho-platform by pentaho.
the class XMLABaseComponent method findExecRoot.
/**
* locate "root" in ExecuteResponse
*/
private SOAPElement findExecRoot(final SOAPMessage reply) throws SOAPException, XMLAException {
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
Name name;
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("ExecuteResponse", "m", XMLABaseComponent.XMLA_URI);
SOAPElement eResponse = selectSingleNode(body, name);
if (eResponse == null) {
throw new XMLAException(Messages.getInstance().getString(// $NON-NLS-1$
"XMLABaseComponent.ERROR_0011_NO_EXECUTE_RESPONSE_ELEMENT"));
}
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("return", "m", XMLABaseComponent.XMLA_URI);
SOAPElement eReturn = selectSingleNode(eResponse, name);
// $NON-NLS-1$//$NON-NLS-2$
name = envelope.createName("root", "", XMLABaseComponent.MDD_URI);
SOAPElement eRoot = selectSingleNode(eReturn, name);
if (eRoot == null) {
throw new XMLAException(Messages.getInstance().getString("XMLABaseComponent.ERROR_0012_NO_RESPONSE_ROOT_ELEMENT"));
}
// $NON-NLS-1$
return eRoot;
}
Aggregations