this.conn.setRequestMethod(this.method.toString()); } catch (ProtocolException e) { throw new HttpException(e.getMessage(), e);
this.conn.setRequestMethod(this.method.toString()); } catch (ProtocolException e) { throw new HttpException(e.getMessage(), e);
private Boolean startSLA(String url, String agreementId){ URL slaUrl = null; try { slaUrl = new URL(url+"/modaclouds/"+agreementId+"/start"); HttpURLConnection httpCon = (HttpURLConnection) slaUrl.openConnection(); httpCon.setRequestMethod("PUT"); httpCon.setRequestProperty("Content-Type", "application/json"); httpCon.connect(); if(httpCon.getResponseCode() == 202){ return true; } } catch (MalformedURLException e) { journal.log(Level.SEVERE, e.getMessage()); } catch (ProtocolException e) { journal.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { journal.log(Level.SEVERE, e.getMessage()); } return false; }
public String makeServiceCall(String reqUrl) { String response = null; try { URL url = new URL(reqUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); response = convertStreamToString(in); } catch (MalformedURLException e) { Log.e(TAG, "MalformedURLException: " + e.getMessage()); } catch (ProtocolException e) { Log.e(TAG, "ProtocolException: " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "IOException: " + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Exception: " + e.getMessage()); } return response; }
} catch (ProtocolException var33) { throw new Exception( "Shouldn\'t happen: HttpURLConnection doesn\'t support DELETE?? " + var33.getMessage(), var33);
private InputStream postRequest( CharSequence method, Map<String,String> params, boolean doHttps, boolean doEncode ) throws IOException { CharSequence buffer = ( null == params ) ? "" : delimit( params.entrySet(), "&", "=", doEncode ); URL serverUrl = ( doHttps ) ? HTTPS_SERVER_URL : _serverUrl; if ( log.isDebugEnabled() ) { StringBuilder sb = new StringBuilder(); sb.append( method ); sb.append( " POST: " ); sb.append( serverUrl.toString() ); sb.append( "?" ); sb.append( buffer ); log.debug( sb.toString() ); } HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); if ( this._timeout != -1 ) { conn.setConnectTimeout( this._timeout ); } if ( this._readTimeout != -1 ) { conn.setReadTimeout( this._readTimeout ); } try { conn.setRequestMethod( "POST" ); } catch ( ProtocolException ex ) { log.error( "Exception: " + ex.getMessage(), ex ); } conn.setDoOutput( true ); conn.connect(); conn.getOutputStream().write( buffer.toString().getBytes() ); return conn.getInputStream(); }
private InputStream postRequest( CharSequence method, Map<String,String> params, boolean doHttps, boolean doEncode ) throws IOException { CharSequence buffer = ( null == params ) ? "" : delimit( params.entrySet(), "&", "=", doEncode ); URL serverUrl = ( doHttps ) ? HTTPS_SERVER_URL : _serverUrl; if ( log.isDebugEnabled() ) { StringBuilder sb = new StringBuilder( method ); sb.append( " POST: " ); sb.append( serverUrl.toString() ); sb.append( "?" ); sb.append( buffer ); log.debug( sb.toString() ); } HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); if ( _timeout != -1 ) { conn.setConnectTimeout( _timeout ); } if ( _readTimeout != -1 ) { conn.setReadTimeout( _readTimeout ); } try { conn.setRequestMethod( "POST" ); } catch ( ProtocolException ex ) { log.error( "Exception: " + ex.getMessage(), ex ); } conn.setDoOutput( true ); conn.connect(); conn.getOutputStream().write( buffer.toString().getBytes() ); return conn.getInputStream(); }
return TokenResponse.error("connection_error", ex.getMessage()); } catch (ProtocolException ex) { return TokenResponse.error("protocol_error", ex.getMessage()); } catch (IOException ex) { return TokenResponse.error("io_error", ex.getMessage());
send(output, e.getMessage());
this.conn.setRequestMethod(this.method.toString()); } catch (ProtocolException e) { throw new HttpException(e.getMessage(), e);
this.conn.setRequestMethod(this.method.toString()); } catch (ProtocolException e) { throw new HttpException(e.getMessage(), e);
@Override public void onReceive(MQTTFrame frame) { LOG.info("Client received:\n" + frame); if (frame.messageType() == PUBLISH.TYPE) { PUBLISH publish = new PUBLISH(); try { publish.decode(frame); } catch (ProtocolException e) { fail("Error decoding publish " + e.getMessage()); } publishList.add(publish); } }
ConnectDatum tryConnect(SocketChannel dstSocket) { // Package visibility for testing purposes. final Timer timer = new Timer(); try { dstSocket.connect(dst); return new ConnectDatum(ConnectResult.OK, timer.getAsLong(), Optional.empty()); } catch (SocketTimeoutException | ClosedByInterruptException ex) { return new ConnectDatum(ConnectResult.TIMED_OUT, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (NoRouteToHostException ex) { return new ConnectDatum(ConnectResult.NO_ROUTE_TO_HOST, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (PortUnreachableException ex) { return new ConnectDatum(ConnectResult.PORT_UNREACHABLE, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (UnknownHostException ex) { return new ConnectDatum(ConnectResult.UNKNOWN_HOST, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (UnknownServiceException ex) { return new ConnectDatum(ConnectResult.UNKNOWN_SERVICE, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (ProtocolException ex) { return new ConnectDatum(ConnectResult.PROTOCOL_ERROR, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (BindException ex) { return new ConnectDatum(ConnectResult.BIND_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (ConnectException ex) { // ConnectException and SocketException seem to cover the same error cases..? return new ConnectDatum(ConnectResult.CONNECT_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (SocketException ex) { // ConnectException and SocketException seem to cover the same error cases..? return new ConnectDatum(ConnectResult.CONNECT_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } catch (IOException ex) { return new ConnectDatum(ConnectResult.IO_ERROR, timer.getAsLong(), Optional.ofNullable(ex.getMessage())); } }
@Override public void onReceive(MQTTFrame frame) { LOG.info("Client received:\n" + frame); if (frame.messageType() == PUBLISH.TYPE) { PUBLISH publish = new PUBLISH(); try { publish.decode(frame); } catch (ProtocolException e) { fail("Error decoding publish " + e.getMessage()); } publishList.add(publish); } }
this.conn.setRequestMethod(this.method.toString()); } catch (ProtocolException e) { throw new HttpException(e.getMessage(), e);
@Override public void onReceive(MQTTFrame frame) { LOG.info("Client received:\n" + frame); if (frame.messageType() == PUBLISH.TYPE) { PUBLISH publish = new PUBLISH(); try { publish.decode(frame); LOG.info("PUBLISH " + publish); } catch (ProtocolException e) { fail("Error decoding publish " + e.getMessage()); } if (publishMap.get(publish.messageId()) != null) { assertTrue(publish.dup()); } publishMap.put(publish.messageId(), publish); } }
throw new QuercusModuleException(e.getMessage());
@Override public void onReceive(MQTTFrame frame) { LOG.info("Client received:\n" + frame); if (frame.messageType() == PUBLISH.TYPE) { PUBLISH publish = new PUBLISH(); try { publish.decode(frame); LOG.info("PUBLISH " + publish); } catch (ProtocolException e) { fail("Error decoding publish " + e.getMessage()); } if (publishMap.get(publish.messageId()) != null) { assertTrue(publish.dup()); } publishMap.put(publish.messageId(), publish); } }
@Test public void verifyResponsePayloadSizeLimitChecks() throws Throwable { // set response payload limit to a small number to force error setUpHost(1024 * 50); int sc = this.serviceCount * 2; int versionCount = 2; List<URI> services = createQueryTargetServices(sc); QueryValidationServiceState newState = putStateOnQueryTargetServices( services, versionCount); // now issue a query that will effectively return a result set greater // than the allowed size limit. QueryTask.QuerySpecification q = new QueryTask.QuerySpecification(); q.options = EnumSet.of(QueryOption.EXPAND_CONTENT); q.query.setTermPropertyName(QueryValidationServiceState.FIELD_NAME_TEXT_VALUE) .setTermMatchValue(newState.textValue) .setTermMatchType(MatchType.PHRASE); boolean limitChecked = false; try { createWaitAndValidateQueryTask(versionCount, services, q, true, true); } catch (ProtocolException ex) { assertTrue(ex.getMessage().contains("/core/query-tasks returned error 500 for POST")); limitChecked = true; } assertTrue("Expected QueryTask failure with INTERNAL_SERVER_ERROR because" + "response payload size was over limit.", limitChecked); }
@Test public void verifyResponsePayloadSizeLimitChecks() throws Throwable { // set response payload limit to a small number to force error setUpHost(1024 * 50); int sc = this.serviceCount * 2; int versionCount = 2; List<URI> services = createQueryTargetServices(sc); QueryValidationServiceState newState = putStateOnQueryTargetServices( services, versionCount); // now issue a query that will effectively return a result set greater // than the allowed size limit. QueryTask.QuerySpecification q = new QueryTask.QuerySpecification(); q.options = EnumSet.of(QueryOption.EXPAND_CONTENT); q.query.setTermPropertyName(QueryValidationServiceState.FIELD_NAME_TEXT_VALUE) .setTermMatchValue(newState.textValue) .setTermMatchType(MatchType.PHRASE); boolean limitChecked = false; try { createWaitAndValidateQueryTask(versionCount, services, q, true, true); } catch (ProtocolException ex) { assertTrue(ex.getMessage().contains("/core/query-tasks returned error 500 for POST")); limitChecked = true; } assertTrue("Expected QueryTask failure with INTERNAL_SERVER_ERROR because" + "response payload size was over limit.", limitChecked); }