Error while creating bug in Bugzilla using Java - java

while trying to create a new bug in bugzilla, i am getting an error
"You must log in before using this part of Bugzilla"
Code looks like
`HttpClient httpClient = new HttpClient();
XmlRpcClient rpcClient = new XmlRpcClient();
XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
factory.setHttpClient(httpClient);
rpcClient.setTransportFactory(factory);
config.setServerURL(new URL("http://192.168.0.203/xmlrpc.cgi"));
rpcClient.setConfig(config);
// map of the login data
Map<String, String> loginMap = new HashMap<String, String>();
loginMap.put("login", "bugzilla.admin#abcd.com");
loginMap.put("password", "bugzilla#admin");
loginMap.put("rememberlogin", "Bugzilla_remember");
// login to bugzilla
Object loginResult = rpcClient.execute("User.login", new Object[]{loginMap});
System.err.println ("loginResult=" + loginResult);
// map of the bug data
Map<String, String> bugMap = new HashMap<String, String>();
bugMap.put("product", "Demo");
bugMap.put("component", "Demo_project");
bugMap.put("summary", "Bug created for test");
bugMap.put("description", "This is text ");
bugMap.put("version", "unspecified");
bugMap.put("op_sys", "Windows");
bugMap.put("platform", "PC");
bugMap.put("priority", "P2");
bugMap.put("severity", "Normal");
bugMap.put("status", "NEW");
// create bug
Object createResult = rpcClient.execute("Bug.create", new Object[]{bugMap});
System.err.println("createResult = " + createResult);
`
At first i am able to login and the response I get is-: loginResult={id=1, token=1-AJ4uG13zlJ}
but when creating a new bug error occurs
`Exception in thread "main" org.apache.xmlrpc.XmlRpcException: You must log in before using this part of Bugzilla.
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
at com.abcd.BugCreator2.main(BugCreator2.java:52)`
Why do I get this error of login again, when I am already logged in.
Edit-:
The above code works fine when tried on https://bugzilla.mozilla.org
It seems there is some problem while configuration of Bugzilla on local server.

first of all thanks to you i was searching code just like yours...
and if you still get that error you should know that you also need to send login and password parameters for create method.
just try like this ..
add this
bugMap.put("login", "bugzilla.admin#abcd.com");
bugMap.put("password", "bugzilla#admin");
before this
bugMap.put("product", "Demo");
bugMap.put("component", "Demo_project");
bugMap.put("summary", "Bug created for test");
bugMap.put("description", "This is text ");
bugMap.put("version", "unspecified");
bugMap.put("op_sys", "Windows");
bugMap.put("platform", "PC");
bugMap.put("priority", "P2");
bugMap.put("severity", "Normal");
bugMap.put("status", "NEW");

Related

Adding card source works in 19.45.0, fails in 20.0.0 and above

I am playing with Stripe-Java and I'm trying to add a card to a customer.
My code looks like this:
Customer stripeCustomer = Customer.retrieve("cus_xxxxxxx");
Map<String, Object> cardParam = new HashMap<String, Object>();
cardParam.put("number", "4242424242424242");
cardParam.put("exp_month", "11");
cardParam.put("exp_year", "2022");
cardParam.put("cvc", "123");
//token
Map<String, Object> tokenParam = new HashMap<String, Object>();
tokenParam.put("card", cardParam);
Token token = Token.create(tokenParam);
//user token
Map<String, Object> sourceParam = new HashMap<String, Object>();
sourceParam.put("source", token.getId());
//add to customer
stripeCustomer.getSources().create(sourceParam);
This works successfully on Stripe-Java version 19.45.0 but not on 20.0.0 or any versions above. Has the method to add a card changed?
A nullpointer exception is thrown
Thanks
This : stripeCustomer.getSources() will be null in v20.0.0 and above of the library because it pins to API version 2020-08-27 where customer.sources was removed by default. [0] [1]
The sources property on Customers is no longer included by default.
You can expand the list but for performance reasons we recommended
against doing so unless needed.
You would need to explicitly expand [2] "sources" when retrieving the Customer in order to populate customer.getSources()
CustomerRetrieveParams params = CustomerRetrieveParams.builder()
.addExpand("sources").build();
Customer stripeCustomer = Customer.retrieve("cus_xxxxxxx", params, null);
Also, your code uses the legacy Token API, and is passing raw card details from your server that puts you in PCI scope, you should look into the recommended integration paths : https://stripe.com/docs/payments/accept-a-payment
[0] https://github.com/stripe/stripe-java/blob/master/CHANGELOG.md#2000---2020-08-31
[1] https://stripe.com/docs/upgrades#2020-08-27
[2] https://stripe.com/docs/expand

Magento SOAP WSDL JAVA - create product

I'm new using magento api, so I generate the classes using Eclipse.
create -> new -> other -> WebService client / put de magento api wsdl.
then Eclipse creates for me the classes.
I can list all catalog_products.list using the api.
But I dont know how to create a product using the api "catalog_product.create"
I am following this docummentation to create a product but there's only example in PHP.
https://devdocs.magento.com/guides/m1x/api/soap/catalog/catalogProduct/catalog_product.create.html
here's my code.
public void consumirWebService() throws Exception {
BindingStub service = (BindingStub) new MagentoServiceLocator().getPort();
String token = service.login("user", "password");
Map<String, String>[] mapss = new Map[1];
Map<String, String> mapProduto = new HashMap<String, String>();
mapProduto.put("type", "virtual");
mapProduto.put("sessionId", "1");
mapProduto.put("set", "4");
mapProduto.put("sku", "7622300243449");
mapProduto.put("storeView", "1");
mapProduto.put("name", "NOME PRODUTO");
mapProduto.put("description", "descricao");
mapProduto.put("short_description", "short description");
mapProduto.put("weight", "1");
mapProduto.put("status", "1");
mapProduto.put("price", "100");
mapProduto.put("visibility", "4");
mapProduto.put("tax_class_id", "1");
mapProduto.put("website_ids", "1");
mapProduto.put("categories_ids", "1");
mapss[0] = mapProduto;
Object o = service.call(token, "catalog_product.create", mapss);
System.out.println("ID" + o);
}
i get this exception always :
Invalid data given. Details in error message.
Can anyone help me please
The example should be enough to understand how you create something with a SOAP Client. The names of the methods and classes are all the same , only different langauge. Try to find the equivalent of each inside your generated java classes.

How to add Notes of a contact with Infusionsoft CRM API in Java

In Infusionsoft CRM, there is a field of a contact named as "Notes" to add note for a contact. I was able to create a contact, search or update using xml-rpc protocol, Java. I tried to add notes in the following way (my code below) but couldn't.
How to add Notes for a contact using their api in Java ?
My approach:
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
XmlRpcClient client = new XmlRpcClient();
config.setServerURL(new URL(uri)); //my app uri
client.setConfig(config);
List params=new ArrayList();
List customField=new ArrayList();
customField.add("this is new text1\n");
customField.add("this is text2\n");
customField.add("text3\n");
customField.add("text4\n");
params.add(api_key);
params.add("ContactNotes");//found from contact Table-schema
params.add(customField);
params.add(contactId); //suppose that was an known contactId Integer.
Integer responseCode=(Integer) client.execute("ContactService.add", params);
Executing the code, it gives this error:
org.apache.xmlrpc.XmlRpcException: No method matching arguments: java.lang.String, java.lang.String, [Ljava.lang.Object;, java.lang.Integer
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:197)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at infusionsoft.ContactOperation.addNote(ContactOperation.java:123)
at infusionsoft.Main.main(Main.java:80)
I just came to know from infusionsoft community post made by #Nicholas_Trecina , added CompletionDate field and made some changes to my code. And it works.
editedVersion:
List params = new ArrayList();
Map noteData = new HashMap();
noteData.put("ContactId", contactId);
noteData.put("ActionDescription", "My Note Title");
noteData.put("isAppointment", 0);
noteData.put("ActionDate","20170803T08:00:00");
noteData.put("CompletionDate","20171109");
noteData.put("CreationNotes", "Note data- what i want to save as note: bla bla bla..");
params.add(api_key);
params.add("ContactAction");
params.add(noteData);
Integer responseCode = (Integer) client.execute(
"DataService.add", params);

ERROR CODE:PE104 in Java and 2CO

I want to implement express checkout link with 2CO payment gateway ; tested the following code:
public void testExpressCheckoutF()
{
Twocheckout.apiusername = "sonoratestw";
Twocheckout.apipassword = "sonorasonora";
Twocheckout.privatekey = "81DBF3R3-04B3-47DB-8068-ED3DAB20BC5A";
Twocheckout.mode = "sandbox";
HashMap<String, String> params = new HashMap<>();
params.put("sid", "901328163");
params.put("mode", "sandbox");
params.put("currency_code", "USD");
params.put("x_receipt_link_url", "http://www.test.com/summary_twocheckoutl_payment.xhtml");
params.put("comment", "some description");
params.put("li_0_product_id", "assdsdcas");
params.put("li_0_type", "product");
params.put("li_0_name", "test name");
params.put("li_0_quantity", String.valueOf(1));
params.put("li_0_price", String.valueOf(33));
params.put("li_0_description", "some description");
String expressCheckout = TwocheckoutCharge.url(params);
System.out.println("\n " + expressCheckout);
}
But when I run the code I always get ERROR CODE:PE104. I found this post as a possible solution http://help.2checkout.com/articles/Knowledge_Article/Error-Code-PE104/?l=en_US&fs=RelatedArticle
But still getting the same error. Can you propose some solution?
Please try removing the li_0_product_id param and trying again or changing the value to an integer and not a string. The article you linked to gives you general areas to start (no lineitems, invalid product_id, etc..) so it's just process of elimination at this point.

Rally API, Creating Test Case Result - Connection Closed Exception

I'm developing in java / groovy and am new to the Rally API, I begun using it last week. I want to be able to use the REST API to create a new Test Case Result. On friday (its monday when I wrote this), I got it working using the example below, putting in the data I wanted using arguments into the method. I found this example on another website.
Today when I ran the code, and I dont think I changed anything, I keep getting "ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 1390; received: 1389).
I rewrote the code again, this time not changing anything from the example just to try and get it working again, and I get the same exception. Heres the code I'm using:
public static void createTestCaseResults(){
// Create and configure a new instance of RallyRestApi
RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"),"username#company.com", "Password");
restApi.setWsapiVersion("1.36");
restApi.setApplicationName("Add Test Case Result");
//Query User
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", "username#company.com"));
QueryResponse userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonElement userQueryElement = userQueryResults.get(0);
JsonObject userQueryObject = userQueryElement.getAsJsonObject();
String userRef = userQueryObject.get("_ref").getAsString();
// Query for Test Case to which we want to add results
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC7562"));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
try{
//Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Date", "2012-06-12T18:00:00.000Z");
newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
newTestCaseResult.addProperty("Build", "2012.05.31.0020101");
newTestCaseResult.addProperty("Tester", userRef);
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if(createResponse.wasSuccessful()){
println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read Test Case
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Test Case Result %s...", ref));
GetRequest getRequest = new GetRequest(ref);
getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
println(String.format("Read Test Case Result. Date = %s, Verdict = %s", obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for (int i=0; i<createErrors.length;i++) {
System.out.println(createErrors[i]);
}
}
}
finally{
restApi.close()
}
}
Appreciate any help with this. Thanks. :)
Is this still happening for you today? I just tried your code on both rally1 and our demo system, and it works reliably every time (only changed username and password, and the test case formatted id).
As a possible next step, I'd set a breakpoint in RallyRestApi.doRequest where the server response code is checked and see what additional information was available - for example, the response code, and the body and headers for the response.
This very well may be a bug in the underlying Apache HttpComponents library. I just upgraded to the latest 4.2.1 components. Would you mind giving the new 1.0.2 jar a try?
https://github.com/RallyTools/RallyRestToolkitForJava
Update:
This has been fixed with the 1.0.4 release of the toolkit today:
https://github.com/downloads/RallyTools/RallyRestToolkitForJava/rally-rest-api-1.0.4.jar

Categories