Search in sources :

Example 16 with ServiceException

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

the class AbstractUnsecuredService_callWithRetryTest method testCallWithRetry_ioException_assertServiceException.

@Test
@SuppressWarnings("unchecked")
public void testCallWithRetry_ioException_assertServiceException() throws Exception {
    HttpClient client = mock(HttpClient.class);
    MockService svc = new MockService("http://localhost/mock", client);
    ServiceRequest<Object, Exception> req = mock(ServiceRequest.class);
    doThrow(new IOException("Pass through")).when(req).call();
    boolean exceptionOccured = false;
    try {
        svc.mockCallNoReturn(req);
    } catch (ServiceException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with ServiceException

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

the class UnsecuredServiceRequestBase method call.

/**
     * {@inheritDoc}}
     */
@Override
public T call() throws E, IOException, ServiceException {
    HttpUriRequest request = createRequest();
    if (request == null)
        throw new ServiceException("Could not create request object");
    HttpResponse response = httpClient.execute(request);
    try {
        final int statusCode = response.getStatusLine().getStatusCode();
        return interpretResponse(statusCode, response);
    } finally {
        closeConnection(response);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) HttpResponse(org.apache.http.HttpResponse)

Example 18 with ServiceException

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

the class AbstractDeleteRequest method createRequest.

/**
    * {@inheritDoc}
    */
@Override
protected final HttpUriRequest createRequest() throws IOException {
    try {
        HttpDelete delete = new HttpDelete(getRequestUri());
        delete.setHeader("Accept", MediaType.APPLICATION_JSON);
        return delete;
    } catch (ServiceException e) {
        throw new IOException("Error creating request URI.", e);
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException)

Example 19 with ServiceException

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

the class AbstractPostRequest method createRequest.

/**
    * {@inheritDoc}
    */
@Override
protected final HttpUriRequest createRequest() throws IOException {
    try {
        HttpPost post = new HttpPost(getRequestUri());
        post.setHeader("Accept", MediaType.APPLICATION_JSON);
        return buildEntityRequest(post, makeContent(), MediaType.APPLICATION_JSON);
    } catch (ServiceException e) {
        throw new IOException("Error creating request URI.", e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException)

Example 20 with ServiceException

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

the class AbstractPutRequest method createRequest.

/**
     * {@inheritDoc}
     */
@Override
protected HttpUriRequest createRequest() throws IOException {
    try {
        HttpPut post = new HttpPut(getRequestUri());
        post.setHeader("Accept", MediaType.APPLICATION_JSON);
        return buildEntityRequest(post, makeContent(), MediaType.APPLICATION_JSON);
    } catch (ServiceException e) {
        throw new IOException("Error creating request URI.", e);
    }
}
Also used : ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut)

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