@Test public void testMessageExtractor() { PipelineBuildListener buildListener = new PipelineBuildListener(null); ActiveMQTextMessage textMessage = new ActiveMQTextMessage(); try { textMessage.setText("1"); } catch (MessageNotWriteableException e) { e.printStackTrace(); } assertEquals(1, buildListener.extractBuiltId(textMessage)); try { textMessage.setText("{\"buildId\":\"2\",\"CI\":\"travis-ci.org\"}"); } catch (MessageNotWriteableException e) { e.printStackTrace(); } assertEquals(2, buildListener.extractBuiltId(textMessage)); ActiveMQBytesMessage bytesMessage = new ActiveMQBytesMessage(); bytesMessage.setContent(new ByteSequence("3".getBytes())); bytesMessage.setReadOnlyBody(true); assertEquals(3, buildListener.extractBuiltId(bytesMessage)); ActiveMQBytesMessage bytesMessageInJson = new ActiveMQBytesMessage(); bytesMessageInJson.setContent(new ByteSequence("{\"buildId\":\"4\",\"CI\":\"travis-ci.org\"}".getBytes())); bytesMessageInJson.setReadOnlyBody(true); assertEquals(4, buildListener.extractBuiltId(bytesMessageInJson)); }
public int extractBuiltId(Message message) { String messageText = null; try { if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; messageText = textMessage.getText(); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] data = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(data); messageText = new String(data); } } catch (JMSException e) { e.printStackTrace(); } try { JSONObject jsonObj = new JSONObject(messageText); messageText = jsonObj.getString("buildId"); } catch (JSONException e) { } return Integer.parseInt(messageText); }
PipelineBuildListener implements Listener,MessageListener { public int extractBuiltId(Message message) { String messageText = null; try { if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; messageText = textMessage.getText(); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] data = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(data); messageText = new String(data); } } catch (JMSException e) { e.printStackTrace(); } try { JSONObject jsonObj = new JSONObject(messageText); messageText = jsonObj.getString("buildId"); } catch (JSONException e) { } return Integer.parseInt(messageText); } }
PipelineBuildListener implements Listener,MessageListener { public int extractBuiltId(Message message) { String messageText = null; try { if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; messageText = textMessage.getText(); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] data = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(data); messageText = new String(data); } } catch (JMSException e) { e.printStackTrace(); } try { JSONObject jsonObj = new JSONObject(messageText); messageText = jsonObj.getString("buildId"); } catch (JSONException e) { } return Integer.parseInt(messageText); } PipelineBuildListener(LauncherAPI launcher); }
PipelineBuildListener implements Listener,MessageListener { public int extractBuiltId(Message message) { String messageText = null; try { if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; messageText = textMessage.getText(); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] data = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(data); messageText = new String(data); } } catch (JMSException e) { e.printStackTrace(); } try { JSONObject jsonObj = new JSONObject(messageText); messageText = jsonObj.getString("buildId"); } catch (JSONException e) { } return Integer.parseInt(messageText); } PipelineBuildListener(LauncherAPI launcher); void runListenerServer(); void onMessage(Message message); int extractBuiltId(Message message); void deleteDir(String dirPath); void delete(File file); void submitBuild(String buildStr); }
PipelineBuildListener implements Listener,MessageListener { public int extractBuiltId(Message message) { String messageText = null; try { if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; messageText = textMessage.getText(); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] data = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(data); messageText = new String(data); } } catch (JMSException e) { e.printStackTrace(); } try { JSONObject jsonObj = new JSONObject(messageText); messageText = jsonObj.getString("buildId"); } catch (JSONException e) { } return Integer.parseInt(messageText); } PipelineBuildListener(LauncherAPI launcher); void runListenerServer(); void onMessage(Message message); int extractBuiltId(Message message); void deleteDir(String dirPath); void delete(File file); void submitBuild(String buildStr);  }