如何配置camel jetty生产者端点以使用SSL证书

时间:2015-04-16 22:44:11

标签: ssl jetty akka typesafe-stack

Camel jetty端点允许多个SSL选项,但仅适用于消费者(即服务器端)。见Apache Camel Jetty

有没有办法强制生产者使用证书而无需编写一堆代码?远程服务器需要客户端身份验证。

1 个答案:

答案 0 :(得分:0)

看起来编码是唯一的选择。我尝试过两种选择:将SSL配置为(1)JettyComponent或(2)https4组件。

column = []
for line in open('name,score.txt','r').readlines():
    column.append(line.strip().split(':')[1])
column_int = map(int, column)
print "average = ", sum(column_int)/float(len(column_int))

}

或者

public class Main {

    public static void main(String args[]) {
        final Queue<Integer> sharedQ = new LinkedList<Integer>();
        Thread waiter = new Waiter(sharedQ);
        Thread chef = new Chef(sharedQ);
        waiter.start();
        chef.start();
    }
}

class Items{
    String[] items = {" ", "Sandwich",  "Cereal", "Coffee", "Pizza"};
    int[] time = {0,5,3,3,7};

    String getItem(int value){
        return items[value];
    }

    int getTime(int value){
        return time[value];
    }
}

class Waiter extends Thread{
    private final Queue<Integer> sharedQ;
    static int ord = 0;
    Items item = new Items();
    SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss aa");
    public Waiter(Queue<Integer> sharedQ) {
        super("Waiter");
        this.sharedQ = sharedQ;
    }

    @Override
    public void run() {
        int choice = 1;
        Scanner in = new Scanner(System.in);
        while(choice >= 1 && choice <= 4) {
            synchronized (sharedQ) {
                System.out.print("Enter item id :");
                choice = in.nextInt();
                if(choice >= 1 && choice <= 4){
                    ord++;
                    System.out.println("Order Number: ORD"+ord+" for " + item.getItem(choice)+" has been placed at +"+dateFormat.format(new Date()).toString());
                    sharedQ.add(choice);
                    sharedQ.notifyAll();
                }
            }
        }
    }
}

class Chef extends Thread{
    private final Queue<Integer> sharedQ;
    Items item = new Items();
    static int ord = 0;
    SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss aa");
    public Chef(Queue<Integer> sharedQ) {
        super("Chef");
        this.sharedQ = sharedQ;
    }

    @Override
    public void run() {
        int choice;
        while(true) {
            try{
                synchronized (sharedQ) {
                //waiting condition - wait until Queue is not empty
                    while (sharedQ.size() == 0) {
                        sharedQ.wait();
                    }
                    System.out.println(sharedQ.size());
                    choice = sharedQ.poll();
                    System.out.println("abc");
                    ord++;
                    System.out.println("Chef : Picked up ORD"+ord+" at "+ dateFormat.format(new Date()).toString());
                    System.out.println("Chef: Cooking "+item.getItem(choice));
                    Thread.sleep(60*1000*item.getTime(choice));
                    System.out.println("Chef : Finished making "+item.getItem(choice)+" at "+ dateFormat.format(new Date()).toString());
                    sharedQ.notify();
                }
            }
            catch (InterruptedException ex) {
                System.out.println("Exception in chef function");
            }
        }
    }
}

}

然后端点URL可以是:

def configJetty = {
  println("Configuring Jetty component...")

  val ksp = new KeyStoreParameters()
  ksp.setResource(keyStore)
  ksp.setPassword(keyPassword)

  val kmp = new KeyManagersParameters()
  kmp.setKeyStore(ksp)
  kmp.setKeyPassword(keyPassword)

  val scp = new SSLContextParameters()
  scp.setKeyManagers(kmp)

  val jettyComponent = camelContext.getComponent("jetty").asInstanceOf[JettyHttpComponent]
  jettyComponent.setSslContextParameters(scp)

def configHttps4 = {
  println("Configuring HTTPS4 component...")

  val ksp = new KeyStoreParameters()
  ksp.setResource(keyStore)
  ksp.setPassword(keyPassword)

  val tsp = new KeyStoreParameters()
  tsp.setResource(trustStore)
  tsp.setPassword(trustPassword)


  val kmp = new KeyManagersParameters()
  kmp.setKeyStore(ksp)
  kmp.setKeyPassword(keyPassword)

  val tmp = new TrustManagersParameters()
  tmp.setKeyStore(tsp)

  val scp = new SSLContextParameters()
  scp.setKeyManagers(kmp)
  scp.setTrustManagers(tmp)

  val httpComponent = camelContext.getComponent("https4").asInstanceOf[HttpComponent]
  httpComponent.setSslContextParameters(scp)

注意:使用上面的代码,jetty组件将不再能说清楚HTTP。