Examples of ByteArrayWriter


Examples of com.maverick.util.ByteArrayWriter

      // Process destination host and port for replacement variables
      VariableReplacement r = new VariableReplacement();
      r.setLaunchSession(launchSession);
      String destHost = r.replace(tunnel.getDestination().getHost());
     
      ByteArrayWriter msg = new ByteArrayWriter();
     
      try {
       
        msg.writeInt(tunnel.getResourceId());
        msg.writeString(tunnel.getSourceInterface());
        msg.writeString(launchSession.getId());
        msg.writeString(tunnel.getSourceInterface());
        msg.writeInt(tunnel.getSourcePort());
        msg.writeString(destHost);
        msg.writeInt(tunnel.getDestination().getPort());
       
       
        Request request = new Request(TunnelingService.START_REMOTE_TUNNEL, msg.toByteArray());
        agent.sendRequest(request, false);
       
      } catch(IOException ex) {
        ex.printStackTrace();
      }
     
        running = true;
        if (log.isInfoEnabled())
            log.info("Starting remote listener on " + tunnel.getSourcePort());
        try {
            while (running) {
                try {
                    Socket s = listeningSocket.accept();
                    if (log.isInfoEnabled())
                        log.info("Received new connection on " + tunnel.getSourcePort() + " from " + s.getInetAddress());
                    RemoteForwardingChannel channel = new RemoteForwardingChannel(this, s, tunnel, launchSession);
                    try {
                        agent.openChannel(channel);
                    } catch (ChannelOpenException e) {
                        log.error("Error opening channel. Remote tunnel remaining open but closing connection.", e);
                        try {
                            s.close();
                        } catch (IOException ioe) {
                        }
                    }
                } catch (IOException e) {
                    if (running) {
                        log.error("IO error waiting for connection, stopping remote tunnel.", e);
                    }
                }
            }
        } finally {
         
        Request request = new Request(TunnelingService.STOP_REMOTE_TUNNEL, msg.toByteArray());
        try {
        agent.sendRequest(request, false);
      } catch (IOException e) {
      }
       
View Full Code Here

Examples of com.maverick.util.ByteArrayWriter

                  filteredResources.add(resource);
              }
          }
         
          // Send the list of resource IDs and names back to the agent
          ByteArrayWriter response = new ByteArrayWriter();
          response.writeInt(filteredResources.size());
          for (Resource resource : filteredResources) {
            response.writeInt(resource.getResourceId());
            response.writeString(resource.getResourceDisplayName());
          }
          request.setRequestData(response.toByteArray());
          return true;
        }
      } catch (Exception e) {
        log.error("Failed to get resources.", e);
      }
View Full Code Here

Examples of com.maverick.util.ByteArrayWriter

        }
        return sent;
    }
   
    private boolean send(Message message, Recipient recipient, SessionInfo info) throws IOException {
        ByteArrayWriter msg = new ByteArrayWriter();
        msg.writeString(message.getSubject());
        msg.writeInt(0);
        msg.writeString(message.getContent());

        DefaultAgentManager agentManager = DefaultAgentManager.getInstance();
        if (agentManager.hasActiveAgent(info) && info.getUser().getPrincipalName().equals(recipient.getRecipientAlias())) {
            try {
                Request request = new Request("agentMessage", msg.toByteArray());
                AgentTunnel tunnel = agentManager.getAgentBySession(info);
                if (tunnel != null) {
                    tunnel.sendRequest(request, false, 0);
                    return true;
                }
View Full Code Here

Examples of com.maverick.util.ByteArrayWriter

   *         launched
   * @throws Exception
   */
  public Request launchApplication(LaunchSession launchSession) throws Exception {
    ApplicationShortcut shortcut = (ApplicationShortcut) launchSession.getResource();
    ByteArrayWriter msg = new ByteArrayWriter();
   
    // If this is a service side application launcher then launch now and inform the agent not to go any further
    ExtensionDescriptor descriptor = ExtensionStore.getInstance().getExtensionDescriptor(shortcut.getApplication());
    if(((ApplicationLauncherType)descriptor.getExtensionType()).isServerSide()) {
      msg.writeBoolean(true);


      // Do the launch
      try {
        if(descriptor.getApplicationBundle().getStatus() != ExtensionBundleStatus.ACTIVATED) {
          throw new Exception("Extension bundle " + descriptor.getApplicationBundle().getId() +" is not activated, cannot launch applicaiton.");
        }
       
        ((ApplicationLauncherType) descriptor.getExtensionType()).launch(new HashMap<String, String>(),
          descriptor,
          shortcut,
          null,
          launchSession,
          null,
          null);

        CoreServlet.getServlet().fireCoreEvent(new ResourceAccessEvent(this,
                ApplicationShortcutEventConstants.APPLICATION_SHORTCUT_LAUNCHED,
                launchSession.getResource(),
                launchSession.getPolicy(),
                launchSession.getSession(),
                CoreEvent.STATE_SUCCESSFUL).addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_NAME,
          descriptor.getName()).addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_ID, descriptor.getId()));

      } catch (Exception ex) {
        CoreServlet.getServlet().fireCoreEvent(new ResourceAccessEvent(this,
            ApplicationShortcutEventConstants.APPLICATION_SHORTCUT_LAUNCHED,
                launchSession.getSession(),
                ex).addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_NAME, descriptor.getName())
                .addAttribute(CoreAttributeConstants.EVENT_ATTR_APPLICATION_ID, descriptor.getId()));
        throw ex;

      }
    }
    else {   
      msg.writeBoolean(false);
      msg.writeString(shortcut.getApplication());
      msg.writeInt(shortcut.getResourceId());
      msg.writeString(launchSession.getId());
      msg.writeString(ExtensionParser.processApplicationParameters(launchSession,
        new Properties(),
        shortcut.getParameters(),
        shortcut.getApplication()));
    }
   
    return new Request("launchApplication", msg.toByteArray());
  }
View Full Code Here

Examples of com.maverick.util.ByteArrayWriter

     */
    public synchronized boolean processRequest(Request request,
        MultiplexedConnection connection) {
      try {
        notifyAll();
        ByteArrayWriter baw = new ByteArrayWriter();
        try {
          baw.writeString(VersionInfo.getVersion().toString());
          request.setRequestData(baw.toByteArray());
          return true;
        } catch (IOException e) {
          log.error("Failed to send back server version.");
          return false;
        }
View Full Code Here

Examples of com.maverick.util.ByteArrayWriter

      try {
        ByteArrayReader reader = new ByteArrayReader(request.getRequestData());
       
        int type = (int)reader.readInt();
        String name = reader.readString();
        ByteArrayWriter baw = new ByteArrayWriter();
       
        switch(type) {
          case PROFILE:
          {
            baw.writeString(Property.getProperty(new ProfilePropertyKey(name, tunnel.getSession())));
            break;
          }
          case SYSTEM:
          {
            baw.writeString(Property.getProperty(new SystemConfigKey(name)));           
            break;
          }
          case REALM:
          {
            baw.writeString(Property.getProperty(new RealmKey(name, tunnel.getSession().getRealmId())));
          }
          default:
          {
            log.error("Agent requested invalid property type!");
            return false;
          }
        }
       
       
        request.setRequestData(baw.toByteArray());
        return true;
     
      } catch(Exception ex) {
        log.error(ex);
        return false;
View Full Code Here

Examples of com.maverick.util.ByteArrayWriter

        DefaultAgentManager.getInstance().getAgentBroadcastExecutor().execute(new Runnable() {
          public void run() {           
            Collection<AgentTunnel> agents = DefaultAgentManager.getInstance().getAgents();
            synchronized(agents) {
              for(AgentTunnel agent : agents) {
                ByteArrayWriter baw = new ByteArrayWriter();
                try {
                  baw.writeInt(resourceType.getResourceTypeId());
                  synchronized(agent) {
                    agent.sendRequest(new Request(AgentTunnel.UPDATE_RESOURCES_REQUEST, baw.toByteArray()), false);
                  }
                }
                catch(IOException ioe) {
                  log.warn("Failed to send resource update request to agent " + agent.getId() + ".", ioe);
                }
View Full Code Here

Examples of com.sshtools.j2ssh.io.ByteArrayWriter

     *
     * @return
     */
    public byte[] getChannelOpenData() {
        try {
            ByteArrayWriter baw = new ByteArrayWriter();
            baw.writeString(hostToConnectOrBind);
            baw.writeInt(portToConnectOrBind);
            baw.writeString(originatingHost);
            baw.writeInt(originatingPort);

            return baw.toByteArray();
        } catch (IOException ioe) {
            return null;
        }
    }
View Full Code Here

Examples of com.sshtools.j2ssh.io.ByteArrayWriter

        if (x11ForwardingConfiguration == null) {
            throw new ForwardingConfigurationException(
                "X11 forwarding hasn't been enabled.");
        }

        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString(x11ForwardingConfiguration.getAddressToBind());
        baw.writeInt(x11ForwardingConfiguration.getPortToBind());
        x11ForwardingConfiguration.getState().setValue(StartStopState.STARTED);

        if (log.isDebugEnabled()) {
            log.info("X11 forwarding started");
            log.debug("Address to bind: " +
View Full Code Here

Examples of com.sshtools.j2ssh.io.ByteArrayWriter

            throw new ForwardingConfigurationException(
                "The name is not a valid forwarding configuration");
        }

        ForwardingConfiguration config = (ForwardingConfiguration) remoteForwardings.get(name);
        ByteArrayWriter baw = new ByteArrayWriter();
        baw.writeString(config.getAddressToBind());
        baw.writeInt(config.getPortToBind());
        connection.sendGlobalRequest(REMOTE_FORWARD_REQUEST, true,
            baw.toByteArray());
        remoteForwardings.put(name, config);
        config.getState().setValue(StartStopState.STARTED);
        log.info("Remote forwarding configuration '" + name + "' started");

        if (log.isDebugEnabled()) {
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.