@Test public void testConvertExpirationParameter() { Injector injector = StartupListener.INJECTOR; QueueResource queueResource = injector.getInstance( QueueResource.class ); Assert.assertNull( queueResource.convertExpirationParameter( "" ) ); Assert.assertNull( queueResource.convertExpirationParameter( "NEVER" ) ); Assert.assertEquals( 5L, queueResource.convertExpirationParameter( "5" ).longValue() ); try { queueResource.convertExpirationParameter( "bogus value" ); fail("Expected exception on bad value"); } catch ( IllegalArgumentException expected ) { } }
Long convertExpirationParameter(String expirationParam) throws IllegalArgumentException { Long expirationSecs = null; if (!QakkaUtils.isNullOrEmpty(expirationParam)) { switch (expirationParam.toUpperCase()) { case "NEVER": case "": expirationSecs = null; break; default: try { expirationSecs = Long.parseLong(expirationParam); } catch (Exception e) { throw new IllegalArgumentException("Invalid expiration parameter"); } break; } } return expirationSecs; }
QueueResource { Long convertExpirationParameter(String expirationParam) throws IllegalArgumentException { Long expirationSecs = null; if (!QakkaUtils.isNullOrEmpty(expirationParam)) { switch (expirationParam.toUpperCase()) { case "NEVER": case "": expirationSecs = null; break; default: try { expirationSecs = Long.parseLong(expirationParam); } catch (Exception e) { throw new IllegalArgumentException("Invalid expiration parameter"); } break; } } return expirationSecs; } }
QueueResource { Long convertExpirationParameter(String expirationParam) throws IllegalArgumentException { Long expirationSecs = null; if (!QakkaUtils.isNullOrEmpty(expirationParam)) { switch (expirationParam.toUpperCase()) { case "NEVER": case "": expirationSecs = null; break; default: try { expirationSecs = Long.parseLong(expirationParam); } catch (Exception e) { throw new IllegalArgumentException("Invalid expiration parameter"); } break; } } return expirationSecs; } @Inject  QueueResource(
            QueueManager              queueManager,
            QueueMessageManager       queueMessageManager,
            URIStrategy               uriStrategy,
            Regions                   regions ); }
QueueResource { Long convertExpirationParameter(String expirationParam) throws IllegalArgumentException { Long expirationSecs = null; if (!QakkaUtils.isNullOrEmpty(expirationParam)) { switch (expirationParam.toUpperCase()) { case "NEVER": case "": expirationSecs = null; break; default: try { expirationSecs = Long.parseLong(expirationParam); } catch (Exception e) { throw new IllegalArgumentException("Invalid expiration parameter"); } break; } } return expirationSecs; } @Inject  QueueResource(
            QueueManager              queueManager,
            QueueMessageManager       queueMessageManager,
            URIStrategy               uriStrategy,
            Regions                   regions ); @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) Response createQueue(Queue queue ); @PUT @Path( "{queueName}/config" ) @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) Response updateQueueConfig( @PathParam("queueName") String queueName, Queue queue); @DELETE @Path( "{queueName}" ) @Produces({MediaType.APPLICATION_JSON}) Response deleteQueue( @PathParam("queueName") String queueName,
                                 @QueryParam("confirm") @DefaultValue("false") Boolean confirmedParam); @GET @Path( "{queueName}/config" ) @Produces({MediaType.APPLICATION_JSON}) Response getQueueConfig( @PathParam("queueName") String queueName); @GET @Produces({MediaType.APPLICATION_JSON}) List<String> getListOfQueues(); @GET @Path( "{queueName}/stats" ) @Produces({MediaType.APPLICATION_JSON}) Response getQueueStats( @PathParam("queueName") String queueName); @POST @Path( "{queueName}/messages" ) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response sendMessageJson(
            @PathParam("queueName")                     String queueName,
            @QueryParam("regions" )   @DefaultValue("") String regionsParam,
            @QueryParam("delay")      @DefaultValue("") String delayParam,
            @QueryParam("expiration") @DefaultValue("") String expirationParam,
                                                        String messageBody); @POST @Path( "{queueName}/messages" ) @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) Response sendMessageBinary(
            @PathParam("queueName")                     String queueName,
            @QueryParam("regions" )   @DefaultValue("") String regionsParam,
            @QueryParam("delay")      @DefaultValue("") String delayParam,
            @QueryParam("expiration") @DefaultValue("") String expirationParam,
            @QueryParam("contentType")                  String actualContentType,
                                                        byte[] messageBody); @GET @Path( "{queueName}/messages" ) @Produces({MediaType.APPLICATION_JSON}) Response getNextMessages( @PathParam("queueName") String queueName,
                                     @QueryParam("count") @DefaultValue("1") String countParam); @DELETE @Path( "{queueName}/messages/{queueMessageId}" ) @Produces({MediaType.APPLICATION_JSON}) Response ackMessage( @PathParam("queueName") String queueName,
                                @PathParam("queueMessageId") String queueMessageId); @GET @Path( "{queueName}/data/{queueMessageId}" ) Response getMessageData(
            @PathParam("queueName") String queueName,
            @PathParam("queueMessageId") String queueMessageIdParam ); }
QueueResource { Long convertExpirationParameter(String expirationParam) throws IllegalArgumentException { Long expirationSecs = null; if (!QakkaUtils.isNullOrEmpty(expirationParam)) { switch (expirationParam.toUpperCase()) { case "NEVER": case "": expirationSecs = null; break; default: try { expirationSecs = Long.parseLong(expirationParam); } catch (Exception e) { throw new IllegalArgumentException("Invalid expiration parameter"); } break; } } return expirationSecs; } @Inject  QueueResource(
            QueueManager              queueManager,
            QueueMessageManager       queueMessageManager,
            URIStrategy               uriStrategy,
            Regions                   regions ); @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) Response createQueue(Queue queue ); @PUT @Path( "{queueName}/config" ) @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) Response updateQueueConfig( @PathParam("queueName") String queueName, Queue queue); @DELETE @Path( "{queueName}" ) @Produces({MediaType.APPLICATION_JSON}) Response deleteQueue( @PathParam("queueName") String queueName,
                                 @QueryParam("confirm") @DefaultValue("false") Boolean confirmedParam); @GET @Path( "{queueName}/config" ) @Produces({MediaType.APPLICATION_JSON}) Response getQueueConfig( @PathParam("queueName") String queueName); @GET @Produces({MediaType.APPLICATION_JSON}) List<String> getListOfQueues(); @GET @Path( "{queueName}/stats" ) @Produces({MediaType.APPLICATION_JSON}) Response getQueueStats( @PathParam("queueName") String queueName); @POST @Path( "{queueName}/messages" ) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response sendMessageJson(
            @PathParam("queueName")                     String queueName,
            @QueryParam("regions" )   @DefaultValue("") String regionsParam,
            @QueryParam("delay")      @DefaultValue("") String delayParam,
            @QueryParam("expiration") @DefaultValue("") String expirationParam,
                                                        String messageBody); @POST @Path( "{queueName}/messages" ) @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) Response sendMessageBinary(
            @PathParam("queueName")                     String queueName,
            @QueryParam("regions" )   @DefaultValue("") String regionsParam,
            @QueryParam("delay")      @DefaultValue("") String delayParam,
            @QueryParam("expiration") @DefaultValue("") String expirationParam,
            @QueryParam("contentType")                  String actualContentType,
                                                        byte[] messageBody); @GET @Path( "{queueName}/messages" ) @Produces({MediaType.APPLICATION_JSON}) Response getNextMessages( @PathParam("queueName") String queueName,
                                     @QueryParam("count") @DefaultValue("1") String countParam); @DELETE @Path( "{queueName}/messages/{queueMessageId}" ) @Produces({MediaType.APPLICATION_JSON}) Response ackMessage( @PathParam("queueName") String queueName,
                                @PathParam("queueMessageId") String queueMessageId); @GET @Path( "{queueName}/data/{queueMessageId}" ) Response getMessageData(
            @PathParam("queueName") String queueName,
            @PathParam("queueMessageId") String queueMessageIdParam );  }