im working with mailchimp, my objetive is to send users to the list in the mailchimp, so i used a wrapper from ecwid this one
So i did a method that send a test user to my list, i added my list id and my Api Key , but i have an error
this is my code
private void mailchimp(){
MailchimpClient client = new MailchimpClient("MY_API_KEY");
try {
EditMemberMethod.CreateOrUpdate method = new EditMemberMethod.CreateOrUpdate("MY_LIST_ID", "vasya.pupkin#gmail.com");
method.status = "subscribed";
method.merge_fields = new MailchimpObject();
method.merge_fields.mapping.put("FNAME", "Vasya");
method.merge_fields.mapping.put("LNAME", "Pupkin");
MemberInfo member = null;
Log.e("mailchimpmember",""+member);
member = client.execute(method);
} catch (IOException e) {
e.printStackTrace();
} catch (MailchimpException e) {
e.printStackTrace();
}
}
The problem is when i reach this method i get this from Apache in my android monitor at line MailchimpClient client = new MailchimpClient("MY_API_KEY");
No virtual method setConnectionManagerShared(Z)Lorg/apache/http/impl/client/HttpClientBuilder; in class Lorg/apache/http/impl/client/HttpClientBuilder; or its super classes (declaration of 'org.apache.http.impl.client.HttpClientBuilder' appears in /data/app/com.myapp.app.debug-1/split_lib_dependencies_apk.apk:classes78.dex)
at com.ecwid.maleorang.connector.HttpClientConnector.(HttpClientConnector.kt:71)
and this one
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/client/HttpClientBuilder;
im really struggling to get mailchimp running in my project, i cant find a good wrapper and dont know how to properly set it up
thanks
Check this video tutorial about posting new members to MailChimp list
https://www.youtube.com/watch?v=TkRUi_vN12k
Or just try using Volley for the http requests
Related
Following their guide in usage here I couldn't get started.
The code:
KucoinClientBuilder builder = new KucoinClientBuilder()
.withApiKeyVersion(2)
.withBaseUrl("https://openapi-sandbox.kucoin.com")
.withApiKey("MyKey", "MySecret", "MyPass");
KucoinRestClient kucoinRestClient = builder.buildRestClient();
KucoinPrivateWSClient kucoinPrivateWSClient;
try {
kucoinPrivateWSClient = builder.buildPrivateWSClient();
KucoinPublicWSClient kucoinPublicWSClient = builder.buildPublicWSClient();
} catch (IOException e) {
e.printStackTrace();
}
builder.buildPrivateWSClient() throws an exception with this message:
KucoinApiException{code='400003', message='KC-API-KEY not exists'}
I copied the Api Key and Secret and pass from the api page
What am I missing here? Why the KC-API-KEY does not exist?
The "sandbox" account is different than the original account.
Its domain is different and you need to register in the sandbox version of the website here
I am given a shortened url and I want to get the expanded form. The below java function is used to achieve this.
public String expand(String shortenedUrl){
URL url = null;
try {
url = new URL(shortenedUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
// open connection
HttpURLConnection httpURLConnection = null;
try {
httpURLConnection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
} catch (IOException e) {
e.printStackTrace();
}
// stop following browser redirect
httpURLConnection.setInstanceFollowRedirects(false);
// extract location header containing the actual destination URL
String expandedURL = httpURLConnection.getHeaderField("Location");
httpURLConnection.disconnect();
return expandedURL;
}
The code works fine in Eclipse but the same doesn't work in android.
String expandedURL = httpURLConnection.getHeaderField("Location");
The above line throws java.lang.RuntimeException: Unable to start activity ComponentInfo. And the error is pointed to the above line. If I remove the above line no error is encountered. Even I am not able to use getResponseCode() function.
int status = 0;
try {
status = httpURLConnection.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
}
This piece of code also has the same problem. works in eclipse but not in android.
Any kind of help will be greatly appreciated.
Edit: The code using above function is,
ExpandUrl expandUrl = new ExpandUrl();
String expandedUrl = expandUrl.expand(shortenedUrl);
Note: The function expand is defined inside the class ExpandUrl.
Well, the code works in Eclipse but not in android. The reason is that you are doing it in Main thread and blocking it. Android wouldn't allow you to do so and throw runtime error.
I have tried to implement your code using AsyncTask in android. It works fine.
Give it a try.
To know more about AsyncTask follow: Android Documentation on AsyncTask
Good Luck!
I am coding a server application that will receive DFT_P03 messages with an added ZPM segment (which i have created a class for as per the HAPI documentation). Currently i am able to access this field as a generic segment when doing the following :
#Override
public Message processMessage(Message t, Map map) throws ReceivingApplicationException, HL7Exception
{
String encodedMessage = new DefaultHapiContext().getPipeParser().encode(t);
logEntryService.logDebug(LogEntry.CONNECTIVITY, "Received message:\n" + encodedMessage + "\n\n");
try
{
InboundMessage inboundMessage = new InboundMessage();
inboundMessage.setMessageTime(new Date());
inboundMessage.setMessageType("Usage");
DFT_P03 usageMessage = (DFT_P03) t;
Segment ZPMSegment = (Segment)usageMessage.get("ZPM");
inboundMessage.setMessage(usageMessage.toString());
Facility facility = facilityService.findByCode(usageMessage.getMSH().getReceivingFacility().getNamespaceID().getValue());
inboundMessage.setTargetFacility(facility);
String controlID = usageMessage.getMSH().getMessageControlID().encode();
controlID = controlID.substring(controlID.indexOf("^") + 1, controlID.length());
inboundMessage.setControlId(controlID);
Message response;
try
{
inboundMessageService.save(inboundMessage);
response = t.generateACK();
logEntryService.logDebug(LogEntry.CONNECTIVITY, "Message ACKed");
}
catch (Exception ex)
{
response = t.generateACK(AcknowledgmentCode.AE, new HL7Exception(ex));
logEntryService.logDebug(LogEntry.CONNECTIVITY, "Message NACKed");
}
return response;
}
catch (IOException e)
{
logEntryService.logDebug(LogEntry.CONNECTIVITY, "Message rejected");
throw new HL7Exception(e);
}
}
I have created a DFT_P03_Custom class as following :
public class DFT_P03_Custom extends DFT_P03
{
public DFT_P03_Custom() throws HL7Exception
{
this(new DefaultModelClassFactory());
}
public DFT_P03_Custom(ModelClassFactory factory) throws HL7Exception
{
super(factory);
String[] segmentNames = getNames();
int indexOfPid = Arrays.asList(segmentNames).indexOf("FT1");
int index = indexOfPid + 1;
Class<ZPM> type = ZPM.class;
boolean required = true;
boolean repeating = false;
this.add(type, required, repeating, index);
}
public ZPM getZPM()
{
return getTyped("ZPM", ZPM.class);
}
}
When trying to typecast the message to a DFT_P03_Custom instance i get a ClassCastException. As per their documentation, i did create the CustomModelClassFactory class but using this i just get tons of validation errors on the controlId field.
I am already using an identical logic to send custom MFN_M01 messages with an added ZFX segment and that works flawlessly. I understand there is some automatic typecasting being done by HAPI when it receives a DFT_P03 message and that is likely what i need to somehow override for it to be able to give me a DFT_P03_Custom instance instead.
If you have some insight on how i can achieve this without having to use a generic segment instance please help!
Thank you!
I finally figured this out. The only way i got this to work was to generate a conformance profile XML file (using an example message from our application as a base) with the messaging workbench on the HAPI site and use the maven plugin to generate the message and segment classes. Only with these classes am i able to correctly parse a message to my custom class. One thing to note is that it DOES NOT work if i try to use the MSH, PID, PV1 or FT1 classes provided by HAPI and use my Z-segment class. It only works if all the segments are the classes generated by the conformance plugin. This combined with a CustomModelClassFactory class (as shown on the HAPI website) and the proper package structure finally allowed me to access my Z-segment.
that's my first question on stackoverflow ; i need to make a post request (using an inputBean/pojo class for needed paramaters) and get a response (using an outputBean/pojo class to map the json response) using the jira rest api , currently i'm using jersey to do the unmarshallowing thing with json and for annotations, here's the code :
public Resource create(CreateIssueRequest createIssueRequest) {
//creating the issue builder with project key and issuetype
IssueInputBuilder issueBuilder = new IssueInputBuilder(
createIssueRequest.getFields().getProject().getKey()
,createIssueRequest.getFields().getIssueType().getCodeName());
//setting issue fields using the inputBean
issueBuilder.setSummary(createIssueRequest.getFields().getSummary());
issueBuilder.setDescription(createIssueRequest.getFields().getDescription());
//requesting the issue creation method , BasicIssue contains the same fields as my outputbean , this whole thing is the request
BasicIssue issue = jiraClient.getClient().getIssueClient().createIssue(issueBuilder.build()).claim();
//creating the output bean
CreateIssueResponse createIssueResponse = new CreateIssueResponse(
issue.getId(),
issue.getKey(),
issue.getSelf());
try {
jiraClient.getClient().getMetadataClient().getStatus(new URI("localhost:8080/rest/api/2/issue"));
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Resource resource = new Resource();
try {
jiraClient.getClient().close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
resource.setData(createIssueResponse);
return resource;
}
what i managed to achieve using this code is creating an issue and obtaining the corresponding outputbean , what i would like instead is getting a Response instance like a jersey one , which has more information attached to it like the status of that response + the entity response (using this code the only thing i get is the entity) ; i've looked for something similar in the jira rest api but i found nothing .
i might have been unclear , if enyone is willing to help me , i'll be glad to clarify any doubts
api:https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue
i solved surrounding the "post request" with a try catch (when the request doesnt return 201 it throws that exception witch holds some useful data like
try{
issue = jiraClient.getClient().getIssueClient().createIssue(issueBuilder.build()).claim();
}catch(RestClientException e){
ErrorResource error = new ErrorResource();
error.setStatus(e.getStatusCode().get());
error.setDetail(e.getLocalizedMessage());
error.setTitle("An error occurred while creating the issue");
resource.setErrors(new ArrayList<ErrorResource>());
resource.getErrors().add(error);
return resource;
}
As you can see, the official JIRA REST Client abstracts away the response and only gives you the object(s) returned from it.
If you want to keep using the client you need to create a filter or an interceptor or something that catches the response before it gets to the Client.
I am getting the following exception from the mqtt broker when I am trying to create a new MqttClient. The error is here ---
Caused by: Persistence already in use (32200)
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:108) [mqtt-client-0.4.0.jar:]
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:273) [mqtt-client-0.4.0.jar:]
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:222) [mqtt-client-0.4.0.jar:]
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:134) [mqtt-client-0.4.0.jar:]
at com.ericsson.asdp.virtualassist.notification.messaging.MQTTHandler.createClient(MQTTHandler.java:61) [classes:]
at com.ericsson.asdp.virtualassist.notification.messaging.MQTTMessagingService.receieve(MQTTMessagingService.java:52) [classes:]
... 44 more
Here is the code for my java class receive() method from where I am trying to connect to mqtt ---
MqttClient subClient = null;
try {
subClient = mqttHandler.createClient(userId, brokerURL);
MQTTNotificationSubscriber notificationSub = new MQTTNotificationSubscriber(mqttHandler);
notificationSub.setUserId(userId);
subClient.setCallback(notificationSub);
mqttHandler.subscribe(subClient, userId);
// do something here
} catch (Exception e) {
logger.error("Error in receive " + e.getMessage());
throw new VirtualAssistServicesException(e.getMessage(), e);
} finally {
try {
mqttHandler.disconnect(subClient);
} catch (MqttException e) {
throw new VirtualAssistServicesException(e.getMessage(), e);
}
}
And here is the MQTTHandler class createClient() method ---
MqttClient subClient = null;
try {
subClient = new MqttClient(brokerURL, clientId);
} catch (MqttException e) {
}
When I create the client for a userId first time it works. From second time onwards it fails with the above exception. I am using clean-session=false here.
If anyone has any idea please let me know. Thanks.
Looks like both clients are trying to use the same file for persistence.
Javadocs for MqttDefaultFilePersistence.open() says
Initialise the persistent store. If a persistent store exists for this client ID then open it, otherwise create a new one. If the persistent store is already open then just return. An application may use the same client ID to connect to many different servers, so the client ID in conjunction with the connection will uniquely identify the persistence store required.
Throws: MqttPersistenceException - if there was a problem opening the
persistent store.
I suppose the file is already open, you must use a different clientId in your code for each one of your Mqtt clients.
This is because in both client you are using same persistence name.
client = new MqttClient("tcp://192.168.1.100:1883", "One");
In the next thread you are using the same:
client1 = new MqttClient("tcp://192.168.1.100:1883", "One");
The persistence name should be different for each connection you want to make. You have to make change like this in client1:
client = new MqttClient("tcp://192.168.1.100:1883", "Two");