use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.
the class FaultTester method testFault3.
public void testFault3() throws Exception {
QName sc1 = new QName("http://example.org/1", "one");
QName sc2 = new QName("http://example.org/2", "two");
QName sc3 = new QName("http://example.org/3", "three");
String faultString = "INTERNAL_ERROR";
QName detailMsg = new QName("DetailMessage");
String detailValue = "This method is not implemented";
SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPFault fault = fac.createFault(faultString, SOAPConstants.SOAP_RECEIVER_FAULT);
fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
fault.appendFaultSubcode(sc1);
fault.appendFaultSubcode(sc2);
fault.appendFaultSubcode(sc3);
fault.addDetail().addDetailEntry(detailMsg).setTextContent(detailValue);
Message fm = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, fault);
// get the SOAPFault back
SOAPFaultBuilder sfb = SOAPFaultBuilder.create(fm);
Throwable ex = sfb.createException(null);
assertTrue(ex instanceof SOAPFaultException);
SOAPFaultException sfe = (SOAPFaultException) ex;
SOAPFault sf = sfe.getFault();
assertTrue(sf.getFaultString().equals(faultString));
// compare detail
Detail detail = sfe.getFault().getDetail();
assertTrue(detail != null);
Iterator iter = detail.getDetailEntries();
assertTrue(iter.hasNext());
DetailEntry n = (DetailEntry) iter.next();
assertTrue(n.getNamespaceURI().equals(detailMsg.getNamespaceURI()) && n.getLocalName().equals(detailMsg.getLocalPart()));
n.getTextContent().equals(detailValue);
// compare code and subcodes
Iterator scs = sf.getFaultSubcodes();
assertTrue(scs.hasNext());
QName sc = (QName) scs.next();
assertTrue(sc.equals(sc1));
assertTrue(scs.hasNext());
sc = (QName) scs.next();
assertTrue(sc.equals(sc2));
assertTrue(scs.hasNext());
sc = (QName) scs.next();
assertTrue(sc.equals(sc3));
}
use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.
the class StubHandler method readResponse.
public JavaCallInfo readResponse(Packet p, JavaCallInfo call) throws Throwable {
Message msg = p.getMessage();
if (msg.isFault()) {
SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
Throwable t = faultBuilder.createException(checkedExceptions);
call.setException(t);
throw t;
} else {
initArgs(call.getParameters());
Object ret = responseBuilder.readResponse(msg, call.getParameters());
call.setReturnValue(ret);
return call;
}
}
use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.
the class DispatchImpl method doInvoke.
/**
* Synchronously invokes a service.
*
* See {@link #process(Packet, RequestContext, ResponseContextReceiver)} on
* why it takes a {@link RequestContext} and {@link ResponseContextReceiver} as a parameter.
*/
public final T doInvoke(T in, RequestContext rc, ResponseContextReceiver receiver) {
Packet response = null;
try {
try {
checkNullAllowed(in, rc, binding, mode);
Packet message = createPacket(in);
message.setState(Packet.State.ClientRequest);
resolveEndpointAddress(message, rc);
setProperties(message, true);
response = process(message, rc, receiver);
Message msg = response.getMessage();
// REVIEW: eliminate allowFaultResponseMsg, but make that behavior default for MessageDispatch, PacketDispatch
if (msg != null && msg.isFault() && !allowFaultResponseMsg) {
SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
// it will get back to us is a protocol exception
throw (SOAPFaultException) faultBuilder.createException(null);
}
} catch (JAXBException e) {
// TODO: i18nify
throw new DeserializationException(DispatchMessages.INVALID_RESPONSE_DESERIALIZATION(), e);
} catch (WebServiceException e) {
// it could be a WebServiceException or a ProtocolException
throw e;
} catch (Throwable e) {
// WebServiceException
throw new WebServiceException(e);
}
return toReturnValue(response);
} finally {
// REVIEW: Move to AsyncTransportProvider
if (response != null && response.transportBackChannel != null)
response.transportBackChannel.close();
}
}
use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.
the class FaultTester method testFault1.
public void testFault1() throws Throwable {
SOAPMessage msg = SOAPVersion.SOAP_11.saajMessageFactory.createMessage(null, new ByteArrayInputStream(fault1.getBytes()));
SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
Throwable t = sfb.createException(null);
assertTrue(t instanceof SOAPFaultException);
}
use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.
the class FaultTester method testFault2.
public void testFault2() throws Throwable {
InputStream is = this.getClass().getClassLoader().getResourceAsStream("fault2.xml");
FileOutputStream fos = new FileOutputStream("fault2.xml");
fos.write(fault2.trim().getBytes());
fos.close();
SOAPMessage msg = SOAPVersion.SOAP_12.saajMessageFactory.createMessage(null, new ByteArrayInputStream(fault2.trim().getBytes()));
SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
Throwable t = sfb.createException(null);
assertTrue(t instanceof SOAPFaultException);
SOAPFaultException sfe = (SOAPFaultException) t;
Detail detail = sfe.getFault().getDetail();
assertTrue(detail != null);
Iterator iter = detail.getDetailEntries();
// there should be two detail entries
assertTrue(iter.hasNext());
DetailEntry de = (DetailEntry) iter.next();
assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail")));
Node n = de.getFirstChild();
assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues"));
assertTrue(iter.hasNext());
de = (DetailEntry) iter.next();
assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail2")));
n = de.getFirstChild();
assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues1"));
}
Aggregations