unable to connect to Mailchimp services using java wrapper - java

I am using Java wrapper of mailchimp API for converting to inline CSS.
I downloaded the java wrapper and tried with method inlineCss();
I register with Mailchimp and got the Api key.
API Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us1
I am getting the below exception while calling the ping(apiKey) method.
Could you please provide me the solution to resolve this problem.
Exception in thread "main" com.nwire.mailchimp.MailChimpServiceException: Failed to read servers response: api.mailchimp.com
at com.nwire.mailchimp.MailChimpServiceFactory$ClientFactory$1.invoke(MailChimpServiceFactory.java:190)
at $Proxy0.ping(Unknown Source)
at com.nwire.mailchimp.test.InlineTest.initialize(InlineTest.java:44)
at com.nwire.mailchimp.test.InlineTest.run(InlineTest.java:36)
at com.nwire.mailchimp.test.InlineTest.main(InlineTest.java:23)
Below is the code I am using for connecting to Mailchimp.
public void initialize() {
mcServices = MailChimpServiceFactory.getMailChimpServices();
final String ping = mcServices.ping(apiKey);
if (IMailChimpServices.PING_SUCCESS.equals(ping)) {
logger.error("MailChimp connection pinged successfully");
} else {
logger.error("Failed to ping MailChimp, response: " + ping);
}
}
Regards,
Nagesh.

Here is your solution
To support Mailchimp datacenter mapping scheme.
Access the correct datacenter
* http://.api.mailchimp.com/1.2/
* replace with position after dash in Our Api key eg.us1 ,uk2 etc.
Check your Url present in MailChimpServiceFactory class of Java-warapper
by default Java wrapper provides
config.setServerURL(new URL("http://api.mailchimp.com/1.2/"))
changed above url to "http://us1.api.mailchimp.com/1.2/"
for more information visit this link http://www.mailchimp.com/api/1.2/

Related

Using JEST to write to Elasticsearch 7.3 - invalid POST method

I've been attempting to write some info to a working elasticsearch 7.3 cluster using the JEST api. Some resources:
here
Have run into this error message:
Incorrect HTTP method for uri [/my_index] and method [POST], allowed: [GET, DELETE, PUT, HEAD]
Im sending the data as follows:
// write directly to elastic
Map<String, Object>infoMap = new LinkedHashMap();
lagInfoMap.put("type", "consumer");
lagInfoMap.put("topicval", topic);
lagInfoMap.put("groupval", group);
lagInfoMap.put("sumval", sumLag);
try {
jestResult = jestClient.execute(new Index.Builder(infoMap).index("my_index").build());
if(!jestResult.isSucceeded()) {
LOGGER.error(jestResult.toString());
}
} catch(IOException ioe) {
LOGGER.error("Unable to write to elastic", ioe);
return false;
}
Seems like it's wanting a PUT request but it's not clear from the docs (or any examples I can find) how to modify the execute method to do so.
Some days ago I also had the same problem and finally gave up the idea of using JEST for elasticsearch 7.3, from their Github page, it doesn't look like their latest release which is 6.3.1 https://github.com/searchbox-io/Jest/releases , isn't compitable with elasticsearch 7.X.
Elasticsearch 7.X uses the PUT HTTP method to index a document, while the earlier version used the POST method, hence you get the below exception.
Incorrect HTTP method for uri [/my_index] and method [POST], allowed:
[GET, DELETE, PUT, HEAD]
I would suggest, you use elasticsearch official high level java client, instead of JEST, this is being developed activity by the elastic, company behind the elasticsearch.

How to list storage classes using Kubernetes client

I am using below line of code to get details about a particular PVC
response = await `serverModule.kubeclient.api.v1.namespaces(ns).persistentvolumeclaims(pvc).get();`
The corresponding API for above call is readNamespacedPersistentVolumeClaim with below format
GET /api/v1/namespaces/{namespace}/persistentvolumeclaims/{name}
Now, I am trying to call readStorageClass using same convention as above
response = await serverModule.kubeclient.apis.storage.k8s.io.v1.storageclasses(sc).get();
As you can see in the link, GET /apis/storage.k8s.io/v1/storageclasses/{name} is the format, I have used above syntax. But for some reason the code fails with error
Exported kubeclient, ready to process requests
TypeError: Cannot read property 'k8s' of undefined
What is the syntax error that I have made. I tried various combinations but none worked.
This issue is listing PersistentVolumeClaim is a part of coreV1Api of kubernetes and listing StorageClass is the part of StorageV1beta1Api. Following it the simplest code for listing storage class using JAVA client:
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: BearerToken
ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken");
BearerToken.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//BearerToken.setApiKeyPrefix("Token");
StorageV1beta1Api apiInstance = new StorageV1beta1Api();
try {
V1beta1StorageClassList result = apiInstance.listStorageClass();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling StorageV1beta1Api#listStorageClass");
e.printStackTrace();
}
Following is the official documentation link for your reference:
https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/StorageV1beta1Api.md#listStorageClass
Hope this helps.
Use client.apis["storage.k8s.io"].v1.storageclasses.get() , Applicable to any api containing dots.
Hope it helps

Google Drive API Authentication - how to do it and how to implement it?

I'm trying to get the title of a document using the file ID. Here's the code:
private static void printFile(Drive service, String fileId) {
try {
File file = service.files().get(fileId).execute();
System.out.println("Title: " + file.getTitle());
} catch (IOException e) {
System.out.println("An error occured: " + e);
}
}
}
However, when I run it I receive a 403 forbidden error that states, "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
I assume that I have to authenticate, but seeing as I'm completely new to Google Drive API and also java, I'm confused as to how to do this (forgive me). I found this webpage: https://developers.google.com/drive/web/auth/web-server which explains how to authenticate but I'm still confused. The page lists multiple classes that do thing such as exchange the authorization code for an access token and use OAuth 2.0 credentials.
My question is do I need to use all of these classes to authenticate? And how do I implement them into my code?
Here is a brief explanation at the http level.
Any Google Drive REST API call requires an http Authorization: Bearer xxxxxx to be set. If there is no such header, you'll get the 403 you're experiencing
The xxxxx is an access token. There are a myriad ways to get one of these depending on the user experience you want to implement and whether you're trying to access the user's Drive files or the application's. Read the Google docs and experiment with the OAuth Playground.
The Google Java library attempts to abstract all of the above. Whether it does a good job or not is for you to decide. Personally I've had more success calling the REST API directly.

Accessing OneNote API from Java

I am interested in writing a Java application that can access my OneNote notebooks via the OneNote API. I am not sure how to gain access to that API from within Java. Can anybody point me to an example of how to get started here? I use Eclipse as my development environment.
This as straightforward process.
The 3 steps would be:
1) create a OneNote application on the OneNote developper's page. More info here https://dev.onedrive.com/app-registration.htm. This is a one time action.
2) your java application should then provide an authentification mechanism and a tolken-refresh mechanism.
See this post for more info on the authentification mechanism part : Getting a OneNote token with Java. This post is about the OAuth 2.0 flow 'Authorization code grant flow'. More info here https://msdn.microsoft.com/en-us/library/hh243647.aspx#flows
3) your java application calls adhoc API Rest methods to retreive the needed informations.
Example to retrieve all your notebooks (using OkHttp for Http requests):
private final static String NOTEBOOKS_ENDPOINT = "https://www.onenote.com/api/v1.0/me/notes/notebooks";
public Notebooks readAllNoteBooks() {
try {
if (client == null)
client = new OkHttpClient();
Request request = createOneNoteRequest(a_valid_tolken, NOTEBOOKS_ENDPOINT);
Response response = client.newCall(request).execute();
JsonObject content = UrlHelper.parseResponse(response);
System.out.println(content);
return Notebooks.build(content.get("value"));
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Request createOneNoteRequest(String mAccessToken, String url) {
Request.Builder reqBuilder = new Request.Builder();
reqBuilder.url(url);
reqBuilder.header("Authorization", "Bearer " + mAccessToken);
return reqBuilder.build();
}
NoteBooks and NoteBook are 2 tiny classes matching the key attributes from the OneNote objects.
Microsoft has provided REST apis for accessing One note functionalities like creating and accessing notes. See OneNote Rest API reference.
singrass,
In addition to the above replies, the Android OneNote API sample may also help you. There is no OneNote application class that you can create (unless you want to create your own). You simply call the API through the HttpClient. If you are unfamiliar on how to call REST APIs in Java in general, this thread may help you.
-- James

Amazon Product Advertising API request with Java

Hi My code for the same is
// Initialize Web Service
HandlerResolver handlerResolver=new AwsHandlerResolver(credentials.getAWSSecretKey());
AWSECommerceService service = new AWSECommerceService();
service.setHandlerResolver(handlerResolver);
// Create Web Service Connection
AWSECommerceServicePortType port = service.getAWSECommerceServicePort();
// Add Parameters for the Item Lookup
ItemLookupRequest itemLookup = new ItemLookupRequest();
itemLookup.setIdType("ASIN");
itemLookup.getItemId().add("B000RE216U");
// Wrap Request in Lookup Body
ItemLookup lookup = new ItemLookup();
lookup.setAWSAccessKeyId(credentials.getAWSAccessKeyId());
lookup.getRequest().add(itemLookup);
ItemLookupResponse response = port.itemLookup(lookup);
System.out.println("response: " + response.toString());
I keep getting the error cannot convert from Void to AWSECommerceService in the beginning. I have the AWSHandlerResolver file and codec jar installed and configured.
Error Message:
Exception in thread "main" javax.xml.ws.WebServiceException: {http://webservices.amazon.com/AWSECommerceService/2010-11-01}AWSECommerceService is not a valid service. Valid services are: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}AWSECommerceService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.ECS.client.jax.AWSECommerceService.<init>(AWSECommerceService.java:46)
I have been searching online. I might have to change target namespace for AWSECommerceService. But cannot find how. Please help me
You are using the wrong namespace (actually, the wrong version of WS) for your Webservice client and its port.
Go to AWSECommerceService and AWSECommerceServicePortType classes and replace all namespaces which look like http://webservices.amazon.com/AWSECommerceService/2010-11-01 with http://webservices.amazon.com/AWSECommerceService/2013-08-01.

Categories