@Test
  public void testRequestClientValidation() {
    Person person = new Person();

    try {
      disconnectedClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setFirstName(""); // empty string is valid
    try {
      disconnectedClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setLastName(""); // empty string is valid

    // this confirms that we passed client validation as we then got the connectivity error
    try {
      disconnectedClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (WebServiceException e) {
      assertTrue(e.getMessage().contains("Could not send Message"));
    }
  }
  /** {@inheritDoc} */
  @Override
  public Map<Integer, MarketBean> findAllMarkets() throws NotFoundException, TechnicalException {
    log.info("Executing operation findAllMarkets");

    Map<Integer, MarketBean> mapOfMarket = new HashMap<Integer, MarketBean>();

    try {

      List<MarcheSoap> listOfMarcheSoap = gererMarcheSoapProxy.rechercherMarches();
      for (MarcheSoap bean : listOfMarcheSoap) {
        mapOfMarket.put(bean.getId(), mapperSoap.map(bean, MarketBean.class));
      }

    } catch (ErreurTechniqueFault e) {
      // maps to TechnicalException
      throw mapperSoap.map(e);
    } catch (ErreurMarcheNonTrouveFault e) {
      // map to NotFoundException
      throw mapperSoap.map(e);
    } catch (WebServiceException e) {
      log.info("a timeout exception has occured: ");
      throw new TechnicalException(e.getMessage(), e.getCause());
    }

    return mapOfMarket;
  }
  /** {@inheritDoc} */
  @Override
  public List<MarketBean> findMarketByName(String name)
      throws NotFoundException, TechnicalException {
    log.info("Executing operation findMarketByName : " + name);

    List<MarketBean> listOfMarkets = new ArrayList<MarketBean>();

    try {

      List<MarcheSoap> listOfMarcheSoap = gererMarcheSoapProxy.rechercherMarchesParNom(name);
      for (MarcheSoap bean : listOfMarcheSoap) {
        listOfMarkets.add(mapperSoap.map(bean, MarketBean.class));
      }

    } catch (ErreurTechniqueFault e) {
      // maps to TechnicalException
      throw mapperSoap.map(e);
    } catch (ErreurMarcheNonTrouveFault e) {
      // map to NotFoundException
      throw mapperSoap.map(e);
    } catch (WebServiceException e) {
      log.info("a timeout exception has occured: ");
      throw new TechnicalException(e.getMessage(), e.getCause());
    }

    return listOfMarkets;
  }
 public void deleteSupplier(List<Long> movCatIdList, boolean ignoreReference)
     throws DBReferenceViolationException {
   try {
     supplierService.deleteSupplier(movCatIdList, ignoreReference);
   } catch (javax.xml.ws.soap.SOAPFaultException ex) {
     ex.printStackTrace();
     throw new ServerException(ex.getMessage(), ex);
   } catch (WebServiceException ex) {
     ex.printStackTrace();
     throw new ServerConnectionException(ex.getMessage(), ex);
   }
 }
 public void updateSupplier(SupplierVO supplierVO)
     throws InvalidInputException, DuplicateException {
   try {
     supplierService.updateSupplier(supplierVO);
   } catch (InvalidAdminInputException ex) {
     throw new InvalidInputException(ex.getMessage(), ex);
   } catch (javax.xml.ws.soap.SOAPFaultException ex) {
     ex.printStackTrace();
     throw new ServerException(ex.getMessage(), ex);
   } catch (WebServiceException ex) {
     ex.printStackTrace();
     throw new ServerConnectionException(ex.getMessage(), ex);
   }
 }
  public List<SupplierVO> getSupplierList() {
    if (supplierService == null) {
      throw new IllegalStateException("supplierService has not set");
    }

    try {
      return supplierService.getSupplierList();
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
      ex.printStackTrace();
      throw new ServerException(ex.getMessage(), ex);
    } catch (WebServiceException ex) {
      ex.printStackTrace();
      throw new ServerConnectionException(ex.getMessage(), ex);
    }
  }
  private void testFail(FaultLocation location, boolean usingAddressing, boolean robust)
      throws PingMeFault {
    // System.out.print("Test interceptor failing in phase: " + location.getPhase());

    control.setFaultLocation(location);

    // oneway reports a plain fault (although server sends a soap fault)

    boolean expectOnewayFault =
        robust || comparator.compare(preLogicalPhase, getPhase(location.getPhase())) > 0;

    try {
      greeter.greetMeOneWay("oneway");
      if (expectOnewayFault) {
        fail("Oneway operation unexpectedly succeded for phase " + location.getPhase());
      }
    } catch (WebServiceException ex) {
      if (!expectOnewayFault) {
        fail("Oneway operation unexpectedly failed.");
      }
      assertEquals(FAULT_MESSAGE, ex.getMessage());
    }

    String expectedMsg = getExpectedInterceptorFaultMessage(location.getPhase());
    try {
      greeter.greetMe("cxf");
      fail("Twoway operation unexpectedly succeded.");
    } catch (WebServiceException ex) {
      Throwable cause = ex.getCause();
      SoapFault sf = (SoapFault) cause;

      assertEquals(expectedMsg, sf.getReason());
      assertEquals(SOAP_FAULT_CODE, sf.getFaultCode());
    }

    try {
      greeter.pingMe();
      fail("Expected PingMeFault not thrown.");
    } catch (WebServiceException ex) {
      Throwable cause = ex.getCause();
      SoapFault sf = (SoapFault) cause;
      assertEquals(expectedMsg, sf.getReason());
      assertEquals(SOAP_FAULT_CODE, sf.getFaultCode());
    }
  }
  /** {@inheritDoc} */
  @Override
  public void deleteMarket(int id) throws InvalidMarketException, TechnicalException {
    log.info("Executing operation deleteMarket");

    try {

      gererMarcheSoapProxy.supprimerMarche(id);

    } catch (ErreurTechniqueFault e) {
      // maps to TechnicalException
      throw mapperSoap.map(e);
    } catch (ErreurMarcheInvalideFault e) {
      // map to InvalidMarketException
      throw mapperSoap.map(e);
    } catch (WebServiceException e) {
      log.info("a timeout exception has occured: ");
      throw new TechnicalException(e.getMessage(), e.getCause());
    }
  }
  /** {@inheritDoc} */
  @Override
  public void createMarket(MarketBean market) throws InvalidMarketException, TechnicalException {
    log.info("Executing operation createMarket");

    try {

      MarcheSoap marcheSoap = (MarcheSoap) mapperSoap.map(market, MarcheSoap.class);
      gererMarcheSoapProxy.creerMarche(marcheSoap);

    } catch (ErreurTechniqueFault e) {
      // maps to TechnicalException
      throw mapperSoap.map(e);
    } catch (ErreurMarcheInvalideFault e) {
      // map to InvalidMarketException
      throw mapperSoap.map(e);
    } catch (WebServiceException e) {
      log.info("a timeout exception has occured: ");
      throw new TechnicalException(e.getMessage(), e.getCause());
    }
  }
  /** {@inheritDoc} */
  @Override
  public MarketBean consultMarket(int idMarket) throws NotFoundException, TechnicalException {
    log.info("Executing operation consultMarket");

    MarketBean marketBean = null;

    try {

      MarcheSoap marcheSoap = gererMarcheSoapProxy.consulterMarche(idMarket);
      marketBean = (MarketBean) mapperSoap.map(marcheSoap, MarketBean.class);

    } catch (ErreurTechniqueFault e) {
      // maps to TechnicalException
      throw mapperSoap.map(e);
    } catch (ErreurMarcheNonTrouveFault e) {
      // map to NotFoundException
      throw mapperSoap.map(e);
    } catch (WebServiceException e) {
      log.info("a timeout exception has occured: ");
      throw new TechnicalException(e.getMessage(), e.getCause());
    }

    return marketBean;
  }
Example #11
0
  /**
   * Negative test...can't convert List of B into C[]
   *
   * @throws Exception
   */
  public void testBListtoCArray() throws Exception {
    ArrayList<B> input = new ArrayList<B>();
    B b = new B();
    b.setData(0);
    input.add(b);
    b = new B();
    b.setData(1);
    input.add(b);
    b = new B();
    b.setData(2);
    input.add(b);

    C[] output = new C[0];

    boolean success = false;
    try {
      output = (C[]) ConvertUtils.convert(input, output.getClass());
    } catch (WebServiceException e) {
      assertTrue(e.getMessage().contains("Cannot convert"));
      success = true;
    }

    assertTrue(success);
  }
Example #12
0
  public synchronized void registerService(EndpointConfiguration configuration) {
    if (delegate == null) {
      // servlet has not be initialized, delay service registration
      configurations.add(configuration);
      return;
    }
    Class<?> seiClass = configuration.getSeiClass();
    ClassLoader classLoader = seiClass.getClassLoader();
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(classLoader);
      URL wsdlLocation = configuration.getWsdlLocation();
      SDDocumentSource primaryWsdl = null;
      if (wsdlLocation != null) {
        // WSDL may not be defined for a Java-based endpoint, in which case it will be introspected
        // from the SEI class
        primaryWsdl = SDDocumentSource.create(wsdlLocation);
      }
      WSBinding binding = BindingImpl.create(BindingID.SOAP11_HTTP);
      Container endpointContainer = container;
      List<SDDocumentSource> metadata = null;
      URL generatedWsdl = configuration.getGeneratedWsdl();
      if (generatedWsdl != null) {
        // create a container wrapper used by Metro to resolve the WSIT configuration
        endpointContainer = new WsitConfigurationContainer(container, generatedWsdl);
        // Compile the list of imported schemas so they can be resolved using ?xsd GET requests.
        // Metro will re-write the WSDL import
        // so clients can dereference the imports when they obtain the WSDL.
        metadata = new ArrayList<>();
        List<URL> schemas = configuration.getGeneratedSchemas();
        if (schemas != null) {
          for (URL schema : schemas) {
            metadata.add(SDDocumentSource.create(schema));
          }
        }
      }
      String servicePath = configuration.getServicePath();
      Invoker invoker = configuration.getInvoker();
      QName serviceName = configuration.getServiceName();
      QName portName = configuration.getPortName();

      // Fetch the handlers
      loadHandlers(binding, configuration);

      WSEndpoint<?> wsEndpoint;
      try {
        wsEndpoint =
            WSEndpoint.create(
                seiClass,
                false,
                invoker,
                serviceName,
                portName,
                endpointContainer,
                binding,
                primaryWsdl,
                metadata,
                null,
                true);
      } catch (WebServiceException e) {
        if (e.getMessage().contains("Not a primary WSDL")) {
          // workaround for WSDLs without service declarations
          wsEndpoint =
              WSEndpoint.create(
                  seiClass,
                  false,
                  invoker,
                  serviceName,
                  portName,
                  endpointContainer,
                  binding,
                  null,
                  metadata,
                  null,
                  true);
        } else {
          throw e;
        }
      }
      wsEndpoint.setExecutor(executorService);

      ServletAdapter adapter =
          servletAdapterFactory.createAdapter(servicePath, servicePath, wsEndpoint);
      delegate.registerServletAdapter(adapter, F3Provider.class.getClassLoader());

      String mexPath = servicePath + MEX_SUFFIX;
      ServletAdapter mexAdapter =
          servletAdapterFactory.createAdapter(mexPath, mexPath, mexEndpoint);
      delegate.registerServletAdapter(mexAdapter, F3Provider.class.getClassLoader());
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }
  public FindAuditEventsResponseType auditQuery(FindAuditEventsRequestType request) {
    String url = null;

    try {
      log.debug(
          "NhincConstants.AUDIT_LOG_ADAPTER_SERVICE_NAME: "
              + NhincConstants.AUDIT_LOG_ADAPTER_SERVICE_NAME);
      url =
          ConnectionManagerCache.getLocalEndpointURLByServiceName(
              NhincConstants.AUDIT_LOG_ADAPTER_SERVICE_NAME);
    } catch (ConnectionManagerException ex) {
      log.error(
          "Error: Failed to retrieve url for service: "
              + NhincConstants.AUDIT_LOG_ADAPTER_SERVICE_NAME
              + " for local home community");
      log.error(ex.getMessage());
    }

    AdapterAuditLogQueryPortType port = getAdapterPort(url);
    FindAuditEventsResponseType resp = null;

    int retryCount =
        gov.hhs.fha.nhinc.webserviceproxy.WebServiceProxyHelper.getInstance().getRetryAttempts();
    int retryDelay =
        gov.hhs.fha.nhinc.webserviceproxy.WebServiceProxyHelper.getInstance().getRetryDelay();
    String exceptionText =
        gov.hhs.fha.nhinc.webserviceproxy.WebServiceProxyHelper.getInstance().getExceptionText();
    javax.xml.ws.WebServiceException catchExp = null;
    if (retryCount > 0
        && retryDelay > 0
        && exceptionText != null
        && !exceptionText.equalsIgnoreCase("")) {
      int i = 1;
      while (i <= retryCount) {
        try {
          resp = port.findAuditEvents(request);
          break;
        } catch (javax.xml.ws.WebServiceException e) {
          catchExp = e;
          int flag = 0;
          StringTokenizer st = new StringTokenizer(exceptionText, ",");
          while (st.hasMoreTokens()) {
            if (e.getMessage().contains(st.nextToken())) {
              flag = 1;
            }
          }
          if (flag == 1) {
            log.warn("Exception calling ... web service: " + e.getMessage());
            System.out.println(
                "retrying the connection for attempt [ "
                    + i
                    + " ] after [ "
                    + retryDelay
                    + " ] seconds");
            log.info(
                "retrying attempt [ "
                    + i
                    + " ] the connection after [ "
                    + retryDelay
                    + " ] seconds");
            i++;
            try {
              Thread.sleep(retryDelay);
            } catch (InterruptedException iEx) {
              log.error(
                  "Thread Got Interrupted while waiting on AdapterAuditLogQuery call :" + iEx);
            } catch (IllegalArgumentException iaEx) {
              log.error(
                  "Thread Got Interrupted while waiting on AdapterAuditLogQuery call :" + iaEx);
            }
            retryDelay = retryDelay + retryDelay; // This is a requirement from Customer
          } else {
            log.error("Unable to call AdapterAuditLogQuery Webservice due to  : " + e);
            throw e;
          }
        }
      }

      if (i > retryCount) {
        log.error("Unable to call AdapterAuditLogQuery Webservice due to  : " + catchExp);
        throw catchExp;
      }

    } else {
      resp = port.findAuditEvents(request);
    }

    return resp;
  }