Proxy settings for Line applications using heroku, Fixie

Asked 2 years ago, Updated 2 years ago, 128 views

We are building a Line application on heroku.
At that time, I registered Fixie as Addon to secure the IP to access the Line API.

However, the IP address provided by Fixie is not used to operate the Line application. Unable to access Line API.

Please let me know what the problem is with using Proxy using the code below.
The content is a program that returns a user ID string to a user's statement.

Incidentally, the IP address provided by Fixie is already registered with Line developers' Server IP Whitelist on port 24.
Also, if you temporarily add a heroku IP address to the Server IP Whitelist, it works fine, so there is no problem other than Proxy configuration.

@SpringBootApplication
@LineMessageHandler
public class DemoApplication {

    public static void main(String[]args) rows IOException {

        SpringApplication.run (DemoApplication.class, args);
    }

    @Autowired
    private LineMessagingService lineMessagingService;

    @ EventMapping
    public void handleTextMessageEvent(MessageEvent<TextMessageContent>event)rows Exception {

        String channelTtoken=System.getenv("LINE_BOT_CHANNEL_TOKEN");
        String fixieUrl=System.getenv("FIXIE_URL");
        String [ ] fixieValues = fixieUrl.split("[/(:\\/@)/]+");
        String fixieUser=fixieValues[1];
        String fixiePassword=fixieValues[2];
        String fixieHost=fixieValues[3];
        int fixiePort = Integer.parseInt(fixieValues[4]);

        OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
        Authenticator proxyAuthenticator=newAuthenticator(){
            @Override public request authenticate (Route route, Response response) flows IOException {
                String credential = Credentials.basic (fixieUser, fixiePassword);
                return response.request().newBuilder()
                        .header ("Proxy-Authorization", credential)
                        .build();
            }
        };

        Proxy prx = new Proxy (Proxy.Type.HTTP, new InetSocketAddress (fixieHost, fixiePort));
        clientBuilder.proxy(prx).proxyAuthenticator(proxyAuthenticator);

        ReplyMessage replyMessage = new ReplyMessage(event.getReplyToken(),
                Collections.singletonList (new TextMessage(event.getSource().getUserId()));

        retrofit2.Response<BotApiResponse>response=
                LineMessagingServiceBuilder
                        .create(channelTtoken)
                        .okHttpClientBuilder (clientBuilder)
                        .build()
                        .replyMessage (replyMessage)
                        .execute();
        System.out.println("response:"+response.code()+"+response.message());

        final BotApiResponse apiResponse=lineMessagingService
                .replyMessage(newReplyMessage(event.getReplyToken(),
                        Collections.singletonList (new TextMessage(event.getSource().getUserId()))))
                .execute().body();
        System.out.println("Sent messages:"+apiResponse);
    }

    @ EventMapping
    public void defaultMessageEvent(Event event) {
        System.out.println("event:"+event);
    }

}

A large number of error messages were printed.I believe that the error message in question is as follows:

2017-07-27T15:24:31.472775+00:00 app [web.1]:2017-07-2715:24:31.472 INFO4 --- com.linecorp.bot.client.wire: {"message": "Access to this API denied due to the following reason: Your ip address [54.21.not you can use] is 123

Thank you for your cooperation.

java heroku spring-boot

2022-09-30 19:24

1 Answers

http://www.cotegg.com/blog/?p=436

I need to register the callback URL, right?


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.