Search in sources :

Example 11 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class DomainController method updateBundleDirection.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/updateBundleDirection", method = RequestMethod.POST)
public ModelAndView updateBundleDirection(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @RequestParam(required = true) String domainName, @RequestParam(required = true) String bundle, @RequestParam(required = true) String direction, @RequestParam(required = true) String directionValue, HttpSession session, Model model) {
    Collection<TrustBundleDomainReltn> bundles = null;
    try {
        bundles = bundleService.getTrustBundlesByDomain(domainName, false);
    } catch (ServiceException ex) {
        Logger.getLogger(DomainController.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (TrustBundleDomainReltn bundleReltn : bundles) {
        if (bundleReltn.getId() == Long.parseLong(bundle)) {
            if (direction.toLowerCase().equals("incoming")) {
                if (Integer.parseInt(directionValue) == 1) {
                    bundleReltn.setIncoming(true);
                } else {
                    bundleReltn.setIncoming(false);
                }
            } else {
                if (Integer.parseInt(directionValue) == 1) {
                    bundleReltn.setOutgoing(true);
                } else {
                    bundleReltn.setOutgoing(false);
                }
            }
        }
    }
    final ModelAndView mav = new ModelAndView();
    mav.setViewName("updateBundleDirection");
    return mav;
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) TrustBundleDomainReltn(org.nhindirect.config.model.TrustBundleDomainReltn) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class UsecuredServiceRequestBase_checkContentTypeTest method testCheckContentType_incompatibleType_assertServiceException.

@Test
public void testCheckContentType_incompatibleType_assertServiceException() throws Exception {
    MockServiceRequest req = new MockServiceRequest(null, "http://service/svc", "Test");
    Header hdr = mock(Header.class);
    when(hdr.getName()).thenReturn("Content-Type");
    when(hdr.getValue()).thenReturn("text/xml");
    HttpEntity entity = mock(HttpEntity.class);
    when(entity.getContentType()).thenReturn(hdr);
    boolean exceptionOccured = false;
    try {
        req.checkContentType("text/plain", entity);
    } catch (ServiceException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : Header(org.apache.http.Header) HttpEntity(org.apache.http.HttpEntity) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) Test(org.junit.Test)

Example 13 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class UnsecureServiceRequestBase_callTest method testCall_nullRequest_assertServiceException.

@Test
public void testCall_nullRequest_assertServiceException() throws Exception {
    HttpClient mockClient = mock(HttpClient.class);
    StatusLine statLine = mock(StatusLine.class);
    when(statLine.getStatusCode()).thenReturn(204);
    HttpResponse resp = mock(HttpResponse.class);
    when(resp.getStatusLine()).thenReturn(statLine);
    when(mockClient.execute((HttpUriRequest) any())).thenReturn(resp);
    MockServiceRequest req = new MockServiceRequest(mockClient, "http://service/svc", "");
    boolean exceptionOccured = false;
    try {
        req.call();
    } catch (ServiceException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : StatusLine(org.apache.http.StatusLine) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 14 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class NotificationSuppressor method service.

/**
	 * {@inheritDoc}
	 */
@Override
public void service(Mail mail) throws MessagingException {
    boolean suppress = false;
    final MimeMessage msg = mail.getMessage();
    final NHINDAddressCollection recipients = getMailRecipients(mail);
    final NHINDAddress sender = getMailSender(mail);
    final Tx txToTrack = getTxToTrack(msg, sender, recipients);
    if (txToTrack != null) {
        try {
            // first check if this a MDN processed message and if the consume processed flag is turned on
            final TxDetail detail = txToTrack.getDetail(TxDetailType.DISPOSITION);
            if (consumeMDNProcessed && txToTrack.getMsgType() == TxMessageType.MDN && detail != null && detail.getDetailValue().contains(MDNStandard.Disposition_Processed))
                suppress = true;
            else // if the first rule does not apply, then go to the tx Service to see if the message should be suppressed
            if (txService != null && txToTrack != null && txService.suppressNotification(txToTrack))
                suppress = true;
        } catch (ServiceException e) {
            // failing to call the txService should not result in an exception being thrown
            // from this service.
            LOGGER.warn("Failed to get notification suppression status from service.  Message will assume to not need supressing.");
        }
    }
    if (suppress)
        mail.setState(Mail.GHOST);
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) Tx(org.nhindirect.common.tx.model.Tx) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) TxDetail(org.nhindirect.common.tx.model.TxDetail)

Example 15 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class TrackIncomingNotification method service.

/**
	 * {@inheritDoc}
	 */
@Override
public void service(Mail mail) throws MessagingException {
    LOGGER.debug("Calling track incoming notification service");
    final MimeMessage msg = mail.getMessage();
    final NHINDAddressCollection recipients = getMailRecipients(mail);
    final NHINDAddress sender = getMailSender(mail);
    final Tx txToMonitor = getTxToTrack(msg, sender, recipients);
    // track message
    if (txToMonitor != null && (txToMonitor.getMsgType() == TxMessageType.DSN || txToMonitor.getMsgType() == TxMessageType.MDN)) {
        try {
            txService.trackMessage(txToMonitor);
        }///CLOVER:OFF
         catch (ServiceException ex) {
            LOGGER.warn("Failed to submit message to monitoring service.", ex);
        }
    ///CLOVER:ON
    }
    LOGGER.debug("Exiting track incoming notification service");
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) Tx(org.nhindirect.common.tx.model.Tx) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection)

Aggregations

ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)42 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)31 ModelAndView (org.springframework.web.servlet.ModelAndView)31 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)19 IOException (java.io.IOException)18 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)15 X509Certificate (java.security.cert.X509Certificate)12 Certificate (org.nhindirect.config.model.Certificate)12 CertificateForm (org.nhindirect.config.ui.form.CertificateForm)12 ArrayList (java.util.ArrayList)11 Domain (org.nhindirect.config.model.Domain)10 TrustBundleAnchor (org.nhindirect.config.model.TrustBundleAnchor)9 AddressForm (org.nhindirect.config.ui.form.AddressForm)9 AnchorForm (org.nhindirect.config.ui.form.AnchorForm)9 Anchor (org.nhindirect.config.model.Anchor)8 DomainForm (org.nhindirect.config.ui.form.DomainForm)8 SimpleForm (org.nhindirect.config.ui.form.SimpleForm)8 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)7 TrustBundle (org.nhindirect.config.model.TrustBundle)6