Search in sources :

Example 31 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 32 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)32 Test (org.junit.Test)10 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)9 SOAPException (javax.xml.soap.SOAPException)9 SOAPFactory (javax.xml.soap.SOAPFactory)9 SOAPFault (javax.xml.soap.SOAPFault)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)9 SOAPMessage (javax.xml.soap.SOAPMessage)8 JAXBContext (javax.xml.bind.JAXBContext)7 JAXBException (javax.xml.bind.JAXBException)7 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)6 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)5 LogicalMessage (javax.xml.ws.LogicalMessage)4 SystemException (com.arjuna.wst.SystemException)3 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)3 BusinessActivityTerminator (com.arjuna.wst11.BusinessActivityTerminator)3 JAXBElement (javax.xml.bind.JAXBElement)3 SOAPHeader (javax.xml.soap.SOAPHeader)3 Source (javax.xml.transform.Source)3