Example usage for java.net ProtocolException ProtocolException

List of usage examples for java.net ProtocolException ProtocolException

Introduction

In this page you can find the example usage for java.net ProtocolException ProtocolException.

Prototype

public ProtocolException() 

Source Link

Document

Constructs a new ProtocolException with no detail message.

Usage

From source file:org.jboss.wise.core.client.impl.wsdlResolver.ConnectionTest.java

@Test(expected = WiseRuntimeException.class)
public void initConnectionShouldThrowWiseRuntimeExceptionWhenGotException() throws Exception {
    HttpURLConnection conn = mock(HttpURLConnection.class);
    doThrow(new ProtocolException()).when(conn).setRequestMethod(anyString());
    connection.initConnection(conn);//from   www  . j a va 2  s . c om
}

From source file:org.wso2.carbon.identity.authenticator.smsotp.SMSOTPAuthenticator.java

/**
 * Send REST call//www  .  j  a v  a  2  s.  c om
 */
public boolean sendRESTCall(String url, String urlParameters) throws IOException {
    HttpsURLConnection connection = null;
    try {
        URL smsProviderUrl = new URL(url + urlParameters);
        connection = (HttpsURLConnection) smsProviderUrl.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod(SMSOTPConstants.HTTP_METHOD);
        if (connection.getResponseCode() == 200) {
            if (log.isDebugEnabled()) {
                log.debug("Code is successfully sent to your mobile number");
            }
            return true;
        }
        connection.disconnect();
    } catch (MalformedURLException e) {
        if (log.isDebugEnabled()) {
            log.error("Invalid URL", e);
        }
        throw new MalformedURLException();
    } catch (ProtocolException e) {
        if (log.isDebugEnabled()) {
            log.error("Error while setting the HTTP method", e);
        }
        throw new ProtocolException();
    } catch (IOException e) {
        if (log.isDebugEnabled()) {
            log.error("Error while getting the HTTP response", e);
        }
        throw new IOException();
    } finally {
        connection.disconnect();
    }
    return false;
}

From source file:org.wso2.carbon.apimgt.core.impl.APIPublisherImplTestCase.java

@Test(description = "Test protocol exception when adding api definition from swagger resource", expectedExceptions = APIManagementException.class)
public void testAddApiDefinitionErrorProtocolException()
        throws APIManagementException, LifecycleException, IOException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    HttpURLConnection httpURLConnection = Mockito.mock(HttpURLConnection.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER))
            .thenReturn(new LifecycleState());
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
    Mockito.doThrow(new ProtocolException()).when(httpURLConnection).setRequestMethod(APIMgtConstants.HTTP_GET);
    apiPublisher.addApiFromDefinition(httpURLConnection);
    Mockito.verify(apiLifecycleManager, Mockito.times(0)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
}