aileron.cc このページをアンテナに追加 RSSフィード

2010-04-10

[][][] catalyst で 強引にフォワードさせてみたかった。

package specification::View::Forward;

use strict;
use HTTP::Request;
use HTTP::Response;
use LWP::UserAgent;
use base qw( Catalyst::View );

__PACKAGE__->mk_accessors('forwardurl');

=head1 NAME

specification::View::Forward

=head1 DESCRIPTION

=head1 AUTHOR

=head1 SEE ALSO

L<specification>

speee

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

sub new 
{
    my($class, $c, $arguments) = @_;
    my $self = $class->next::method($c);
                return $self;
}

sub process 
{
    my ( $self, $c ) = @_;
    my $url = $c->stash->{forwardurl};
    my $ua = new LWP::UserAgent;
    my $req = HTTP::Request->new('GET' => $url);
    my $res = $ua->request($req);
    $c->response->body($res->content);
}
1;

[] webアプリケーション開発時にクライアント認証部分とか意識するのは、いやだ

クライアントの認証部分を開発するのが嫌だから、前段のwebサーバで行いたい。

クライアント -> フロントwebサーバ -> アプリケーションサーバ

の流れでリクエストが伝搬されていく際に

フロントのwebサーバで認証処理を行って、アプリケーションサーバ

httpリクエストが伝搬される際に、httpのヘッダ情報を拡張して

クライアントのIDを付与する

アプリケーションサーバでは、クライアントのIDを取得するだけになるので

追加でアプリケーションを開発する際の認証処理をあまり考慮しなくて済む。

2010-04-05

[][][][] maven2wtp プロジェクトで困った場合

mvn eclipse:clean

mvn -Dwtpversion=2.0 eclipse:eclipse

maven2コマンドラインから使用して、eclipseの設定ファイルを再度生成しなおす。

eclipse上のmaven2プラグインは、偶に謎の挙動をする為

maven2コマンドラインに頼る方が簡単。

2010-03-24

[][] h2db de fizzbuzz

select
    s.X as id , l.label
from
    SYSTEM_RANGE(1,
    100) as s 
left join
    (
        select
            3 as X,
            'fizz' as label 
        union
        select
            9 as X,
            'fizz' as label
        union
        select
            12 as X,
            'fizz' as label
        union
        select
            5 as X ,
            'buzz' as label
        union
        select
            10 as X ,
            'buzz' as label
        union
        select
            0 as X ,
            'fizzbuzz' as label
    ) l 
        on (
            mod(s.X, 15) = l.X 
        )
order by id

2010-03-16

[] java 問題

1) java.lang.Iterable<T> インタフェースを実装し、FizzBuzzを実装せよ

2) 下記プログラムを実行した際の、三個所の if 文について説明せよ

/**
 * @author aileron
 */
public class EqTest
{
    /**
     * @param args
     */
    public static void main(final String... args)
    {
        final String test1 = test1();
        final String test3 = test3();
        final String test2 = "AAAA";

        System.out.println("test1 : " + test1);
        System.out.println("test2 : " + test2);
        System.out.println("test3 : " + test3);

        if (test1.equals(test2))
        {
            System.out.println("test1 eq test2");
        }

        if (test1 == test2)
        {
            System.out.println("test1 == test2");
        }

        if (test1 == test3)
        {
            System.out.println("test1 == test3");
        }
    }

    /**
     * @return test1
     */
    private static String test1()
    {
        return "AAAA";
    }

    /**
     * @return test3
     */
    private static String test3()
    {
        String test3 = "";
        for (int i = 0; i < 4; i++)
        {
            test3 += "A";
        }
        return test3;
    }
}

3) 下記プログラムの実行結果をしめせ

public class RecTest
{
    /**
     * @param args
     */
    public static void main(final String... args)
    {
        final List<String> list = new ArrayList<String>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        list.add("ddd");
        list.add("eeee");
        final int result = rec(list);
        System.out.println(result);
    }

    /**
     * @param args
     * @return ok
     */
    public static int rec(final List<String> args)
    {
        final String arg = args.get(args.size() - 1);
        System.out.println(arg);

        if (args.size() == 1)
        {
            return 2;
        }
        final List<String> subList = args.subList(0, args.size() - 1);
        final int result = rec(subList);
        return result * 2;
    }
}

2010-03-10

[] java 修得度問題

1)Javaのプロセスに対してSIGQUITシグナルを送った時の動作を説明してください。


2)public static void main 関数を実装し
  Bをインスタンス化し、標準出力に "20-test" と出力される様にせよ

package sample;
class A<A>
{
    class B<B>
    {
        public void out()
        {
            System.out.print(a);
            System.out.print("-");
            System.out.println(b);
        }

        private A a;
        private B b;
    }

    /**
     * @param args
     */
    public static void main(final String... args)
    {
    }
}

3)public static void main を 実行した結果
  hoge
  fuga
  hogehoge
  になるように enum B の コンストラクタは修正せず 実装せよ

package sample;

class A
{
    static interface AA
    {
        String value();
    }

    enum B implements AA
    {
        A,

        B,

        C;

        private B()
        {
        }
    }

    /**
     * 
     * 
     * @param args
     */
    public static void main(final String... args)
    {
        System.out.println(B.A.value());
        System.out.println(B.B.value());
        System.out.println(B.C.value());
    }
}





4)本プログラムを実行した結果を示せ

package sample;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@B(C.class)
public class A
{
    /**
     * @param args
     * @throws Exception
     */
    public static void main(final String... args) throws Exception
    {
        System.out.println(C.class.getAnnotation(B.class)
                .value()
                .getAnnotation(B.class)
                .value()
                .newInstance()
                .value());
    }

    /**
     * @return label
     */
    public String label()
    {
        return "fuga";
    }

    /**
     * @return value
     * @throws Exception
     */
    public String value() throws Exception
    {
        return this.getClass()
                .getAnnotation(B.class)
                .value()
                .newInstance()
                .getClass()
                .getAnnotation(B.class)
                .value()
                .newInstance()
                .value();
    }
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface B
{
    String lable() default "hogexhoge";

    Class<? extends A> value() default A.class;
}

@B(D.class)
class C extends A
{
    /**
     * @return label
     */
    @Override
    public String label()
    {
        return "hogahoga";
    }

    /**
     * @return value
     */
    @Override
    public String value()
    {
        return "fugafuga";
    }
}

@B
class D extends A
{
}