Configure Proxy under AWS KinesisAsyncClient in java - java

I need to configure proxies for the Kinesis client. Currently I m using KinesisAsyncClient object for performing async operations on the kinesis stream.
After a bit of a search over internet, I came to a conclusion that there is no proper resource which helps to configure proxies over async clients.
So is there any way we can configure the proxy host, port, username, password and non-proxy-hosts under the KinesisAsyncClient object.
Thanks in Advance!

I am able to set Proxy host and port and pass to the KinesisAsyncClient using the following code:
String hostString="127.0.0.1";
int port=8080;
ProxyConfiguration proxyConfiguration =ProxyConfiguration.builder().host(hostString).port(port).build();
SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().proxyConfiguration(proxyConfiguration).build();
KinesisAsyncClient client = KinesisAsyncClient.builder().httpClient(httpClient).build();
Please note I have set a sample hostString and Port.
Hope this helps.

Related

How do you get Client's IP address? (Spring WebFlux WebSocket)

As the title says, how do you obtain the details of the connection so to speak. Is there a way to get it through the WebSocketSession? I feel like I am missing something...
I need a way in order to ban ip addresses of bad users and also I wanted to display all users who are online on a map (like a dot on a map). I don't need help with the later I need help with getting a client's IP address.
I am using Spring's WebFlux WebSocket.
EDIT: I created a feature request : https://jira.spring.io/browse/SWF-1728
The Servlet-based WebSocketSession object does provide that information. This seems to be missing from the reactive flavor.
You should create a Spring Framework issue to request this as an enhancement.
WebSocketSession has a method called getRemoteAddress(), you can get the remote address using any of its implemetation.
you can find ip address using HttpServletRequest for example
String remoteHost = request.getRemoteHost();
String remoteAddr = request.getRemoteAddr();
if (remoteAddr.equals("0:0:0:0:0:0:0:1")) {
InetAddress localip = java.net.InetAddress.getLocalHost();
remoteAddr = localip.getHostAddress();
remoteHost = localip.getHostName();
}
I did it by
public Mono<ServerResponse> hello(ServerRequest request) {
String remoteAddr = request.remoteAddress().get().getAddress().getHostAddress());
return null;
}

java.security.cert.CertificateException: No subject alternative names matching IP address

I have different issues with this exception, Please try to understand.
I'm sending data from one application to another through web service call in Java.
whenever I called it will connect to some other application. in that
a situation I get the above exception, this problem occur only in
byte Grid server.
We solved above problem like this our admin removed security,
means we have https they removed s so we are working with
HTTP, but it's not good, I want to connect through web service call with security, can any one give me the best idea.Please see my sample code
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
String request = PropertyFactory.getProperty("someUrl");
url = new URL(request);
postConnection = (HttpURLConnection) url.openConnection();
can I handle through code?
If you are using Oracle JDK between 1.8.0_51 and 1.8.0_60, there was an issue when connecting via IP address instead of hostname. In the case of using the IP-address, this address also has to be mentioned in the Subject alternative names of the cert. According to Mulesoft Support a workaround would be to set the JVM argument "jdk.tls.trustNameService" to true - resulting in a reverse name lookup for the IP address.
Byte grid having internal firewall so its may be stop, Please contact with byte grid team.

CXF + wsdl2java + authentication

I created the jar from the WSDL for my client using the wsdl2java command. Now, I need to know how I can authenticate my client in order to complete an operation?
I am using CXF 2.7.16. I created my service using the generated class MyApp_Service, I am struggling with this. Isn't there a simple way to tell my client the credentials it should use to gain access to the web service?
I read about the Spring configuration, however I am unable to figure out if it applies to my case and how if yes. I tried to cast the MyApp_Service class to BindingProvider in order to use the method which consist to put the USERNAME and PASSWORD properties in the context with a value. However, MyApp_Service cannot be cast to BindingProvider.
This is my first web service client application ever. So, any help will be welcomed.
Update 2015-05-28: I tried to define the AuthenticationPolicy but is seems not working. Here is the code:
Client client = JaxWsDynamicClientFactory.newInstance().createClient(wsdlUrl);
ClientImpl clt = (ClientImpl) client;
HTTPConduit cc = (HTTPConduit) clt.getConduit();
org.apache.cxf.configuration.security.ObjectFactory secOF = new org.apache.cxf.configuration.security.ObjectFactory();
AuthorizationPolicy ap = secOF.createAuthorizationPolicy();
ap.setUserName(usagerWS);
ap.setPassword(mdpWS);
ap.setAuthorizationType("Basic");
cc.setAuthorization(ap);
Sniffing with WireShark, the Authorization header is clearly missing in the HTTP request.
What is missing?
Problem solved, here is the solution:
MyApp_Service service = new MyApp_Service(wsdlUrl, new QName(namespace, serviceName));
MyApp port = service.getMyApp();
// Set credentials
Map<String, Object> reqCtxt = ((javax.xml.ws.BindingProvider) port).getRequestContext();
reqCtxt.put(javax.xml.ws.BindingProvider.USERNAME_PROPERTY, username);
reqCtxt.put(javax.xml.ws.BindingProvider.PASSWORD_PROPERTY, password);
No more usage of the dynamic client. Only the classes generated with wsdl2java are used.

soap set parameter java

I am implementing a TV listing service and I have decided to use ROVI as my data provider.
They provide me with an API that allows me to exchange data between my application and their servers by means of SOAP requests.
Since I am programming in Java, I used wsimport to generate the classes that would enable me to interact with their server.
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
I have come across a problem which Google doesn't seem to have the answer for.
According to their API, whenever I want to make a call to a SOAP service I have to add my API Key to the end of url.
The problem is, I don't know how to do that. Using the stubs generated by wsimport, I can create a request object as it should be; however the URL is not displayed as per their specification. The url I currently get is: http://api.rovicorp.com/v9/listingsservice.asmx and what is required is: http://api.rovicorp.com/v9/listingsservice.asmx?apikey=myAPIkey. I obtained that by printing the following code:
System.out.println(port.toString());
Trying to run the following code:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Yields the following error:
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 403: Forbidden
What java method can I use to append this parameter into the SOAP request URL.
Thanks for your help.
Edit.
I am still struggling with this and haven't been lucky with responses, if anyone could point me in the direction of a framework or something that could facilitate this would be great!
Cheers
I manage to work around my problem using something called BindingProvider.
I added the following to my code:
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://api.rovicorp.com/v9/listingsservice.asmx?apikey=" + APIKey);
With the aforementioned code the call to the API is successful:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Hope it helps someone in the future.

XMPP Server, smack API connectivity

I am trying to connect to Tigase Server, implement a client in Java using smack API.
ConnectionConfiguration config = new ConnectionConfiguration("192.32.104.93", 5222, "ELVES-D463645");
Connection connection = new XMPPConnection(config);
connection.connect();
When code reaches connect. I get following stacktrace.
stream:error (host-unknown)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:214)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
No response from the server.:
at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:73)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:230)
at org.jivesoftware.smack.Connection.login(Connection.java:366)
at com.directv.xmpp.client.poc.FirstClient.main(FirstClient.java:20)
XMPPException Occured while connecting to server No response from the server.
Can anyone please help me find, where am I going wrong. Thanks!
I found the solution to it.
I was entering the service name and hostname in wrong place.
and because my server is locally hosted. following code stub worked for connection with Tigase Server.
ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222, "yourdomain");
yourdomain shoulde be the domain name which was entered earlier while installation and configuration of the server.
Thank you all for your help though.
ConnectionConfiguration config = new ConnectionConfiguration("192.32.104.93", 5222, "ELVES-D463645");
The serviceName, third argument of the ConnectionConfiguration constructor, seems to be wrong. I would expect something like a domain here (example.com).
You did not even reach the Tigase server. The error appears to be related to either configuration of the DNS or to parameters you pass to the Smack library.
I do not know Smack API but from the error you attach it looks like you provide incorrect hostname, or at least a hostname which does not have a correct DNS entry.
This is fine and you should still be able to connect to the server if you can provide IP address as well.
Try below, or check your XMPP server Authentication setting
ConnectionConfiguration config = new ConnectionConfiguration(XMPP_HOST, XMPP_PORT);
config.setCompressionEnabled(false);
config.setSASLAuthenticationEnabled(false);
connection = new XMPPConnection(config);
Here is a code for Smack 4.3.4
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setHostAddress(InetAddress.getByName(host))
.setXmppDomain(JidCreate.domainBareFrom(Domain))
.setUsernameAndPassword("username", "password")
.setPort(5222)
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(conf);
connection.connect();
connection.login();

Categories

Resources