Beispiel #1
0
 public static ClientProviderFactory createInstance(Bus bus) {
   if (bus == null) {
     bus = BusFactory.getThreadDefaultBus();
   }
   ClientProviderFactory baseFactory = initBaseFactory(bus);
   ClientProviderFactory factory = new ClientProviderFactory(baseFactory, bus);
   factory.setBusProviders();
   return factory;
 }
Beispiel #2
0
  protected <T> void writeBody(
      T o, Message outMessage, Class<?> cls, Type type, Annotation[] anns, OutputStream os) {

    if (o == null) {
      return;
    }
    @SuppressWarnings("unchecked")
    MultivaluedMap<String, Object> headers =
        (MultivaluedMap<String, Object>) outMessage.get(Message.PROTOCOL_HEADERS);

    @SuppressWarnings("unchecked")
    Class<T> theClass = (Class<T>) cls;

    MediaType contentType = JAXRSUtils.toMediaType(headers.getFirst("Content-Type").toString());

    List<WriterInterceptor> writers =
        ClientProviderFactory.getInstance(outMessage)
            .createMessageBodyWriterInterceptor(
                theClass, type, anns, contentType, outMessage, null);
    if (writers != null) {
      try {
        JAXRSUtils.writeMessageBody(
            writers, o, theClass, type, anns, contentType, headers, outMessage);

        OutputStream realOs = outMessage.get(OutputStream.class);
        if (realOs != null) {
          realOs.flush();
        }
      } catch (Exception ex) {
        reportMessageHandlerProblem("MSG_WRITER_PROBLEM", cls, contentType, ex);
      }
    } else {
      reportMessageHandlerProblem("NO_MSG_WRITER", cls, contentType, null);
    }
  }
Beispiel #3
0
  protected Object handleResponse(Message outMessage, Class<?> serviceCls) throws Throwable {
    try {
      Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
      ((ResponseImpl) r).setOutMessage(outMessage);
      getState().setResponse(r);

      Method method = outMessage.getExchange().get(Method.class);
      checkResponse(method, r, outMessage);
      if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) {
        return null;
      }
      if (method.getReturnType() == Response.class
          && (r.getEntity() == null
              || InputStream.class.isAssignableFrom(r.getEntity().getClass())
                  && ((InputStream) r.getEntity()).available() == 0)) {
        return r;
      }
      if (PropertyUtils.isTrue(
          super.getConfiguration().getResponseContext().get(BUFFER_PROXY_RESPONSE))) {
        r.bufferEntity();
      }

      Class<?> returnType = method.getReturnType();
      Type genericType =
          InjectionUtils.processGenericTypeIfNeeded(
              serviceCls, returnType, method.getGenericReturnType());
      returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType);
      return readBody(r, outMessage, returnType, genericType, method.getDeclaredAnnotations());
    } finally {
      ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
    }
  }
Beispiel #4
0
    @Override
    public Builder request() {
      checkClosed();

      initTargetClientIfNeeded();

      ClientProviderFactory pf =
          ClientProviderFactory.getInstance(WebClient.getConfig(targetClient).getEndpoint());
      List<Object> providers = new LinkedList<Object>();
      Configuration cfg = configImpl.getConfiguration();
      for (Object p : cfg.getInstances()) {
        if (!(p instanceof Feature)) {
          Map<Class<?>, Integer> contracts = cfg.getContracts(p.getClass());
          if (contracts == null || contracts.isEmpty()) {
            providers.add(p);
          } else {
            providers.add(new FilterProviderInfo<Object>(p, pf.getBus(), contracts));
          }
        }
      }

      pf.setUserProviders(providers);
      WebClient.getConfig(targetClient)
          .getRequestContext()
          .putAll(getConfiguration().getProperties());
      WebClient.getConfig(targetClient)
          .getRequestContext()
          .put(Client.class.getName(), ClientImpl.this);
      WebClient.getConfig(targetClient)
          .getRequestContext()
          .put(Configuration.class.getName(), getConfiguration());
      // TLS
      TLSClientParameters tlsParams = secConfig.getTlsClientParams();
      if (tlsParams.getSSLSocketFactory() != null || tlsParams.getTrustManagers() != null) {
        WebClient.getConfig(targetClient).getHttpConduit().setTlsClientParameters(tlsParams);
      }

      // start building the invocation
      return new InvocationBuilderImpl(WebClient.fromClient(targetClient));
    }
Beispiel #5
0
  protected String convertParamValue(Object pValue, Annotation[] anns) {
    if (pValue == null) {
      return null;
    }
    ProviderFactory pf = ClientProviderFactory.getInstance(cfg.getBus());
    if (pf != null) {
      Class<?> pClass = pValue.getClass();

      @SuppressWarnings("unchecked")
      ParamConverter<Object> prov =
          (ParamConverter<Object>) pf.createParameterHandler(pClass, anns);
      if (prov != null) {
        return prov.toString(pValue);
      }
    }
    return pValue.toString();
  }
Beispiel #6
0
 private static ResponseExceptionMapper<?> findExceptionMapper(Message message, Class<?> exType) {
   ClientProviderFactory pf = ClientProviderFactory.getInstance(message);
   return pf.createResponseExceptionMapper(message, exType);
 }