javax.xml.ws.ProtocolException Java Examples

The following examples show how to use javax.xml.ws.ProtocolException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SOAPHandlerProcessor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: SOAPHandlerProcessor.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: SOAPHandlerProcessor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: SOAPHandlerProcessor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #5
Source File: SOAPHandlerProcessor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: SOAPHandlerProcessor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: SOAPHandlerProcessor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replace the message in the given message context with a
 * fault message. If the context already contains a fault
 * message, then return without changing it.
 *
 * <p>This method should only be called during a request,
 * because during a response an exception from a handler
 * is dispatched rather than replacing the message with
 * a fault. So this method can use the MESSAGE_OUTBOUND_PROPERTY
 * to determine whether it is being called on the client
 * or the server side. If this changes in the spec, then
 * something else will need to be passed to the method
 * to determine whether the fault code is client or server.
 */
final void insertFaultMessage(C context,
    ProtocolException exception) {
    try {
        if(!context.getPacketMessage().isFault()) {
            Message faultMessage = Messages.create(binding.getSOAPVersion(),
                    exception,determineFaultCode(binding.getSOAPVersion()));
            context.setPacketMessage(faultMessage);
        }
    } catch (Exception e) {
        // severe since this is from runtime and not handler
        logger.log(Level.SEVERE,
            "exception while creating fault message in handler chain", e);
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!(Boolean) result.get("validated-token")) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example #9
Source File: XMLHandlerProcessor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #10
Source File: XMLHandlerProcessor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #11
Source File: TieHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #12
Source File: XMLHandlerProcessor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #13
Source File: AbstractWsSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleOutbound(SOAPMessageContext context) {
   try {
      this.getLogger().debug("adding WS-Security header");
      this.addWSSecurity(context);
      context.getMessage().saveChanges();
      return true;
   } catch (Exception var3) {
      throw new ProtocolException(var3);
   }
}
 
Example #14
Source File: XMLHandlerProcessor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #15
Source File: IncomingSecurityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean handleInbound(SOAPMessageContext context) {
   SOAPMessage message = context.getMessage();
   WSSecurityEngine secEngine = new WSSecurityEngine();
   RequestData requestData = new RequestData();
   requestData.setWssConfig(this.config);

   try {
      SOAPHeader header = message.getSOAPHeader();
      if (header != null) {
         NodeList list = header.getElementsByTagNameNS(WSSE.getNamespaceURI(), WSSE.getLocalPart());
         if (list != null) {
            LOG.debug("Verify WS Security Header");

            for(int j = 0; j < list.getLength(); ++j) {
               List<WSSecurityEngineResult> results = secEngine.processSecurityHeader((Element)list.item(j), requestData);
               Iterator i$ = results.iterator();

               while(i$.hasNext()) {
                  WSSecurityEngineResult result = (WSSecurityEngineResult)i$.next();
                  if (!(Boolean)result.get("validated-token")) {
                     StringBuffer sb = new StringBuffer();
                     sb.append("Unable to validate incoming soap message. Action [");
                     sb.append(result.get("action"));
                     sb.append("].");
                     throw new ProtocolException(sb.toString());
                  }
               }
            }
         }
      }

      return true;
   } catch (WSSecurityException var12) {
      throw new ProtocolException(var12);
   } catch (SOAPException var13) {
      throw new ProtocolException(var13);
   }
}
 
Example #16
Source File: TieHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #17
Source File: TieHandler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #18
Source File: TieHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #19
Source File: XMLHandlerProcessor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #20
Source File: TieHandler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #21
Source File: XMLHandlerProcessor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #22
Source File: TieHandler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #23
Source File: XMLHandlerProcessor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
final void insertFaultMessage(C context,
        ProtocolException exception) {
    if(exception instanceof HTTPException) {
        context.put(MessageContext.HTTP_RESPONSE_CODE,((HTTPException)exception).getStatusCode());
    }
    if (context != null) {
        // non-soap case
        context.setPacketMessage(Messages.createEmpty(binding.getSOAPVersion()));
    }
}
 
Example #24
Source File: TieHandler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Message createResponse(JavaCallInfo call) {
        Message responseMessage;
        if (call.getException() == null) {
            responseMessage = isOneWay ? null : createResponseMessage(call.getParameters(), call.getReturnValue());
        } else {
            Throwable e = call.getException();
            Throwable serviceException = getServiceException(e);
            if (e instanceof InvocationTargetException || serviceException != null) {
//              Throwable cause = e.getCause();
              //if (!(cause instanceof RuntimeException) && cause instanceof Exception) {
                if (serviceException != null) {
                    // Service specific exception
                    LOGGER.log(Level.FINE, serviceException.getMessage(), serviceException);
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion,
                            javaMethodModel.getCheckedException(serviceException.getClass()), serviceException);
                } else {
                    Throwable cause = e.getCause();
                    if (cause instanceof ProtocolException) {
                        // Application code may be throwing it intentionally
                        LOGGER.log(Level.FINE, cause.getMessage(), cause);
                    } else {
                        // Probably some bug in application code
                        LOGGER.log(Level.SEVERE, cause.getMessage(), cause);
                    }
                    responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, cause);
                }
            } else if (e instanceof DispatchException) {
                responseMessage = ((DispatchException)e).fault;
            } else {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
                responseMessage = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e);
            }
        }
//        return req.createServerResponse(responseMessage, req.endpoint.getPort(), javaMethodModel.getOwner(), req.endpoint.getBinding());

        return responseMessage;
    }
 
Example #25
Source File: ThrowFaultInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Boolean isColoc = (Boolean)message.get("org.apache.cxf.message.Message.COLOCATED");
    if (isColoc == null || isColoc == Boolean.FALSE) {
        String str = new String("Collocated Invocation should have been detected.");
        throw new ProtocolException(str);
    }
}
 
Example #26
Source File: ModifyNumberHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public final boolean handleMessage(LogicalMessageContext messageContext) {
    //System.out.println("LogicalMessageHandler handleMessage called");

    try {
        // get the LogicalMessage from our context
        LogicalMessage msg = messageContext.getMessage();

        // check the payload, if its an AddNumbers request, we'll intervene
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        Object payload = msg.getPayload(jaxbContext);
        Object value = payload;
        if (payload instanceof JAXBElement) {
            value = ((JAXBElement<?>)payload).getValue();
        }

        if (value instanceof AddNumbers) {
            AddNumbers req = (AddNumbers)value;

            int a = req.getArg0();
            req.setArg0(a * 10);
            msg.setPayload(payload, jaxbContext);
        }
        return true;
    } catch (JAXBException ex) {
        throw new ProtocolException(ex);
    }

}
 
Example #27
Source File: TestHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean handleMessage(T ctx) {
    methodCalled("handleMessage");
    printHandlerInfo("handleMessage", isOutbound(ctx));

    boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    boolean ret = getHandleMessageRet();

    if (!isServerSideHandler()) {
        return true;
    }

    try {
        verifyJAXWSProperties(ctx);
    } catch (PingException e) {
        e.printStackTrace();
        throw new ProtocolException(e);
    }

    Object obj = ctx.getMessage().getPayload(jaxbCtx);

    if (obj instanceof Ping
        || obj instanceof PingResponse) {
        ret = handlePingMessage(outbound, ctx);
    } else if (obj instanceof PingWithArgs) {
        ret = handlePingWithArgsMessage(outbound, ctx);
    }
    return ret;
}
 
Example #28
Source File: HandlerInvocationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogicalHandlerHandleMessageThrowsProtocolExceptionClientOutbound() throws Exception {
    final String clientHandlerMessage = "handler1 client side";

    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
        public boolean handleMessage(LogicalMessageContext ctx) {
            super.handleMessage(ctx);
            Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            if (outbound) {
                throw new ProtocolException(clientHandlerMessage);
            }
            return true;
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);

    addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1);

    try {
        handlerTest.ping();
        fail("did not get expected exception");
    } catch (ProtocolException e) {
        assertEquals(clientHandlerMessage, e.getMessage());
    }

    assertEquals(1, handler1.getHandleMessageInvoked());
    assertEquals(1, handler2.getHandleMessageInvoked());
    assertEquals(0, soapHandler1.getHandleMessageInvoked());

    assertEquals(0, handler2.getHandleFaultInvoked());
    assertEquals(1, handler1.getHandleFaultInvoked());
    assertEquals(0, soapHandler1.getHandleFaultInvoked());

    assertEquals(1, handler1.getCloseInvoked());
    assertEquals(1, handler2.getCloseInvoked());
    assertEquals(0, soapHandler1.getCloseInvoked());
    assertTrue(handler2.getInvokeOrderOfClose()
               < handler1.getInvokeOrderOfClose());
}
 
Example #29
Source File: HandlerInvocationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogicalHandlerHandleMessageThrowsProtocolExceptionClientInbound() throws Exception {
    final String clientHandlerMessage = "handler1 client side";

    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
        public boolean handleMessage(LogicalMessageContext ctx) {
            super.handleMessage(ctx);
            Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            if (!outbound) {
                throw new ProtocolException(clientHandlerMessage);
            }
            return true;
        }
    };
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);

    addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1);

    try {
        handlerTest.ping();
        //fail("did not get expected exception");
    } catch (ProtocolException e) {
        assertEquals(clientHandlerMessage, e.getMessage());
    }

    assertEquals(1, handler1.getHandleMessageInvoked());
    assertEquals(2, handler2.getHandleMessageInvoked());
    assertEquals(2, soapHandler1.getHandleMessageInvoked());

    assertEquals(0, handler2.getHandleFaultInvoked());
    assertEquals(0, handler1.getHandleFaultInvoked());
    assertEquals(0, soapHandler1.getHandleFaultInvoked());

    assertEquals(1, handler1.getCloseInvoked());
    assertEquals(1, handler2.getCloseInvoked());
    assertEquals(1, soapHandler1.getCloseInvoked());
    assertTrue(handler2.getInvokeOrderOfClose()
               < handler1.getInvokeOrderOfClose());
}
 
Example #30
Source File: MAPTestBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testExplicitMAPs() throws Exception {
    try {
        String msgId = "urn:uuid:12345-" + Math.random();
        Map<String, Object> requestContext =
            ((BindingProvider)greeter).getRequestContext();
        AddressingProperties maps = new AddressingProperties();
        AttributedURIType id =
            ContextUtils.getAttributedURI(msgId);
        maps.setMessageID(id);
        requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
        String greeting = greeter.greetMe("explicit1");
        assertEquals("unexpected response received from service",
                     "Hello explicit1",
                     greeting);
        checkVerification();

        // the previous addition to the request context impacts
        // on all subsequent invocations on this proxy => a duplicate
        // message ID fault is expected
        try {
            greeter.greetMe("explicit2");
            fail("expected ProtocolException on duplicate message ID");
        } catch (ProtocolException pe) {
            assertEquals("expected duplicate message ID failure",
                       "Duplicate Message ID " + msgId, pe.getMessage());
            checkVerification();
        }

        // clearing the message ID ensure a duplicate is not sent
        maps.setMessageID(null);
        //maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue()));
        greeting = greeter.greetMe("explicit3");
        assertEquals("unexpected response received from service",
                     "Hello explicit3",
                     greeting);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception)ex.getCause();
    }
}