CPD Results

The following document contains the results of PMD's CPD 4.1.

Duplications

File Line
org\apache\commons\messagelet\impl\HttpMessageletResponseImpl.java 45
org\apache\commons\messagelet\impl\MessageletResponseImpl.java 45
    public MessageletResponseImpl(ServletResponse response) {
        super(response);
    }

    /** Resets the response, ready for a new request */
    public void reset() {
        writer = null;
        stream = null;
    }
    
    /** Called to finish the request */
    public void finish() throws IOException, JMSException {
        try {
            if ( writer != null ) {
                writer.flush();
                writer.close();
            }
            if ( stream != null ) {
                byte[] data = stream.toByteArray();

                // for now assume a text message
                String text = new String(data);
                Message message = getReplyMessenger().createTextMessage( text );
                sendReply( message );
            }
        }
        finally {
            writer = null;
            stream = null;
        }
    }
    
    // MessageletResponse methods
    //-------------------------------------------------------------------------    
    
    /** Sends a reply to the original message */
    public void sendReply(Message replyMessage) throws JMSException {
        getReplyMessenger().send( getReplyToDestination(), replyMessage );
    }
    
    public Messenger getReplyMessenger() {
        return messenger;
    }
    
    public Destination getReplyToDestination() {
        return replyToDestination;
    }
    
    public void setReplyMessenger(Messenger messenger) {
        this.messenger = messenger;
    }
    
    public void setReplyToDestination(Destination replyToDestination) {
        this.replyToDestination = replyToDestination;
    }
    
    
    // Implementation methods
    //-------------------------------------------------------------------------    
    
    public void flushBuffer() throws IOException {
        if ( stream != null ) {
            stream.flush();
        }
    }
    
    public ServletOutputStream getOutputStream() throws IOException {
        if (writer != null) {
            throw new IllegalStateException("getWriter() has already been called " +
            "for this response");
        }
        if (stream == null) {
            stream = createOutputStream();
        }
        return stream;
    }
    
    public PrintWriter getWriter() throws IOException {
        if (writer != null) {
            return writer;
        }        
        if (stream != null) {
            throw new IllegalStateException("getOutputStream() has already been called for this response");
        }        
        stream = createOutputStream();
        writer = new PrintWriter(stream);
        return writer;
    }
    
    protected BufferedServletOutputStream createOutputStream() {
        return new BufferedServletOutputStream();
    }
}

File Line
org\apache\commons\messenger\task\ConsumerTask.java 58
org\apache\commons\messenger\task\ProducerTask.java 61
    }

    public Messenger getMessenger() throws JMSException {
        if ( messenger == null ) {
            messenger = getMessengerManager().getMessenger( getMessengerName() );
        }
        return messenger;
    }
    
    /** Sets the Messenger to be used */
    public void setMessenger(Messenger messenger) {
        this.messenger = messenger;
    }
    
    /** Getter for property messengerName.
     * @return Value of property messengerName.
     */
    public String getMessengerName() {
        return messengerName;
    }

    /** Setter for property messengerName.
     * @param messengerName New value of property messengerName.
     */
    public void setMessengerName(String messengerName) {
        this.messengerName = messengerName;
    }

    /** Getter for property destination.
     * @return Value of property destination.
     */
    public Destination getDestination() throws JMSException {
        if ( destination == null ) {
            destination = getMessenger().getDestination( getSubject() );
        }
        return destination;
    }

    /** Setter for property destination.
     * @param destination New value of property destination.
     */
    public void setDestination(Destination destination) {
        this.destination = destination;
    }

    /** Getter for property subject.
     * @return Value of property subject.
     */
    public String getSubject() {
        return subject;
    }

    /** Setter for property subject.
     * @param subject New value of property subject.
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }
    
    
    /** Getter for property messengerManager.
     * @return Value of property messengerManager.
     */
    public MessengerManager getMessengerManager() {
        return messengerManager;
    }
    
    /** Setter for property messengerManager.
     * @param messengerManager New value of property messengerManager.
     */
    public void setMessengerManager(MessengerManager messengerManager) {
        this.messengerManager = messengerManager;
    }

    /** 
     * Sets the URI of the Messenger.xml configuration document to use
     * to configure the messengers to use for this task.
     */
    public void setConfiguration(String uri) throws JMSException {
        setMessengerManager( MessengerManager.load( uri ) );
    }
    
    /** Getter for property sleep, which defines the number of milliseconds to 
     * sleep for before each send.
     * @return Value of property sleep.
     */
    public long getSleep() {

File Line
org\apache\commons\messagelet\impl\HttpMessageletRequestImpl.java 39
org\apache\commons\messagelet\impl\MessageletRequestImpl.java 38
    public MessageletRequestImpl(ServletRequest request) {
        super(request);
    }

    public void setMessage(Message message) throws JMSException {
        this.message = message;
        this.stream = createInputStream();
        
        // also publish the message as a request scope attribute
        setAttribute( "message", message );
    }

    public void setMessenger(Messenger messenger) {
        setAttribute( "messenger", messenger );
    }

    // MessageletRequest methods
    //-------------------------------------------------------------------------    
    
    /** @return the Message which originated this request */
    public Message getMessage() {
        return message;
    }

    
    // ServletRequest methods
    //-------------------------------------------------------------------------    

    public ServletInputStream getInputStream() {
        return stream;
    }

    public BufferedReader getReader() {
        return new BufferedReader( new InputStreamReader( stream ) );
    }

    // Implementation methods
    //-------------------------------------------------------------------------    


    protected ServletInputStream createInputStream() throws JMSException {
        if ( message instanceof TextMessage ) {
            TextMessage textMessage = (TextMessage) message;
            return new BufferedServletInputStream( textMessage.getText() );
        }
        
        // ##### handle ByteMessage and StreamMessage somehow one day?
        return new BufferedServletInputStream();
    }
    
}

File Line
org\apache\commons\messenger\tool\Caller.java 37
org\apache\commons\messenger\tool\Consumer.java 38
            Producer client = new Producer();
            client.run( args );
        }
        catch (JMSException e) {
            System.out.println( "Caught: " + e );
            Exception linked = e.getLinkedException();
            if ( linked != null ) {
                System.out.println( "Underlying exception: " + linked );
                linked.printStackTrace();
            }
            else {
                e.printStackTrace();
            }
        }
        catch (Exception e) {
            System.out.println( "Caught: " + e );
            e.printStackTrace();
        }
    }
    
    public void run(String[] args) throws Exception {
        if ( args.length < 2 ) {
            System.out.println( "Usage: Producer messengerName destination [fileName]" );