public void start() {

    // define a JSON provider and a mapping between REST and JSON namespace's
    JSONProvider<IngredientRESTService> jsonProvider = new JSONProvider<IngredientRESTService>();
    Map<String, String> map = new HashMap<String, String>();
    map.put("http://rest.ws.wfm", "{}");
    jsonProvider.setNamespaceMap(map);

    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(IngredientRESTService.class);
    sf.setResourceProvider(
        IngredientRESTService.class,
        new SingletonResourceProvider(new IngredientRESTServiceImpl()));
    sf.setAddress("http://localhost:63083");

    sf.getInFaultInterceptors().add(new LoggingInInterceptor());
    sf.getOutFaultInterceptors().add(new LoggingOutInterceptor());
    sf.getInInterceptors().add(new LoggingInInterceptor());
    sf.getOutInterceptors().add(new LoggingOutInterceptor());
    sf.setProvider(jsonProvider);

    BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
    JAXRSBindingFactory factory = new JAXRSBindingFactory();
    factory.setBus(sf.getBus());
    manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);

    // REST-Service
    this.restserver = sf.create();
    this.restserver.start();
  }
예제 #2
0
  public static List<Object> setupProviders() {
    List<Object> providers = new ArrayList<Object>();
    JSONProvider<OAuthAuthorizationData> jsonP = new JSONProvider<OAuthAuthorizationData>();
    jsonP.setNamespaceMap(
        Collections.singletonMap("http://org.apache.cxf.rs.security.oauth", "ns2"));
    providers.add(jsonP);
    OAuthJSONProvider oauthProvider = new OAuthJSONProvider();
    providers.add(oauthProvider);

    return providers;
  }
예제 #3
0
  private static DemoRestService2 client() {

    final JSONProvider jsonProvider = new JSONProvider();
    jsonProvider.setDropRootElement(true);
    jsonProvider.setSupportUnwrapped(true);
    jsonProvider.setDropCollectionWrapperElement(true);
    jsonProvider.setSerializeAsArray(true);

    final List<JSONProvider> providers = newArrayList(jsonProvider);

    return JAXRSClientFactory.create(
        "http://localhost:8080/rest/v2.0/", DemoRestService2.class, providers);
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public Set<Object> getSingletons() {
    Set<Object> singletons = new HashSet<Object>();
    singletons.add(new XopAttachmentServiceImpl());
    singletons.add(new MultipartsServiceImpl());

    JSONProvider provider = new JSONProvider();
    // equivalent to provider.setIgnoreNamespaces(true);
    provider.setOutTransformElements(Collections.singletonMap("{http://ksoong.org}Book", "Book"));

    provider.setInTransformElements(Collections.singletonMap("Book", "{http://ksoong.org}Book"));

    singletons.add(provider);

    return singletons;
  }
 private JsonPath toJson(final JaxbVideosJson obj) throws Exception {
   final ByteArrayOutputStream baos = new ByteArrayOutputStream();
   jsonProvider.writeTo(
       obj,
       JaxbVideosJson.class,
       JaxbVideosJson.class,
       new Annotation[0],
       MediaType.APPLICATION_JSON_TYPE,
       new MetadataMap<String, Object>(),
       baos);
   return new JsonPath(baos.toString());
 }
 private void registerJsonProvider() {
   JSONProvider jsonProvider = new JSONProvider();
   jsonProvider.setSupportUnwrapped(false);
   jsonProvider.setSerializeAsArray(true);
   ProviderFactory.getSharedInstance().registerUserProvider(jsonProvider);
 }