protected <T extends Message> T packUnpackAndTest(T message) throws Exception {
   DatagramPacket packet = message.pack();
   T unpackedMessage = Message.unpack(packet);
   Assert.assertEquals(0, unpackedMessage.getEnvObjectID().intValue());
   Assert.assertEquals(4294967295l, unpackedMessage.getSequentialNumber().longValue());
   Assert.assertEquals(65535, unpackedMessage.getPort().intValue());
   Assert.assertEquals(3, unpackedMessage.getProtocolVersion().intValue());
   return unpackedMessage;
 }
Example #2
0
  /**
   * Construct a client-side proxy that implements the named protocol, talking to a server at the
   * named address.
   *
   * @param protocol protocol
   * @param clientVersion client's version
   * @param addr server address
   * @param ticket security ticket
   * @param conf configuration
   * @param factory socket factory
   * @param rpcTimeout max time for each rpc; 0 means no timeout
   * @return the proxy
   * @throws IOException if any error occurs
   */
  @SuppressWarnings("unchecked")
  public static <T extends VersionedProtocol> ProtocolProxy<T> getProtocolProxy(
      Class<T> protocol,
      long clientVersion,
      InetSocketAddress addr,
      UserGroupInformation ticket,
      Configuration conf,
      SocketFactory factory,
      int rpcTimeout)
      throws IOException {
    T proxy =
        (T)
            Proxy.newProxyInstance(
                protocol.getClassLoader(),
                new Class[] {protocol},
                new Invoker(addr, ticket, conf, factory, rpcTimeout, protocol));
    String protocolName = protocol.getName();

    try {
      ProtocolSignature serverInfo =
          proxy.getProtocolSignature(
              protocolName, clientVersion, ProtocolSignature.getFingerprint(protocol.getMethods()));
      return new ProtocolProxy<T>(protocol, proxy, serverInfo.getMethods());
    } catch (RemoteException re) {
      IOException ioe = re.unwrapRemoteException(IOException.class);
      if (ioe.getMessage()
          .startsWith(IOException.class.getName() + ": " + NoSuchMethodException.class.getName())) {
        // Method getProtocolSignature not supported
        long serverVersion = proxy.getProtocolVersion(protocol.getName(), clientVersion);
        if (serverVersion == clientVersion) {
          return new ProtocolProxy<T>(protocol, proxy, null);
        }
        throw new VersionMismatch(protocolName, clientVersion, serverVersion, proxy);
      }
      throw re;
    }
  }
Example #3
0
 public ResponseInfo(HttpResponse paramHttpResponse, T paramT, boolean paramBoolean) {
   this.response = paramHttpResponse;
   this.result = paramT;
   this.resultFormCache = paramBoolean;
   if (paramHttpResponse != null) {
     this.locale = paramHttpResponse.getLocale();
     paramT = paramHttpResponse.getStatusLine();
     if (paramT != null) {
       this.statusCode = paramT.getStatusCode();
       this.protocolVersion = paramT.getProtocolVersion();
     }
     for (this.reasonPhrase = paramT.getReasonPhrase(); ; this.reasonPhrase = null) {
       paramHttpResponse = paramHttpResponse.getEntity();
       if (paramHttpResponse == null) {
         break;
       }
       this.contentLength = paramHttpResponse.getContentLength();
       this.contentType = paramHttpResponse.getContentType();
       this.contentEncoding = paramHttpResponse.getContentEncoding();
       return;
       this.statusCode = 0;
       this.protocolVersion = null;
     }
     this.contentLength = 0L;
     this.contentType = null;
     this.contentEncoding = null;
     return;
   }
   this.locale = null;
   this.statusCode = 0;
   this.protocolVersion = null;
   this.reasonPhrase = null;
   this.contentLength = 0L;
   this.contentType = null;
   this.contentEncoding = null;
 }