use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class WebFaultOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Fault f = (Fault) message.getContent(Exception.class);
if (f == null) {
return;
}
try {
Throwable thr = f.getCause();
SOAPFaultException sf = null;
if (thr instanceof SOAPFaultException) {
sf = (SOAPFaultException) thr;
} else if (thr.getCause() instanceof SOAPFaultException) {
sf = (SOAPFaultException) thr.getCause();
}
if (sf != null) {
SoapVersion soapVersion = (SoapVersion) message.get(SoapVersion.class.getName());
if (soapVersion != null && soapVersion.getVersion() != 1.1) {
if (f instanceof SoapFault) {
for (Iterator<QName> it = CastUtils.cast(sf.getFault().getFaultSubcodes()); it.hasNext(); ) {
((SoapFault) f).addSubCode(it.next());
}
}
if (sf.getFault().getFaultReasonLocales().hasNext()) {
Locale lang = (Locale) sf.getFault().getFaultReasonLocales().next();
String convertedLang = lang.getLanguage();
String country = lang.getCountry();
if (country.length() > 0) {
convertedLang = convertedLang + '-' + country;
}
f.setLang(convertedLang);
}
}
message.setContent(Exception.class, f);
}
} catch (Exception e) {
// do nothing;
}
Throwable cause = f.getCause();
WebFault fault = null;
if (cause != null) {
fault = getWebFaultAnnotation(cause.getClass());
if (fault == null && cause.getCause() != null) {
fault = getWebFaultAnnotation(cause.getCause().getClass());
if (fault != null || cause instanceof RuntimeException) {
cause = cause.getCause();
}
}
}
if (cause instanceof Exception && fault != null) {
Exception ex = (Exception) cause;
Object faultInfo = null;
try {
Method method = cause.getClass().getMethod("getFaultInfo", new Class[0]);
faultInfo = method.invoke(cause, new Object[0]);
} catch (NoSuchMethodException e) {
faultInfo = createFaultInfoBean(fault, cause);
} catch (InvocationTargetException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("INVOCATION_TARGET_EXC", BUNDLE), e);
} catch (IllegalAccessException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e);
} catch (IllegalArgumentException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e);
}
Service service = message.getExchange().getService();
try {
DataWriter<XMLStreamWriter> writer = service.getDataBinding().createWriter(XMLStreamWriter.class);
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) {
Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
writer.setSchema(schema);
}
OperationInfo op = message.getExchange().getBindingOperationInfo().getOperationInfo();
QName faultName = getFaultName(fault, cause.getClass(), op);
MessagePartInfo part = getFaultMessagePart(faultName, op);
if (f.hasDetails()) {
writer.write(faultInfo, part, new W3CDOMStreamWriter(f.getDetail()));
} else {
writer.write(faultInfo, part, new W3CDOMStreamWriter(f.getOrCreateDetail()));
if (!f.getDetail().hasChildNodes()) {
f.setDetail(null);
}
}
f.setMessage(ex.getMessage());
} catch (Exception nex) {
if (nex instanceof Fault) {
message.setContent(Exception.class, nex);
super.handleMessage(message);
} else {
// if exception occurs while writing a fault, we'll just let things continue
// and let the rest of the chain try handling it as is.
LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", nex);
}
}
} else {
FaultMode mode = message.get(FaultMode.class);
if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
// only convert checked exceptions with this
// otherwise delegate down to the normal protocol specific stuff
super.handleMessage(message);
}
}
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class SOAPHandlerInterceptorTest method prepareSOAPHeader.
private Object[] prepareSOAPHeader() throws Exception {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
SoapVersion soapVersion = Soap11.getInstance();
Element envElement = doc.createElementNS(soapVersion.getEnvelope().getNamespaceURI(), soapVersion.getEnvelope().getLocalPart());
Element headerElement = doc.createElementNS(soapVersion.getNamespace(), soapVersion.getHeader().getLocalPart());
Element bodyElement = doc.createElementNS(soapVersion.getBody().getNamespaceURI(), soapVersion.getBody().getLocalPart());
Element childElement = doc.createElementNS("http://apache.org/hello_world_rpclit/types", "ns2:header1");
Attr attr = childElement.getOwnerDocument().createAttributeNS(soapVersion.getNamespace(), "SOAP-ENV:mustUnderstand");
attr.setValue("true");
childElement.setAttributeNodeNS(attr);
headerElement.appendChild(childElement);
envElement.appendChild(headerElement);
envElement.appendChild(bodyElement);
doc.appendChild(envElement);
return new Object[] { doc, headerElement };
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class ServiceJavascriptBuilder method createInputSerializer.
private void createInputSerializer() {
// If are working on a wrapped method, then we use the wrapper element.
// If we are working on an unwrapped method, we will have to work from the unwrapped parts.
MessageInfo message = currentOperation.getInput();
String serializerFunctionGlobalName = getFunctionGlobalName(message.getName(), "serializeInput");
String serializerFunctionPropertyName = getFunctionPropertyName(inputMessagesWithNameConflicts, message, message.getName()) + "_serializeInput";
code.append("function " + serializerFunctionGlobalName + "(cxfjsutils, args) {\n");
String wrapperXmlElementName = null;
// we could use the wrapped part, or we could use a conventional name.
if (isWrapped) {
wrapperXmlElementName = prefixAccumulator.xmlElementString(inputWrapperPartInfo.getConcreteName());
utils.appendLine("var wrapperObj = new " + inputWrapperClassName + "();");
int px = 0;
for (String param : inputParameterNames) {
utils.appendLine("wrapperObj.set" + StringUtils.capitalize(param) + "(args[" + px + "]);");
px++;
}
} else if (isRPC) {
// make sure the rpc element has a valid prefix
prefixAccumulator.xmlElementString(currentOperation.getName());
}
if (soapBindingInfo != null) {
SoapVersion soapVersion = soapBindingInfo.getSoapVersion();
assert soapVersion.getVersion() == 1.1;
utils.appendLine("var xml;");
utils.appendLine("xml = cxfjsutils.beginSoap11Message(\"" + prefixAccumulator.getAttributes() + "\");");
} else {
// other alternative is XML, which isn't really all here yet.
unsupportedConstruct("XML_BINDING", currentInterfaceClassName, xmlBindingInfo.getName());
}
utils.setXmlStringAccumulator("xml");
if (isWrapped) {
ParticleInfo elementInfo = ParticleInfo.forPartElement(inputWrapperElement, xmlSchemaCollection, "wrapperObj", wrapperXmlElementName);
elementInfo.setContainingType(null);
utils.generateCodeToSerializeElement(elementInfo, "", xmlSchemaCollection);
} else {
String operationXmlElement = null;
if (isRPC) {
operationXmlElement = prefixAccumulator.xmlElementString(currentOperation.getName());
// RPC has a level of element for the entire operation.
// we might have some schema to model this, but the following seems
// sufficient.
utils.appendString("<" + operationXmlElement + ">");
}
int px = 0;
// the JavaScript programmer is stuck with the situation).
for (ParticleInfo ean : unwrappedElementsAndNames) {
String savedjsName = ean.getJavascriptName();
try {
ean.setJavascriptName("args[" + px + "]");
utils.generateCodeToSerializeElement(ean, "", xmlSchemaCollection);
px++;
} finally {
ean.setJavascriptName(savedjsName);
}
}
if (isRPC) {
utils.appendString("</" + operationXmlElement + ">");
}
}
utils.appendLine("xml = xml + cxfjsutils.endSoap11Message();");
utils.appendLine("return xml;");
code.append("}\n\n");
code.append(currentInterfaceClassName + ".prototype." + serializerFunctionPropertyName + " = " + serializerFunctionGlobalName + ";\n\n");
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class SecurityTokenServiceProvider method createSOAPFault.
private SoapFault createSOAPFault(Throwable ex) {
String faultString = "Internal STS error";
QName faultCode = null;
if (ex != null) {
if (ex instanceof STSException && ((STSException) ex).getFaultCode() != null) {
faultCode = ((STSException) ex).getFaultCode();
}
faultString = ex.getMessage();
}
MessageContext messageContext = context.getMessageContext();
SoapVersion soapVersion = (SoapVersion) messageContext.get(SoapVersion.class.getName());
SoapFault fault;
if (soapVersion.getVersion() == 1.1 && faultCode != null) {
fault = new SoapFault(faultString, faultCode);
} else {
fault = new SoapFault(faultString, soapVersion.getSender());
if (soapVersion.getVersion() != 1.1 && faultCode != null) {
fault.setSubCode(faultCode);
}
}
return fault;
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class RMEndpointTest method testCreateEndpoint.
@Test
public void testCreateEndpoint() throws NoSuchMethodException, EndpointException {
Method m = RMEndpoint.class.getDeclaredMethod("getUsingAddressing", new Class[] { EndpointInfo.class });
Service as = control.createMock(Service.class);
EndpointInfo aei = new EndpointInfo();
ae = new EndpointImpl(null, as, aei);
rme = EasyMock.createMockBuilder(RMEndpoint.class).withConstructor(manager, ae).addMockedMethod(m).createMock(control);
rme.setAplicationEndpoint(ae);
rme.setManager(manager);
SoapBindingInfo bi = control.createMock(SoapBindingInfo.class);
aei.setBinding(bi);
SoapVersion sv = Soap11.getInstance();
EasyMock.expect(bi.getSoapVersion()).andReturn(sv);
String ns = "http://schemas.xmlsoap.org/wsdl/soap/";
EasyMock.expect(bi.getBindingId()).andReturn(ns);
aei.setTransportId(ns);
String addr = "addr";
aei.setAddress(addr);
Object ua = new Object();
EasyMock.expect(rme.getUsingAddressing(aei)).andReturn(ua);
control.replay();
rme.createServices();
rme.createEndpoints(null);
Endpoint e = rme.getEndpoint(ProtocolVariation.RM10WSA200408);
WrappedEndpoint we = (WrappedEndpoint) e;
assertSame(ae, we.getWrappedEndpoint());
Service s = rme.getService(ProtocolVariation.RM10WSA200408);
assertEquals(1, s.getEndpoints().size());
assertSame(e, s.getEndpoints().get(RM10Constants.PORT_NAME));
}
Aggregations