Search in sources :

Example 16 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class TestHandler method handlePingWithArgsMessage.

private boolean handlePingWithArgsMessage(boolean outbound, T ctx) {
    LogicalMessage msg = ctx.getMessage();
    Object payload = msg.getPayload(jaxbCtx);
    addHandlerId(ctx.getMessage(), ctx, outbound);
    boolean ret = true;
    if (payload instanceof PingWithArgs) {
        String arg = ((PingWithArgs) payload).getHandlersCommand();
        StringTokenizer strtok = new StringTokenizer(arg, " ");
        String hid = "";
        String direction = "";
        String command = "";
        if (strtok.countTokens() >= 3) {
            hid = strtok.nextToken();
            direction = strtok.nextToken();
            command = strtok.nextToken();
        }
        if (!getHandlerId().equals(hid)) {
            return true;
        }
        if ("stop".equals(command)) {
            if (!outbound && "inbound".equals(direction)) {
                PingResponse resp = new PingResponse();
                resp.getHandlersInfo().addAll(getHandlerInfoList(ctx));
                msg.setPayload(resp, jaxbCtx);
                ret = false;
            } else if (outbound && "outbound".equals(direction)) {
                ret = false;
            }
        } else if ("throw".equals(command)) {
            String exceptionType = null;
            String exceptionText = "HandleMessage throws exception";
            if (strtok.hasMoreTokens()) {
                exceptionType = strtok.nextToken();
            }
            if (strtok.hasMoreTokens()) {
                exceptionText = strtok.nextToken();
            }
            if (exceptionType != null && !outbound && "inbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                }
            } else if (exceptionType != null && outbound && "outbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                }
            }
        }
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) PingWithArgs(org.apache.handler_test.types.PingWithArgs) StringTokenizer(java.util.StringTokenizer) PingResponse(org.apache.handler_test.types.PingResponse) LogicalMessage(javax.xml.ws.LogicalMessage)

Example 17 with ProtocolException

use of javax.xml.ws.ProtocolException in project cxf by apache.

the class TestSOAPHandler method getReturnValue.

private boolean getReturnValue(boolean outbound, SOAPMessageContext ctx) {
    boolean ret = true;
    try {
        SOAPMessage msg = ctx.getMessage();
        SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
        if (body.getFirstChild().getFirstChild() == null) {
            return true;
        }
        Node commandNode = body.getFirstChild().getFirstChild().getFirstChild();
        String arg = commandNode.getNodeValue();
        String namespace = body.getFirstChild().getFirstChild().getNamespaceURI();
        StringTokenizer strtok = new StringTokenizer(arg, " ");
        String hid = "";
        String direction = "";
        String command = "";
        if (strtok.countTokens() >= 3) {
            hid = strtok.nextToken();
            direction = strtok.nextToken();
            command = strtok.nextToken();
        }
        if (!getHandlerId().equals(hid)) {
            return true;
        }
        if ("stop".equals(command)) {
            if (!outbound && "inbound".equals(direction)) {
                // remove the incoming request body.
                Document doc = body.getOwnerDocument();
                // build the SOAP response for this message
                // 
                Node wrapper = doc.createElementNS(namespace, "pingResponse");
                wrapper.setPrefix("ns4");
                body.removeChild(body.getFirstChild());
                body.appendChild(wrapper);
                for (String info : getHandlerInfoList(ctx)) {
                    // 
                    if (!info.contains(getHandlerId())) {
                        Node newEl = doc.createElementNS(namespace, "HandlersInfo");
                        newEl.setPrefix("ns4");
                        newEl.appendChild(doc.createTextNode(info));
                        wrapper.appendChild(newEl);
                    }
                }
                ret = false;
            } else if (outbound && "outbound".equals(direction)) {
                ret = false;
            }
        } else if ("throw".equals(command)) {
            String exceptionType = null;
            String exceptionText = "HandleMessage throws exception";
            if (strtok.hasMoreTokens()) {
                exceptionType = strtok.nextToken();
            }
            if (strtok.hasMoreTokens()) {
                exceptionText = strtok.nextToken();
            }
            if (exceptionType != null && !outbound && "inbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                } else if ("SOAPFaultException".equals(exceptionType)) {
                    throw createSOAPFaultException(exceptionText);
                } else if ("SOAPFaultExceptionWDetail".equals(exceptionType)) {
                    throw createSOAPFaultExceptionWithDetail(exceptionText);
                }
            } else if (exceptionType != null && outbound && "outbound".equals(direction)) {
                if ("RuntimeException".equals(exceptionType)) {
                    throw new RuntimeException(exceptionText);
                } else if ("ProtocolException".equals(exceptionType)) {
                    throw new ProtocolException(exceptionText);
                } else if ("SOAPFaultException".equals(exceptionType)) {
                    throw createSOAPFaultException(exceptionText);
                } else if ("SOAPFaultExceptionWDetail".equals(exceptionType)) {
                    throw createSOAPFaultExceptionWithDetail(exceptionText);
                }
            }
        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return ret;
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) SOAPBody(javax.xml.soap.SOAPBody) StringTokenizer(java.util.StringTokenizer) Node(org.w3c.dom.Node) SOAPException(javax.xml.soap.SOAPException) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage)

Aggregations

ProtocolException (javax.xml.ws.ProtocolException)17 Test (org.junit.Test)10 LogicalMessage (javax.xml.ws.LogicalMessage)4 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBElement (javax.xml.bind.JAXBElement)3 JAXBException (javax.xml.bind.JAXBException)3 Source (javax.xml.transform.Source)3 AddNumbers (org.apache.handlers.types.AddNumbers)3 StringTokenizer (java.util.StringTokenizer)2 SOAPException (javax.xml.soap.SOAPException)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 WebServiceException (javax.xml.ws.WebServiceException)2 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)2 PingResponse (org.apache.handler_test.types.PingResponse)2 PingWithArgs (org.apache.handler_test.types.PingWithArgs)2 AddNumbersResponse (org.apache.handlers.types.AddNumbersResponse)2 ObjectFactory (org.apache.handlers.types.ObjectFactory)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPBody (javax.xml.soap.SOAPBody)1