// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java
// public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper>
// {
//     final ObjectMapper defaultObjectMapper;
// 
//     public SimpleBankJacksonObjectMapperProvider()
//     {
//         defaultObjectMapper = new ObjectMapper();
//         defaultObjectMapper.registerModule(new JacksonReladomoModule());
//     }
// 
//     @Override
//     public ObjectMapper getContext(Class<?> type)
//     {
//         return defaultObjectMapper;
//     }
// }


import com.gs.fw.common.mithra.MithraManager;
import com.gs.fw.common.mithra.MithraManagerProvider;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import simplebank.serialization.SimpleBankJacksonObjectMapperProvider;
import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
/*
Copyright 2016 Goldman Sachs.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
*/

package simplebank.web;



public class SimpleBankServer
{
    private ResourceConfig config;

    public SimpleBankServer(String runtimeConfigXML) throws Exception
    {
        this.initReladomo(runtimeConfigXML);
    }

    protected void initReladomo(String runtimeConfigXML) throws Exception
    {
        MithraManager mithraManager = MithraManagerProvider.getMithraManager();
        mithraManager.setTransactionTimeout(60 * 1000);
        InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML);
        MithraManagerProvider.getMithraManager().readConfiguration(stream);
        stream.close();
    }

    private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception
    {
        InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName);
        if (stream == null)
        {
            throw new Exception("Failed to locate " + fileName + " in classpath");
        }
        return stream;
    }

    protected void initResources()
    {
        this.config = new ResourceConfig(CustomerResource.class);
        config.register(JacksonFeature.class);
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java
// public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper>
// {
//     final ObjectMapper defaultObjectMapper;
// 
//     public SimpleBankJacksonObjectMapperProvider()
//     {
//         defaultObjectMapper = new ObjectMapper();
//         defaultObjectMapper.registerModule(new JacksonReladomoModule());
//     }
// 
//     @Override
//     public ObjectMapper getContext(Class<?> type)
//     {
//         return defaultObjectMapper;
//     }
// }


// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java
import com.gs.fw.common.mithra.MithraManager;
import com.gs.fw.common.mithra.MithraManagerProvider;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import simplebank.serialization.SimpleBankJacksonObjectMapperProvider;
import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

/*
Copyright 2016 Goldman Sachs.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
*/

package simplebank.web;



public class SimpleBankServer
{
    private ResourceConfig config;

    public SimpleBankServer(String runtimeConfigXML) throws Exception
    {
        this.initReladomo(runtimeConfigXML);
    }

    protected void initReladomo(String runtimeConfigXML) throws Exception
    {
        MithraManager mithraManager = MithraManagerProvider.getMithraManager();
        mithraManager.setTransactionTimeout(60 * 1000);
        InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML);
        MithraManagerProvider.getMithraManager().readConfiguration(stream);
        stream.close();
    }

    private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception
    {
        InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName);
        if (stream == null)
        {
            throw new Exception("Failed to locate " + fileName + " in classpath");
        }
        return stream;
    }

    protected void initResources()
    {
        this.config = new ResourceConfig(CustomerResource.class);
        config.register(JacksonFeature.class);
        config.register(SimpleBankJacksonObjectMapperProvider.class);