Example #1
0
  @Override
  protected void setProviders(Object... providers) {
    List<ProviderInfo<? extends Object>> theProviders =
        prepareProviders((Object[]) providers, null);
    super.setCommonProviders(theProviders);
    for (ProviderInfo<? extends Object> provider : theProviders) {
      Class<?> providerCls = ClassHelper.getRealClass(provider.getProvider());
      if (filterContractSupported(provider, providerCls, ClientRequestFilter.class)) {
        addProviderToList(clientRequestFilters, provider);
      }

      if (filterContractSupported(provider, providerCls, ClientResponseFilter.class)) {
        addProviderToList(clientResponseFilters, provider);
      }

      if (ResponseExceptionMapper.class.isAssignableFrom(providerCls)) {
        addProviderToList(responseExceptionMappers, provider);
      }
    }
    Collections.sort(
        clientRequestFilters, new BindingPriorityComparator(ClientRequestFilter.class, true));
    Collections.sort(
        clientResponseFilters, new BindingPriorityComparator(ClientResponseFilter.class, false));

    injectContextProxies(responseExceptionMappers, clientRequestFilters, clientResponseFilters);
  }
Example #2
0
 @Override
 public void clearProviders() {
   super.clearProviders();
   responseExceptionMappers.clear();
   clientRequestFilters.clear();
   clientResponseFilters.clear();
 }
  /* (non-Javadoc)
   * @see org.apache.cxf.interceptor.Interceptor#handleMessage(org.apache.cxf.message.Message)
   */
  public void handleMessage(Message message) {
    try {
      if (message != null) {

        List<Object> params = message.getContent(List.class); // parameter instances
        if (params.get(0) instanceof HasXsl) {

          OperationResourceInfo ori = message.getExchange().get(OperationResourceInfo.class);
          JAXBElementProvider provider =
              (JAXBElementProvider)
                  ProviderFactory.getInstance(message)
                      .createMessageBodyWriter(
                          ori.getMethodToInvoke().getReturnType(),
                          ori.getMethodToInvoke().getGenericReturnType(),
                          ori.getMethodToInvoke().getAnnotations(),
                          MediaType.APPLICATION_XML_TYPE,
                          message);
          Map<String, Object> properties = new HashMap<String, Object>();

          HasXsl hasXsl = (HasXsl) params.get(0);
          // System.out.println("Stylesheet params " + hasXsl.getClass() + " " + hasXsl.getXsl());
          if (hasXsl == null || hasXsl.getXsl().equalsIgnoreCase(Constants.NO_XSL)) {
            properties.put(XML_HEADERS, "<!-- no stylesheet -->");
          } else {
            properties.put(
                XML_HEADERS,
                "<?xml-stylesheet type='application/xml' href='" + hasXsl.getXsl() + "'?>");
          }
          provider.setMarshallerProperties(properties);
        }
      }
    } catch (Throwable x) {
      throw new WebApplicationException(Response.status(Status.BAD_REQUEST).build());
    }
  }
Example #4
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();
  }
Example #5
0
 private static synchronized ClientProviderFactory initBaseFactory(Bus bus) {
   ClientProviderFactory factory = (ClientProviderFactory) bus.getProperty(SHARED_CLIENT_FACTORY);
   if (factory != null) {
     return factory;
   }
   factory = new ClientProviderFactory(null, bus);
   ProviderFactory.initBaseFactory(factory);
   bus.setProperty(SHARED_CLIENT_FACTORY, factory);
   return factory;
 }
  @SuppressWarnings("unchecked")
  @Test
  public void testContextResolver() {
    ContextResolver<JAXBContext> resolver = new CustomContextResolver();
    ProviderFactory factory = ServerProviderFactory.getInstance();
    factory.registerUserProvider(resolver);

    Message m = new MessageImpl();
    Exchange ex = new ExchangeImpl();
    m.setExchange(ex);
    ex.setInMessage(m);
    Endpoint e = EasyMock.createMock(Endpoint.class);
    e.get(ServerProviderFactory.class.getName());
    EasyMock.expectLastCall().andReturn(factory);
    EasyMock.replay(e);
    ex.put(Endpoint.class, e);
    MessageContext mc = new MessageContextImpl(m);
    ContextResolver<JAXBContext> resolver2 =
        mc.getResolver(ContextResolver.class, JAXBContext.class);
    assertNotNull(resolver2);
    assertSame(resolver2, resolver);
  }
 private void registerJsonProvider() {
   JSONProvider jsonProvider = new JSONProvider();
   jsonProvider.setSupportUnwrapped(false);
   jsonProvider.setSerializeAsArray(true);
   ProviderFactory.getSharedInstance().registerUserProvider(jsonProvider);
 }