Examples of IEncoderDecoder


Examples of org.serviceconnector.net.IEncoderDecoder

   * Description: Encode body types test<br>
   * Expectation: passes
   */
  @Test
  public void t25_EncodeBodyTypesTest() {
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPPart(SCMPVersion.CURRENT));

    String header = "msn=" + msgSequenceNr + "\n" + "bty=" + bodyType.getValue() + "\n" + "mty=" + msgType.getValue() + "\n";

    String expectedString = TestUtil.getSCMPString(headKey, header, body);

    OutputStream os = new ByteArrayOutputStream();
    try {
      coder.encode(os, encodeScmp);
    } catch (Exception e) {
      Assert.fail("Should not throw exception");
    }
    Assert.assertEquals(expectedString, os.toString());

    coder = coderFactory.createEncoderDecoder(encodeScmp);
    bodyType = SCMPBodyType.TEXT;
    encodeScmp.setHeader(SCMPHeaderAttributeKey.BODY_TYPE, bodyType.getValue());

    header = "msn=" + msgSequenceNr + "\n" + "bty=" + bodyType.getValue() + "\n" + "mty=" + msgType.getValue() + "\n";

    expectedString = TestUtil.getSCMPString(headKey, header, body);

    os = new ByteArrayOutputStream();
    try {
      coder.encode(os, encodeScmp);
    } catch (Exception e) {
      Assert.fail("Should not throw exception");
    }
    Assert.assertEquals(expectedString, os.toString());
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    IEncoderDecoder encoderDecoder = null;
    SCMPMessage scReply = null;
    SCMPMessage reqMessage = null;
    try {
      byte[] buffer = new byte[request.getContentLength()];
      request.getInputStream().read(buffer);
      Statistics.getInstance().incrementTotalMessages(buffer.length);
      if (ConnectionLogger.isEnabledFull()) {
        ConnectionLogger.logReadBuffer(this.getClass().getSimpleName(), request.getServerName(), request.getServerPort(),
            buffer, 0, buffer.length);
      }
      ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
      encoderDecoder = AppContext.getEncoderDecoderFactory().createEncoderDecoder(buffer);
      reqMessage = (SCMPMessage) encoderDecoder.decode(bais);

      if (reqMessage.isKeepAlive() == true) {
        // keep alive received, just reply nothing more to do.
        reqMessage.setIsReply(true);
        // write reply to servlet output stream
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

   *            the message
   * @param response
   *            the response
   */
  private void writeResponse(SCMPMessage requestMessage, SCMPMessage responseMessage, HttpServletResponse response) {
    IEncoderDecoder encoderDecoder;
    try {
      if (responseMessage.isLargeMessage()) {
        // response is large create a large response for reply
        SCMPCompositeSender largeResponse = new SCMPCompositeSender(responseMessage);
        SCMPMessage firstSCMP = largeResponse.getFirst();
        SCMPMessageSequenceNr messageSequenceNr = this.requester.getSCMPMsgSequenceNr();
        firstSCMP.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, messageSequenceNr.incrementAndGetMsgSequenceNr());
        int oti = requestMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
        // adding compositeReceiver to the composite registry
        SCBaseServlet.compositeRegistry.addSCMPLargeResponse(requestMessage.getSessionId(), largeResponse, oti);
        responseMessage = firstSCMP;
      }
      encoderDecoder = AppContext.getEncoderDecoderFactory().createEncoderDecoder(responseMessage);
      encoderDecoder.encode(response.getOutputStream(), responseMessage);
      response.flushBuffer();
    } catch (Exception e) {
      LOGGER.error("Encoding message and replying to SC failed.", e);
    }
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

    String requestString = TestUtil.getSCMPString(headKey, null, null);

    byte[] buffer = requestString.getBytes();
    InputStream is = new ByteArrayInputStream(buffer);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPKeepAlive(SCMPVersion.CURRENT));

    SCMPMessage message = null;
    try {
      message = (SCMPMessage) coder.decode(is);
    } catch (Exception e) {
      Assert.fail("Should not throw exception");
    }
    verifySCMP(message);
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

    this.headKey = SCMPHeaderKey.KRS;
    String requestString = headKey.name() + " 0000000 00000 1.0\n";

    byte[] buffer = requestString.getBytes();
    InputStream is = new ByteArrayInputStream(buffer);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPKeepAlive(SCMPVersion.CURRENT));

    SCMPMessage message = null;
    try {
      message = (SCMPMessage) coder.decode(is);
    } catch (Exception e) {
      Assert.fail("Should not throw exception");
    }
    verifySCMP(message);
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

   */
  @Test
  public void t10_EncodeKRQTest() {
    this.headKey = SCMPHeaderKey.KRQ;
    this.encodeScmp = new SCMPKeepAlive(SCMPVersion.CURRENT);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPKeepAlive(SCMPVersion.CURRENT));

    String expectedString = this.headKey.name() + " 0000000 00000 " + SCMPVersion.CURRENT + "\n";

    OutputStream os = new ByteArrayOutputStream();
    try {
      coder.encode(os, encodeScmp);
    } catch (Exception e) {
      Assert.fail("Should not throw exception");
    }
    Assert.assertEquals(expectedString, os.toString());
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

   */
  @Test
  public void t11_EncodeKRSTest() {
    this.headKey = SCMPHeaderKey.KRS;
    this.encodeScmp = new SCMPKeepAlive(SCMPVersion.CURRENT);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPKeepAlive(SCMPVersion.CURRENT));

    String expectedString = this.headKey.name() + " 0000000 00000 " + SCMPVersion.CURRENT + "\n";

    OutputStream os = new ByteArrayOutputStream();
    try {
      encodeScmp.setIsReply(true);
      coder.encode(os, encodeScmp);
    } catch (Exception e) {
      Assert.fail("Should not throw exception");
    }
    Assert.assertEquals(expectedString, os.toString());
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

  public void t01_InvalidSCMPVersionFormatTest() {
    String requestString = "REQ 0000053 00053 xxx\nldt=2010-08-02T11:24:52.093+0200\nver=1.0-000\nmty=ATT";

    byte[] buffer = requestString.getBytes();
    InputStream is = new ByteArrayInputStream(buffer);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPPart(SCMPVersion.CURRENT));

    try {
      coder.decode(is);
      Assert.fail("Should throw exception");
    } catch (Exception e) {
      Assert.assertEquals("Incompatible SCMP release nr. [xxx]", e.getMessage());
    }
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

  public void t02_InvalidSCMPVersion9_9Test() {
    String requestString = "REQ 0000053 00053 9.9\nldt=2010-08-02T11:24:52.093+0200\nver=1.0-000\nmty=ATT";

    byte[] buffer = requestString.getBytes();
    InputStream is = new ByteArrayInputStream(buffer);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPPart(SCMPVersion.CURRENT));

    try {
      coder.decode(is);
      Assert.fail("Should throw exception");
    } catch (Exception e) {
      Assert.assertEquals("Incompatible SCMP release nr. [9.9]", e.getMessage());
    }
  }
View Full Code Here

Examples of org.serviceconnector.net.IEncoderDecoder

  public void t03_InvalidSCMPVersion0_9Test() {
    String requestString = "REQ 0000053 00053 0.9\nldt=2010-08-02T11:24:52.093+0200\nver=1.0-000\nmty=ATT";

    byte[] buffer = requestString.getBytes();
    InputStream is = new ByteArrayInputStream(buffer);
    IEncoderDecoder coder = coderFactory.createEncoderDecoder(new SCMPPart(SCMPVersion.CURRENT));

    try {
      coder.decode(is);
      Assert.fail("Should throw exception");
    } catch (Exception e) {
      Assert.assertEquals("Incompatible SCMP release nr. [0.9]", e.getMessage());
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.