Example usage for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity

List of usage examples for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods InputStreamRequestEntity InputStreamRequestEntity.

Prototype

public InputStreamRequestEntity(InputStream paramInputStream, String paramString) 

Source Link

Usage

From source file:org.apache.wink.itest.standard.JAXRSReaderTest.java

/**
 * Tests a resource method invoked with a BufferedReader as a parameter.
 * This should fail with a 415 since the reader has no way to necessarily
 * wrap it to the type./*w w w.jav a2  s.c o m*/
 * 
 * @throws HttpException
 * @throws IOException
 */
public void testInputStreamImplementation() throws HttpException, IOException {
    HttpClient client = new HttpClient();

    PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/reader/subclasses/shouldfail");
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    postMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "any/type"));
    try {
        client.executeMethod(postMethod);
        assertEquals(415, postMethod.getStatusCode());
    } finally {
        postMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.standard.JAXRSSourceTest.java

/**
 * Tests a resource method invoked with a SAXSource as a parameter. This
 * should fail with a 415 since the reader has no way to necessarily wrap it
 * to the type.// ww  w  .  j a v a2 s. co  m
 * 
 * @throws HttpException
 * @throws IOException
 */
public void testSourceSubclassImplementation() throws HttpException, IOException {
    HttpClient client = new HttpClient();

    PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/source/subclasses/shouldfail");
    byte[] barr = new byte[1000];
    Random r = new Random();
    r.nextBytes(barr);
    postMethod
            .setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "application/xml"));
    try {
        client.executeMethod(postMethod);
        assertEquals(415, postMethod.getStatusCode());
    } finally {
        postMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.standard.JAXRSStreamingOutputTest.java

/**
 * Tests posting to a StreamingOutput and then returning StreamingOutput.
 * /*from w  ww.ja  v  a2s  .co m*/
 * @throws HttpException
 * @throws IOException
 */
public void testPostStreamingOutput() throws HttpException, IOException {
    HttpClient client = new HttpClient();

    PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/streamingoutput");
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    postMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "text/plain"));
    postMethod.addRequestHeader("Accept", "text/plain");
    try {
        client.executeMethod(postMethod);

        assertEquals(200, postMethod.getStatusCode());
        InputStream is = postMethod.getResponseBodyAsStream();

        byte[] receivedBArr = new byte[barr.length];
        DataInputStream dis = new DataInputStream(is);
        dis.readFully(receivedBArr);

        int checkEOF = dis.read();
        assertEquals(-1, checkEOF);
        for (int c = 0; c < barr.length; ++c) {
            assertEquals(barr[c], receivedBArr[c]);
        }
        assertEquals("text/plain", postMethod.getResponseHeader("Content-Type").getValue());
        Header contentLengthHeader = postMethod.getResponseHeader("Content-Length");
        assertNull(contentLengthHeader == null ? "null" : contentLengthHeader.getValue(), contentLengthHeader);
    } finally {
        postMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.standard.JAXRSStreamingOutputTest.java

/**
 * Tests putting and then getting a StreamingOutput.
 * /*  www .  j a v a  2s.  c  om*/
 * @throws HttpException
 * @throws IOException
 */
public void testPutStreamngOutput() throws HttpException, IOException {
    HttpClient client = new HttpClient();

    PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/streamingoutput");
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "bytes/array"));
    try {
        client.executeMethod(putMethod);
        assertEquals(204, putMethod.getStatusCode());
    } finally {
        putMethod.releaseConnection();
    }

    GetMethod getMethod = new GetMethod(getBaseURI() + "/providers/standard/streamingoutput");
    try {
        client.executeMethod(getMethod);
        assertEquals(200, getMethod.getStatusCode());
        InputStream is = getMethod.getResponseBodyAsStream();

        byte[] receivedBArr = new byte[barr.length];
        DataInputStream dis = new DataInputStream(is);
        dis.readFully(receivedBArr);

        int checkEOF = dis.read();
        assertEquals(-1, checkEOF);
        for (int c = 0; c < barr.length; ++c) {
            assertEquals(barr[c], receivedBArr[c]);
        }

        String contentType = (getMethod.getResponseHeader("Content-Type") == null) ? null
                : getMethod.getResponseHeader("Content-Type").getValue();
        assertNotNull(contentType, contentType);
        Header contentLengthHeader = getMethod.getResponseHeader("Content-Length");
        assertNull(contentLengthHeader == null ? "null" : contentLengthHeader.getValue(), contentLengthHeader);
    } finally {
        getMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.standard.JAXRSStreamingOutputTest.java

/**
 * Tests receiving a StreamingOutput with a non-standard content-type.
 * /*from  w ww  .j  a v a2 s. co  m*/
 * @throws HttpException
 * @throws IOException
 */
public void testWithRequestAcceptHeaderWillReturnRequestedContentType() throws HttpException, IOException {
    HttpClient client = new HttpClient();

    PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/streamingoutput");
    byte[] barr = new byte[100000];
    Random r = new Random();
    r.nextBytes(barr);
    putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "any/type"));
    try {
        client.executeMethod(putMethod);
        assertEquals(204, putMethod.getStatusCode());
    } finally {
        putMethod.releaseConnection();
    }

    GetMethod getMethod = new GetMethod(getBaseURI() + "/providers/standard/streamingoutput");
    getMethod.addRequestHeader("Accept", "mytype/subtype");
    try {
        client.executeMethod(getMethod);
        assertEquals(200, getMethod.getStatusCode());
        InputStream is = getMethod.getResponseBodyAsStream();

        byte[] receivedBArr = new byte[barr.length];
        DataInputStream dis = new DataInputStream(is);
        dis.readFully(receivedBArr);

        int checkEOF = dis.read();
        assertEquals(-1, checkEOF);
        for (int c = 0; c < barr.length; ++c) {
            assertEquals(barr[c], receivedBArr[c]);
        }
        assertEquals("mytype/subtype", getMethod.getResponseHeader("Content-Type").getValue());
        Header contentLengthHeader = getMethod.getResponseHeader("Content-Length");
        assertNull(contentLengthHeader == null ? "null" : contentLengthHeader.getValue(), contentLengthHeader);
    } finally {
        getMethod.releaseConnection();
    }
}

From source file:org.artifactory.cli.rest.RestClient.java

public static byte[] put(String uri, InputStream input, final String inputType, int expectedStatus,
        String expectedResultType, boolean printStream, int timeout, Credentials credentials)
        throws IOException {
    return put(uri, new InputStreamRequestEntity(input, inputType), expectedStatus, expectedResultType,
            printStream, timeout, credentials);
}

From source file:org.bonitasoft.connectors.webdav.exo.ExoUploadFile.java

/**
 * upload the specified file to eXo/*w  w  w  . ja v a2 s  .c om*/
 * 
 * @param destinationUri
 *            -- file's URI in eXo
 * @param file
 *            -- file's local path
 * @param contentType
 * @throws Exception
 */
public void uploadFile(final String destinationUri, final String file, final String contentType)
        throws Exception {

    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("uploadFile '" + file + "' with mimeType '" + contentType + "' to folder '" + destinationUri
                + "'");
    }

    // parse and decode file name
    final String parentUri = destinationUri.substring(0, destinationUri.lastIndexOf("/") + 1);
    String filename = destinationUri.substring(destinationUri.lastIndexOf("/") + 1);
    filename = ExoConnectorUtil.encodeSpecialCharacter(filename);
    filename = java.net.URLEncoder.encode(filename, "UTF-8");

    final PutMethod httpMethod = new PutMethod(parentUri + filename);

    final FileInputStream fis = new FileInputStream(file);
    final RequestEntity requestEntity = new InputStreamRequestEntity(fis, contentType);
    httpMethod.setRequestEntity(requestEntity);

    client.executeMethod(httpMethod);

    processResponse(httpMethod, true);
    httpMethod.releaseConnection();
}

From source file:org.cipango.kaleo.integration.WatcherInfoTest.java

/**
 * <pre>/*from w ww.  j  a v a2 s  .  co m*/
    Alice               Kaleo              SipUnit
  |                   |(1) PUBLISH          |
  |                   |<--------------------|
  |                   |(2) 200 OK           |
  |                   |-------------------->|
  |(3) SUBSCRIBE      |                     |
  |Event:presence     |                     |
  |------------------>|                     |
  |(4) 200 OK         |                     |
  |<------------------|                     |
  |(5) NOTIFY         |                     |
  |<------------------|                     |
  |(6) 200 OK         |                     |
  |------------------>|                     |
  |                   |(7) SUBSCRIBE        |
  |                   |Event:presence.winfo |
  |                   |<--------------------|
  |                   |(8) 200 OK           |
  |                   |-------------------->|
  |                   |(9) NOTIFY           |
  |                   |-------------------->|
  |                   |(10) 200 OK          |
  |                   |<--------------------|
  |                   |(11) HTTP PUT        | Change subscription state from 
  |                   |<--------------------| allow to polite-block
  |                   |(12) 200 OK          |
  |                   |-------------------->|
  |(13) NOTIFY        |                     | Send NOTIFY with neutral state
  |<------------------|                     |
  |(14) 200 OK        |                     |
  |------------------>|                     |
  |                   |(15) NOTIFY          |
  |                   |-------------------->| 
  |                   |(16) 200 OK          |
  |                   |<--------------------|
  |                   |(17) SUBSCRIBE       |
  |                   |Expires = 0          |
  |                   |<--------------------|
  |                   |(18) 200 OK          |
  |                   |-------------------->|
  |                   |(19) NOTIFY          |
  |                   |-------------------->|
  |                   |(20) 200 OK          |
  |                   |<--------------------|
  |(21) SUBSCRIBE     |                     |
  |Expires: 0         |                     |
  |------------------>|                     |
  |(22) 200 OK        |                     |
  |<------------------|                     |
  |(23) NOTIFY        |                     |
  |<------------------|                     |
  |(24) 200 OK        |                     |
  |------------------>|                     |
  |                   |(25) PUBLISH         |
  |                   |Expires = 0          |
  |                   |<--------------------|
  |                   |(26) 200 OK          |
  |                   |-------------------->|
  * </pre>
 */
public void testSubscription3() throws Exception {
    Publisher publisher = new Publisher(getBob().getAor());
    getBob().customize(publisher);
    SipServletRequest request = publisher.newPublish(getClass().getResourceAsStream("publish1.xml"), 60);
    publisher.start(request); // 1
    assertThat(publisher.waitForResponse(), isSuccess()); //2

    Subscriber presence = new Subscriber("presence", getAlice().customize(new Dialog()));
    SipServletResponse response = presence.startSubscription(getAlice().getAor(), getBob().getAor(), 100); //3
    assertThat(response, isSuccess()); //4

    SipServletRequest notify = presence.waitForNotify(); // 5
    notify.createResponse(SipServletResponse.SC_OK).send(); // 6

    Presence presenceDoc = getPresence(notify);
    assertEquals(Basic.OPEN, presenceDoc.getTupleArray()[0].getStatus().getBasic());

    Subscriber winfo = new Subscriber("presence.winfo", getBob().customize(new Dialog()));
    response = winfo.startSubscription(getBob().getAor(), getBob().getAor(), 60); //7
    assertThat(response, isSuccess()); // 8

    notify = winfo.waitForNotify(); //9
    notify.createResponse(SipServletResponse.SC_OK).send(); //10

    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getUri(getBob()), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getUri(getAlice()), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());

    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + BOB_PRES_RULES_URI); // 11

    InputStream is = WatcherInfoTest.class
            .getResourceAsStream("/xcap-root/pres-rules/users/put/elementPoliteBlock.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);

    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();

    notify = presence.waitForNotify(); //13
    notify.createResponse(SipServletResponse.SC_OK).send(); //14

    presenceDoc = getPresence(notify);
    assertEquals(Basic.CLOSED, presenceDoc.getTupleArray()[0].getStatus().getBasic());

    notify = winfo.waitForNotify(); //15
    notify.createResponse(SipServletResponse.SC_OK).send(); //16

    watcherinfo = getWatcherinfo(notify);
    assertEquals(1, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getUri(getBob()), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getUri(getAlice()), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());

    response = winfo.stopSubscription(); //17
    assertThat(response, isSuccess()); //18

    notify = winfo.waitForNotify(); // 19
    notify.createResponse(SipServletResponse.SC_OK).send(); // 20

    response = presence.stopSubscription(); //21
    assertThat(response, isSuccess()); //22

    notify = presence.waitForNotify(); // 23
    notify.createResponse(SipServletResponse.SC_OK).send(); // 24

    publisher.newUnPublish().send();
    assertThat(publisher.waitForResponse(), isSuccess());
}

From source file:org.cipango.kaleo.integration.WatcherInfoTest.java

/**
 * <pre>//ww w  .  j  av  a  2  s . c  o  m
Bob                Kaleo                 Alice
  |                   |(1) PUBLISH          |
  |                   |<--------------------|
  |                   |(2) 200 OK           |
  |                   |-------------------->|
  |(3) SUBSCRIBE      |                     |
  |Event:presence     |                     |
  |Expires: 0         |                     |
  |------------------>|                     |
  |(4) 200 OK         |                     |
  |<------------------|                     |
  |(5) NOTIFY         |                     | In pending state, so basic status is closed
  |<------------------|                     |
  |(6) 200 OK         |                     |
  |------------------>|                     |
  |                   |(7) SUBSCRIBE        |
  |                   |Event:presence.winfo |
  |                   |<--------------------|
  |                   |(8) 200 OK           |
  |                   |-------------------->|
  |                   |(9) NOTIFY           |
  |                   |-------------------->|
  |                   |(10) 200 OK          |
  |                   |<--------------------|
  |                   |(11) HTTP PUT        | Change subscription state from 
  |                   |<--------------------| allow to polite-block
  |                   |(12) 200 OK          |
  |                   |-------------------->|
  |(13) SUBSCRIBE     |                     |
  |Event:presence     |                     |
  |Expires: 0         |                     |
  |------------------>|                     |
  |(14) 200 OK        |                     |
  |<------------------|                     |
  |(15) NOTIFY        |                     |
  |<------------------|                     |
  |(16) 200 OK        |                     |
  |------------------>|                     |
  |                   |(17) PUBLISH         |
  |                   |Expires = 0          |
  |                   |<--------------------|
  |                   |(18) 200 OK          |
  |                   |-------------------->|
  * </pre>
  * Note: Alice and Bob are inverted in this test.
 */
public void testWaitingState() throws Exception {
    Publisher publisher = new Publisher(getAlice().getAor());
    getAlice().customize(publisher);
    SipServletRequest request = publisher.newPublish(getClass().getResourceAsStream("publish1.xml"), 60);
    publisher.start(request); // 1
    assertThat(publisher.waitForResponse(), isSuccess()); //2

    Subscriber presence = new Subscriber("presence", getBob().customize(new Dialog()));
    SipServletResponse response = presence.startSubscription(getBob().getAor(), getAlice().getAor(), 0); //3
    assertThat(response, isSuccess()); //4

    SipServletRequest notify = presence.waitForNotify(); // 5
    notify.createResponse(SipServletResponse.SC_OK).send(); // 6

    Presence presenceDoc = getPresence(notify);
    assertEquals(Basic.CLOSED, presenceDoc.getTupleArray()[0].getStatus().getBasic());

    Subscriber winfo = new Subscriber("presence.winfo", getAlice().customize(new Dialog()));
    response = winfo.startSubscription(getAlice().getAor(), getAlice().getAor(), 60); //7
    assertThat(response, isSuccess()); // 8

    notify = winfo.waitForNotify(); //9
    notify.createResponse(SipServletResponse.SC_OK).send(); //10

    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getUri(getAlice()), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.TIMEOUT, watcher.getEvent());
    assertEquals(getUri(getBob()), watcher.getStringValue());
    assertEquals(Status.WAITING, watcher.getStatus());

    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + ALICE_PRES_RULES_URI); // 11

    InputStream is = WatcherInfoTest.class
            .getResourceAsStream("/xcap-root/pres-rules/users/put/elementCondAliceBob.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);

    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();

    presence = new Subscriber("presence", getBob().customize(new Dialog()));
    response = presence.startSubscription(getBob().getAor(), getAlice().getAor(), 0); // 13
    assertThat(response, isSuccess()); //14

    notify = presence.waitForNotify(); // 15
    notify.createResponse(SipServletResponse.SC_OK).send(); // 16

    presenceDoc = getPresence(notify);
    assertEquals(Basic.OPEN, presenceDoc.getTupleArray()[0].getStatus().getBasic());

    publisher.newUnPublish().send(); // 17
    assertThat(publisher.waitForResponse(), isSuccess()); //18
}

From source file:org.cipango.kaleo.sipunit.WatcherInfoTest.java

/**
 * <pre>//w w w.j av  a 2  s  .  c o  m
    Alice               Kaleo              SipUnit
  |                   |(1) PUBLISH          |
  |                   |<--------------------|
  |                   |(2) 200 OK           |
  |                   |-------------------->|
  |(3) SUBSCRIBE      |                     |
  |Event:presence     |                     |
  |------------------>|                     |
  |(4) 200 OK         |                     |
  |<------------------|                     |
  |(5) NOTIFY         |                     |
  |<------------------|                     |
  |(6) 200 OK         |                     |
  |------------------>|                     |
  |                   |(7) SUBSCRIBE        |
  |                   |Event:presence.winfo |
  |                   |<--------------------|
  |                   |(8) 200 OK           |
  |                   |-------------------->|
  |                   |(9) NOTIFY           |
  |                   |-------------------->|
  |                   |(10) 200 OK          |
  |                   |<--------------------|
  |                   |(11) HTTP PUT        | Change subscription state from 
  |                   |<--------------------| allow to polite-block
  |                   |(12) 200 OK          |
  |                   |-------------------->|
  |(13) NOTIFY        |                     | Send NOTIFY with neutral state
  |<------------------|                     |
  |(14) 200 OK        |                     |
  |------------------>|                     |
  |                   |(15) NOTIFY          |
  |                   |-------------------->| 
  |                   |(16) 200 OK          |
  |                   |<--------------------|
  |                   |(17) SUBSCRIBE       |
  |                   |Expires = 0          |
  |                   |<--------------------|
  |                   |(18) 200 OK          |
  |                   |-------------------->|
  |                   |(19) NOTIFY          |
  |                   |-------------------->|
  |                   |(20) 200 OK          |
  |                   |<--------------------|
  |(21) SUBSCRIBE     |                     |
  |Expires: 0         |                     |
  |------------------>|                     |
  |(22) 200 OK        |                     |
  |<------------------|                     |
  |(23) NOTIFY        |                     |
  |<------------------|                     |
  |(24) 200 OK        |                     |
  |------------------>|                     |
  |                   |(25) PUBLISH         |
  |                   |Expires = 0          |
  |                   |<--------------------|
  |                   |(26) 200 OK          |
  |                   |-------------------->|
  * </pre>
 */
public void testSubscription3() throws Exception {
    PublishSession publishSession = new PublishSession(getBobPhone());
    Request publish = publishSession.newPublish(getClass().getResourceAsStream("publish1.xml"), 60); // 1
    publishSession.sendRequest(publish, SipResponse.OK); // 2

    SubscribeSession presenceSession = new SubscribeSession(getAlicePhone(), "presence");
    Request subscribe = presenceSession.newInitialSubscribe(100, getBobUri()); // 3
    presenceSession.sendRequest(subscribe, Response.OK); // 4

    ServerTransaction tx = presenceSession.waitForNotify(); // 5
    //System.out.println("3:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 6
    Presence presence = getPresence(tx.getRequest());
    assertEquals(Basic.OPEN, presence.getTupleArray()[0].getStatus().getBasic());

    SubscribeSession winfoSession = new SubscribeSession(getBobPhone(), "presence.winfo"); // 7
    subscribe = winfoSession.newInitialSubscribe(60, getBobUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 8

    tx = winfoSession.waitForNotify(); // 9
    Request notify = tx.getRequest();
    //System.out.println(notify);
    winfoSession.sendResponse(Response.OK, tx); // 10 
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME,
            ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getBobUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());

    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + BOB_PRES_RULES_URI); // 11

    InputStream is = WatcherInfoTest.class
            .getResourceAsStream("/xcap-root/pres-rules/users/put/elementPoliteBlock.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);

    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();

    tx = presenceSession.waitForNotify(); // 13
    //System.out.println("11:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 14
    presence = getPresence(tx.getRequest());
    assertEquals(Basic.CLOSED, presence.getTupleArray()[0].getStatus().getBasic());

    tx = winfoSession.waitForNotify(); // 15
    notify = tx.getRequest();
    winfoSession.sendResponse(Response.OK, tx); // 16
    System.out.println(notify);
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME,
            ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    watcherinfo = getWatcherinfo(notify);
    assertEquals(1, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getBobUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());

    subscribe = winfoSession.newSubsequentSubscribe(0); // 17
    winfoSession.sendRequest(subscribe, Response.OK); // 18

    tx = winfoSession.waitForNotify(); // 19
    winfoSession.sendResponse(Response.OK, tx); // 20

    subscribe = presenceSession.newSubsequentSubscribe(0); // 21
    presenceSession.sendRequest(subscribe, Response.OK); // 22

    tx = presenceSession.waitForNotify(); // 23
    presenceSession.sendResponse(Response.OK, tx); // 24

    publish = publishSession.newUnpublish(); // 25
    publishSession.sendRequest(publish, Response.OK); // 26
}