Beispiel #1
0
 @Override
 public void read(org.jpac.plc.Connection conn) throws IOException, WrongOrdinaryException {
   Connection ownConn =
       (org.jpac.plc.modbus.Connection) conn; // cast connection to modbus connection
   // wait for response sequence header to load
   // read to byte length of message
   //        try { waitForBytes(ownConn.getInputStream(), 9); }
   //        catch(IOException ex) {
   ////            Log.error("Invalid modbus protocol found while reading ReadRequest response
   // header: ", ex);
   //            Log.error("read failed");
   //            throw ex;
   //        }
   // read to byte length of message
   int transID = ownConn.getInputStream().readUnsignedShort();
   int protocolID = ownConn.getInputStream().readUnsignedShort();
   int field_length = ownConn.getInputStream().readUnsignedShort();
   int unitID = ownConn.getInputStream().readUnsignedByte();
   int functionID = ownConn.getInputStream().readUnsignedByte();
   int byte_count = ownConn.getInputStream().readUnsignedByte();
   if (!(functionID == Modbus.MODBUS_FUNCTIONCODE_WRITECOILS
       || functionID == Modbus.MODBUS_FUNCTIONCODE_WRITEMULTIPLEREGISTERS)) {
     // Modbus exception received
     throw new IOException(
         "Modbus response for functionID "
             + functionID
             + " returned with error code "
             + byte_count);
   }
 }
 @Override
 protected Object attemptReadResponse(Connection cnx) throws Exception {
   Message msg = createResponseMessage();
   if (msg != null) {
     msg.setComms(
         cnx.getSocket(),
         cnx.getInputStream(),
         cnx.getOutputStream(),
         cnx.getCommBuffer(),
         cnx.getStats());
     if (msg instanceof ChunkedMessage) {
       try {
         return processResponse(cnx, msg);
       } finally {
         msg.unsetComms();
         processSecureBytes(cnx, msg);
       }
     } else {
       try {
         msg.recv();
       } finally {
         msg.unsetComms();
         processSecureBytes(cnx, msg);
       }
       return processResponse(cnx, msg);
     }
   } else {
     return null;
   }
 }
  @Test
  public void proxy1() throws Exception {
    String repoPath = "target/localrepo_" + UUID.randomUUID();

    Properties properties = new Properties();
    properties.setProperty(TEST_PID + "." + ServiceConstants.PROPERTY_LOCAL_REPOSITORY, repoPath);
    properties.setProperty(
        TEST_PID + "." + ServiceConstants.PROPERTY_REPOSITORIES, "http://qfdqfqfqf.fra@id=fake");

    File file = new File("target/test-classes/settings-mirror-proxy.xml");
    MavenConfiguration config = UnitHelp.getConfig(file, properties);
    File localRepo = new File(repoPath);
    // you must exist.
    localRepo.mkdirs();

    Connection c =
        new Connection(
            new URL(null, "mvn:ant/ant/1.5.1", new org.ops4j.pax.url.mvn.Handler()),
            new AetherBasedResolver(config));
    c.getInputStream();

    assertEquals(
        "the artifact must be downloaded",
        true,
        new File(localRepo, "ant/ant/1.5.1/ant-1.5.1.jar").exists());

    // test for PAXURL-209
    assertThat(System.getProperty("http.proxyHost"), is(nullValue()));
  }
Beispiel #4
0
 @Override
 public void write(org.jpac.plc.Connection conn) throws IOException {
   // write request to output stream
   Connection ownConn =
       (org.jpac.plc.modbus.Connection) conn; // cast connection to modbus connection
   ownConn.getOutputStream().writeShort(Modbus.getNextTransactionID());
   ownConn.getOutputStream().writeShort(0); // protocol identifier is always 0 for MODBUS/TCP
   ownConn.getOutputStream().writeShort(getDataLength() + 7);
   ownConn
       .getOutputStream()
       .writeByte(0); // unit identifier is not used and will therefore always be 0
   ownConn.getOutputStream().writeByte(getFunctionCode());
   // empty input stream before new request written
   ownConn.getInputStream().skipBytes(ownConn.getInputStream().available());
   writeData(conn);
   ownConn.getOutputStream().flush();
 }
Beispiel #5
0
  /**
   * Handle the response from a request.
   *
   * @throws ResponseException if there is a problem reading the response
   */
  private void handleResponse() throws ResponseException, CommandAbortedException {
    try {
      LoggedDataInputStream dis = connection.getInputStream();
      loggedDataInputStream = dis;

      int ch = -1;
      try {
        ch = dis.read();
      } catch (InterruptedIOException ex) {
        abort();
      }

      while (!abort && ch != -1) {
        StringBuffer responseNameBuffer = new StringBuffer();
        // read in the response name
        while (ch != -1 && (char) ch != '\n' && (char) ch != ' ') {
          responseNameBuffer.append((char) ch);
          try {
            ch = dis.read();
          } catch (InterruptedIOException ex) {
            abort();
            break;
          }
        }

        String responseString = responseNameBuffer.toString();
        Response response = getResponseFactory().createResponse(responseString);
        // Logger.logInput(new String("<" + responseString + " processing start>\n").getBytes()); //
        // NOI18N
        response.process(dis, this);
        boolean terminal = response.isTerminalResponse();

        // handle SpecialResponses
        if (terminal && response instanceof ErrorMessageResponse) {
          ErrorMessageResponse errorResponce = (ErrorMessageResponse) response;
          String errMsg = errorResponce.getMessage();
          throw new CommandAbortedException(errMsg, errMsg);
        }
        // Logger.logInput(new String("<" + responseString + " processed " + terminal +
        // ">\n").getBytes()); // NOI18N
        if (terminal || abort) {
          break;
        }

        try {
          ch = dis.read();
        } catch (InterruptedIOException ex) {
          abort();
          break;
        }
      }

      if (abort) {
        String localMsg = CommandException.getLocalMessage("Client.commandAborted", null); // NOI18N
        throw new CommandAbortedException("Aborted during request processing", localMsg); // NOI18N
      }
    } catch (EOFException ex) {
      throw new ResponseException(
          ex, ResponseException.getLocalMessage("CommandException.EndOfFile", null)); // NOI18N
    } catch (IOException ex) {
      throw new ResponseException(ex);
    }
  }