本文整理汇总了Java中org.apache.cxf.binding.soap.SoapFault类的典型用法代码示例。如果您正苦于以下问题:Java SoapFault类的具体用法?Java SoapFault怎么用?Java SoapFault使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SoapFault类属于org.apache.cxf.binding.soap包,在下文中一共展示了SoapFault类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRouteBuilder
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(fromURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
QName faultCode = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server");
SoapFault fault = new SoapFault("Get the null value of person name", faultCode);
Element details = StaxUtils.read(new StringReader(DETAILS)).getDocumentElement();
fault.setDetail(details);
exchange.setException(fault);
}
});
}
};
}
示例2: errorResponse
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
public static ApiResponse errorResponse(@ExchangeException Exception ex){
String message;
int code = 5000;
if (ex instanceof BeanValidationException){
code=5001;
message = Optional.ofNullable(((BeanValidationException)ex).getConstraintViolations()).orElseGet(Collections::emptySet)
.stream()
.map((v)->"'"+v.getPropertyPath()+"' "+v.getMessage())
.collect(Collectors.joining("; "));
} else if (ex instanceof SoapFault) {
//SoapFault in only thrown is http 200 was returned with soap:Fault, otherwise cxf throws the http exception
code=5002;
message = "Error calling soap service: "+((SoapFault)ex).getMessage();
}
else {
message = ex.getMessage();
}
return new ApiResponse(code, message);
}
示例3: createRouteBuilder
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: onException
from("direct:start")
.onException(SoapFault.class)
.maximumRedeliveries(0)
.handled(true)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
SoapFault fault =
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
exchange.getOut().setFault(true);
exchange.getOut().setBody(fault);
}
})
.end()
.to(serviceURI);
// END SNIPPET: onException
// START SNIPPET: ThrowFault
from(routerEndpointURI).setFaultBody(constant(SOAP_FAULT));
// END SNIPPET: ThrowFault
}
};
}
示例4: testInvokingServiceFromCXFClient
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
clientBean.setAddress(routerAddress);
clientBean.setServiceClass(HelloService.class);
clientBean.setBus(bus);
HelloService client = (HelloService) proxyFactory.create();
try {
client.echo("hello world");
fail("Expect to get an exception here");
} catch (Exception e) {
assertEquals("Expect to get right exception message", EXCEPTION_MESSAGE, e.getMessage());
assertTrue("Exception is not instance of SoapFault", e instanceof SoapFault);
assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault)e).getDetail().getTextContent());
//In CXF 2.1.2 , the fault code is per spec , the below fault-code is for SOAP 1.1
assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault)e).getFaultCode().toString());
}
}
示例5: createRouteBuilder
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(fromURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
JAXBContext context = JAXBContext.newInstance("org.apache.camel.wsdl_first.types");
QName faultCode = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server");
SoapFault fault = new SoapFault("Get the null value of person name", faultCode);
Element details = StaxUtils.read(new StringReader(DETAILS)).getDocumentElement();
UnknownPersonFault unknowPersonFault = new UnknownPersonFault();
unknowPersonFault.setPersonId("");
context.createMarshaller().marshal(unknowPersonFault, details);
fault.setDetail(details);
exchange.getOut().setBody(fault);
exchange.getOut().setFault(true);
}
});
}
};
}
示例6: handleMessage
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Override
public void handleMessage(final SoapMessage message) throws Fault {
final Fault fault = (Fault) message.getContent(Exception.class);
// Only change the fault code if it was not generated by Cyclos
if (!WebServiceHelper.isFromCyclos(fault)) {
final Throwable exception = fault.getCause() == null ? fault : fault.getCause();
final SoapFault soapFault = WebServiceHelper.fault(exception);
fault.setDetail(null);
fault.setFaultCode(soapFault.getFaultCode());
fault.setMessage(message(exception));
}
// there are cases where this interceptor is invoked but the context wasn't initialized
// (e.g.: there is a unmarshalling error when CXF is trying to convert the request parameters)
//
if (WebServiceContext.isInitialized()) {
final HttpServletRequest request = WebServiceContext.getRequest();
request.setAttribute("soapFault", fault);
}
webServiceHelper.error(fault);
}
示例7: testProxyRedelivery
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Test
public void testProxyRedelivery() throws Exception {
TransferRequest request = new TransferRequest();
request.setBank("Bank of Camel");
request.setFrom("Jakub");
request.setTo("Scott");
request.setAmount("1");
context.stopRoute("wsBackend");
assertTrue(context.getRouteStatus("wsBackend").isStopped());
try {
TransferResponse response = template.requestBody("cxf:http://localhost:" + port1 + "/paymentService?serviceClass=org.camelcookbook.ws.payment_service.Payment", request, TransferResponse.class);
fail("Should have failed as backend WS is down");
} catch (CamelExecutionException e) {
SoapFault fault = assertIsInstanceOf(SoapFault.class, e.getCause());
log.info(fault.getReason());
}
}
示例8: testProxyRedeliverySpring
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Test
public void testProxyRedeliverySpring() throws Exception {
TransferRequest request = new TransferRequest();
request.setBank("Bank of Camel");
request.setFrom("Jakub");
request.setTo("Scott");
request.setAmount("1");
context.stopRoute("wsBackend");
assertTrue(context.getRouteStatus("wsBackend").isStopped());
try {
TransferResponse response = template.requestBody("cxf:http://localhost:" + port1 + "/paymentService?serviceClass=org.camelcookbook.ws.payment_service.Payment", request, TransferResponse.class);
fail("Should have failed as backend WS is down");
} catch (CamelExecutionException e) {
SoapFault fault = assertIsInstanceOf(SoapFault.class, e.getCause());
log.info(fault.getReason());
}
}
示例9: getValue
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
public SoapFault getValue() throws Exception {
SoapFault fault = new SoapFault(message, faultCode);
if (xmlDetail != null) {
Document document = xmlDetail.getValue();
if (!document.getDocumentElement().getNodeName().equals("detail")) {
logger.warn("The provided XML is not wrapped in a detail element, this is required and one will be added");
DocumentBuilder builder = xmlUtilities.getDocumentBuilder();
Document newDetailDocument = builder.newDocument();
Element newDetailElement = newDetailDocument.createElement("detail");
newDetailDocument.appendChild(newDetailElement);
newDetailElement.appendChild(newDetailDocument.importNode(document.getDocumentElement(), true));
fault.setDetail(newDetailElement);
} else
fault.setDetail(document.getDocumentElement());
}
return fault;
}
示例10: createRouteBuilder
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
//a straight through proxy
from("jetty:http://localhost:8090/testWS")
.to("jetty:http://localhost:8090/targetWS?bridgeEndpoint=true&throwExceptionOnFailure=false");
SoapFault fault = new SoapFault("Pretend SOAP Fault", SoapFault.FAULT_CODE_CLIENT);
from("cxf:http://localhost:8092/testWSFault?wsdlURL=data/PingService.wsdl&dataFormat=PAYLOAD")
.setFaultBody(constant(fault));
SoapFault detailedFault = new SoapFault("Pretend Detailed SOAP Fault", SoapFault.FAULT_CODE_SERVER);
detailedFault.setDetail(new XmlUtilities().getXmlAsDocument("<detail><foo/></detail>").getDocumentElement());
from("cxf:http://localhost:8092/testWSFaultDetail?wsdlURL=data/PingService.wsdl&dataFormat=PAYLOAD")
.setFaultBody(constant(detailedFault));
from("jetty:http://localhost:8093/jsonPingService")
.setBody(constant("{\"response\":\"PONG\"}"));
}
};
}
示例11: testInvokingServiceFromCamel
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Test
public void testInvokingServiceFromCamel() throws Exception {
Object result = template.sendBodyAndHeader("direct:start", ExchangePattern.InOut, "hello world", CxfConstants.OPERATION_NAME, "echo");
assertTrue("Exception is not instance of SoapFault", result instanceof SoapFault);
assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault)result).getDetail().getTextContent());
assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault)result).getFaultCode().toString());
}
示例12: testInvokingServiceFromCamel
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
@Test
public void testInvokingServiceFromCamel() throws Exception {
try {
template.sendBodyAndHeader("direct:start", ExchangePattern.InOut, "hello world", CxfConstants.OPERATION_NAME, "echo");
fail("Should have thrown an exception");
} catch (Exception ex) {
Throwable result = ex.getCause();
assertTrue("Exception is not instance of SoapFault", result instanceof SoapFault);
assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault)result).getDetail().getTextContent());
assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault)result).getFaultCode().toString());
}
}
示例13: secureResponse
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
public void secureResponse(SoapMessage message)
{
SOAPMessage request = message.getExchange().getInMessage().get(SOAPMessage.class);
SOAPMessage response = message.getContent(SOAPMessage.class);
MessageInfo messageInfo = new GenericMessageInfo(request, response);
AuthStatus authStatus = null;
try
{
authStatus = sctx.secureResponse(messageInfo, null);
}
catch (AuthException e)
{
if (isSOAP12(message))
{
SoapFault soap12Fault = new SoapFault(e.getMessage(), Soap12.getInstance().getReceiver());
throw soap12Fault;
}
else
{
throw new SoapFault(e.getMessage(), new QName("", "jaspi AuthException"));
}
}
if (messageInfo.getResponseMessage() != null && !message.getExchange().isOneWay())
{
if (AuthStatus.SEND_CONTINUE == authStatus)
{
message.put(Message.RESPONSE_CODE, Integer.valueOf(303));
}
if (AuthStatus.SEND_FAILURE == authStatus)
{
message.put(Message.RESPONSE_CODE, Integer.valueOf(500));
}
}
}
示例14: secureRequest
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
public void secureRequest(SoapMessage message)
{
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
MessageInfo messageInfo = new GenericMessageInfo(soapMessage, null);
String authContextID = clientConfig.getAuthContextID(messageInfo);
Properties serverContextProperties = new Properties();
serverContextProperties.put("security-domain", securityDomain);
serverContextProperties.put("jaspi-policy", jpi);
Subject clientSubject = new Subject();
@SuppressWarnings("unused")
AuthStatus authStatus = null;
try
{
ClientAuthContext cctx = clientConfig.getAuthContext(authContextID, clientSubject, serverContextProperties);
authStatus = cctx.secureRequest(messageInfo, clientSubject);
}
catch (AuthException e)
{
if (isSOAP12(message))
{
SoapFault soap12Fault = new SoapFault(e.getMessage(), Soap12.getInstance().getSender());
throw soap12Fault;
}
else
{
throw new SoapFault(e.getMessage(), new QName("", "japsi AuthException"));
}
}
//TODO:look at how to handle AuthStatus
}
示例15: validateResponse
import org.apache.cxf.binding.soap.SoapFault; //导入依赖的package包/类
public void validateResponse(SoapMessage message)
{
SOAPMessage request = message.getExchange().getInMessage().get(SOAPMessage.class);
SOAPMessage response = message.getContent(SOAPMessage.class);
MessageInfo messageInfo = new GenericMessageInfo(request, response);
String authContextID = clientConfig.getAuthContextID(messageInfo);
Properties serverContextProperties = new Properties();
serverContextProperties.put("security-domain", securityDomain);
serverContextProperties.put("jaspi-policy", jpi);
Subject clientSubject = new Subject();
@SuppressWarnings("unused")
AuthStatus authStatus = null;
try
{
ClientAuthContext sctx = clientConfig.getAuthContext(authContextID, clientSubject, serverContextProperties);
authStatus = sctx.validateResponse(messageInfo, new Subject(), new Subject());
}
catch (AuthException e)
{
if (isSOAP12(message))
{
SoapFault soap12Fault = new SoapFault(e.getMessage(), Soap12.getInstance().getSender());
throw soap12Fault;
}
else
{
throw new SoapFault(e.getMessage(), new QName("", "japsi AuthException"));
}
}
//TODO:handle AuthStatus
}