The method execute() is undefined for the type Mirror.Accounts.Insert - google-glass

I am creating a server side Dynamic Web Project using Java and Eclipse IDE for Google Glass Mirror API. In my web project I have a lib folder under WEB-INF
In the lib folder i have added the following .jar files
google-api-client-1.18.0-rc-sources.jar
google-api-services-mirror-v1-rev66-1.19.0.jar
google-collections-1.0-rc2.jar
google-http-client-1.18.0-rc.jar
google-http-client-jackson-1.19.0.jar
My server side code is
#SuppressWarnings("serial")
public class GlassAuthenticateUser extends HttpServlet{
public static Mirror getMirrorService() throws GeneralSecurityException,
IOException, URISyntaxException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(MIRROR_ACCOUNT_SCOPES)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Mirror service = new Mirror.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
return service;
}
public static void createAccount(Mirror mirror, String userToken, String accountName,
String authTokenType, String authToken) {
try {
Account account = new Account();
List<AuthToken> authTokens = Lists.newArrayList(
new AuthToken().setType(authTokenType).setAuthToken(authToken));
account.setAuthTokens(authTokens);
mirror.accounts().insert(
userToken, ACCOUNT_TYPE, accountName, account).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException{
//TO DO
}
}
}
I am getting the following error
The method execute() is undefined for the type Mirror.Accounts.Insert
Why is that so? I have download the latest Google API java client and used them in my project. However, it is unable to also resolve the GoogleCredential class
Can anyone suggest which .jar files should I be adding to resolve this issue?

It looks like you have the source jar for google-api-client-1.18.0-rc, when you need the class jar. You should be able to download the latest bundle from https://code.google.com/p/google-api-java-client/wiki/Downloads?tm=2 and then extracting google-api-java-client/libs/google-api-client-1.18.0-rc.jar from the downloaded zip file.

Related

AWS .Net Core SDK Simple Email Service Suppression List Not Working

I am trying to retrieve the SES account-level suppression list using AWS SDK in .Net Core:
Below is my code:
public class SimpleEmailServiceUtility : ISimpleEmailServiceUtility
{
private readonly IAmazonSimpleEmailServiceV2 _client;
public SimpleEmailServiceUtility(IAmazonSimpleEmailServiceV2 client)
{
_client = client;
}
public async Task<ListSuppressedDestinationsResponse> GetSuppressionList()
{
ListSuppressedDestinationsRequest request = new ListSuppressedDestinationsRequest();
request.PageSize = 10;
ListSuppressedDestinationsResponse response = new ListSuppressedDestinationsResponse();
try
{
response = await _client.ListSuppressedDestinationsAsync(request);
}
catch (Exception ex)
{
Console.WriteLine("ListSuppressedDestinationsAsync failed with exception: " + ex.Message);
}
return response;
}
}
But it doesn't seem to be working. The request takes too long and then returns empty response or below error if I remove try/catch:
An unhandled exception occurred while processing the request.
TaskCanceledException: A task was canceled.
System.Threading.Tasks.TaskCompletionSourceWithCancellation<T>.WaitWithCancellationAsync(CancellationToken cancellationToken)
TimeoutException: A task was canceled.
Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
Can anyone please guide if I am missing something?
Thank you!
I have tested your code and everything works correctly.
using Amazon;
using Amazon.SimpleEmailV2;
using Amazon.SimpleEmailV2.Model;
internal class Program
{
private async static Task Main(string[] args)
{
var client = new AmazonSimpleEmailServiceV2Client("accessKeyId", "secrectAccessKey", RegionEndpoint.USEast1);
var utility = new SimpleEmailServiceUtility(client);
var result = await utility.GetSuppressionList();
}
}
<PackageReference Include="AWSSDK.SimpleEmailV2" Version="3.7.1.127" />
Things that you can check:
Try again, maybe it was a temporary problem.
Try with the latest version that I am using(if not already)
How far are you from the region that you try to get the list? Try making the same request from an EC2 instance in that region.
Finally found the issue, I was using awsConfig.DefaultClientConfig.UseHttp = true;' in startup` which was causing the issue. Removing it fixed the issue and everything seems to be working fine now.

Ksoap2 client returned failed to connect to /192.168.15.56(port 1122) after 60000ms

I wrote a webservice in .net. I publish the service in IIS and started it. I also edited its bindings to connect to the 1122. In firewall i added inbound and outbound rules to access my port 1122. At this point i was able to open the webservice page in my android phones browser. I used ksoap2 library in my android code to access the .net service. I tested the service first on emulator and it worked fine. When i tried to test the same code on the phone it throws exception
failed to connect to /192.168.15.56(port 1122) after 60000ms.
This is the part of my code that controls the ip and calls my asynctask
String inputId=editText1.getText().toString();
//String params[]=new String[]{"10.0.2.2:1122",inputId};
String params[]=new String[]{"192.169.15.56:1122",inputId};
new MyAsyncTask().execute(params);
My class to process ksoap2 looks like this:
class MyAsyncTask extends AsyncTask<String, Void, String>
{
public String SOAP_ACTION= "http://threepin.org/findUserNameById";
public String OPERATION_NAME="findUserNameById";
public String WSDL_TARGET_NAMESPACE="http://threepin.org/";
public String SOAP_ADDRESS;
private SoapObject request;
private HttpTransportSE httpTransport;
private SoapSerializationEnvelope envelope;
Object response=null;
#Override
protected void onPreExecute() {
super.onPreExecute();
progressBar.setVisibility(View.VISIBLE);
}
#Override
protected String doInBackground(String... params) {
SOAP_ADDRESS="http://"+params[0]+"/myWebService.asmx";
request=new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("Id");
pi.setValue(Integer.parseInt(params[1]));
pi.setType(Integer.class);
request.addProperty(pi);
pi=new PropertyInfo();
envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
httpTransport=new HttpTransportSE(SOAP_ADDRESS,60000);
try
{
httpTransport.call(SOAP_ACTION,envelope);
response=envelope.getResponse();
}
catch (Exception e)
{
response=e.getMessage();
}
return response.toString();
}
#Override
protected void onPostExecute(final String result) {
super.onPostExecute(result);
mhandler.post(new Runnable() {
#Override
public void run() {
textView1.setText(result);
progressBar.setVisibility(View.GONE);
}
});
}
Yes my pc ip is 192.168.15.56 i double checked. here is my ip
The port is 1122. I can open it in my phones browser it looked like this
but instead of localhost 192.168.15.56 was shown any help! I could get.
I solved it i added in my web.config by default these were off so before doing this i could see local host and methods of my service in the mobile browser but not able to test them. Plus while concatination this instruction SOAP_ADDRESS= SOAP_ADDRESS="http://"+params[0]+"/myWebService.asmx";was messing up even though the path was same i was not able to open it instead of this "http://"+params[0]+"/myWebService.asmx" i hardcored the path and it worked the code is fine

Absolute path in Spring Boot

I'm using Spring Boot and i created a web service for photos upload.
for saving files, i used absolute path "/uploads", but it signals that this location's not exist, so i processed by using java path, src/...
in local server, that's working very well, but after hosting it on heroku server, images are not uploading. after adding an elements, the src of pictures is not exist.
this is the webservice:
//image /////////////////////////////////////////////////////////////////////
private final Logger log = LoggerFactory.getLogger(this.getClass());
#PostMapping("/")
#RequestMapping(value="/transfererImage", method = RequestMethod.POST)
public void transfererImage(#RequestParam("file") MultipartFile file, #RequestParam("nom") String nom) throws Exception{
String nomFichier="";
try {
nomFichier = nom;
byte[] bytes = file.getBytes();
ClassLoader classLoader = getClass().getClassLoader();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream (new FileOutputStream(new File("src/main/resources/static/images/"+nomFichier)));
bufferedOutputStream.write(bytes);
bufferedOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.info("une erreur est produite lors de la lecture de fichier"+ nomFichier);
}
}
thank you
I solved this problem by using this method:
System.getProperty("user.dir"))
it returns root folder of the project.
Thank you.

How do I unit test streaming download using jersey / dropwizard?

I have a resource method which produces a streaming download:
#GET
#Path("/{assetId}")
#Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response download(#PathParam("assetId") String assetId) {
StreamingOutput stream = os -> service.download(assetId, os);
return Response.ok(stream).build();
}
I want to unit test this with a mock service object. I already have:
private static AssetsService service = Mockito.mock(AssetsService.class);
#ClassRule
public final static ResourceTestRule resource = ResourceTestRule.builder()
.addResource(new AssetsResource(service))
.addProvider(MultiPartFeature.class)
.build();
#Test
public void testDownload() {
reset(service);
// how to get an output stream from this?
resource.client().target("/assets/123").request().get();
}
Per my comment in the test, what do I need to do in order to get an outputstream from the response? I find the jersey client API pretty confusing.
Once I have this, I'll stub the service call so that it writes a known file, and test that it's received correctly.
Try this:
Response response = resource.client().target("/assets/123").request().get();
InputStream is = response.readEntity(InputStream.class);

Getting Error while consuming self created webservices which connect Oracle SQL Developer

I am creating a webservices and while consuming getting error like this:
Exception in thread "main" org.apache.axis2.AxisFault: org.apache.axis2.AxisFault: >Mapping qname not fond for the package: oracle.jdbc.driver
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse>>>>(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.db.DatabaseClassStub.getDataBaseConnection(DatabaseClassStub.java:185)
at com.db.TestDatabaseClass.main(TestDatabaseClass.java:13)
For creating webservices that Connect Oracle SQL Developer using apache axis2 and eclipse. I have used the following s/w:
1). Eclipse Helios
2). Apache Tomcat 6
3). axis2-1.6.1-bin and axis2-1.6.1-war and also kept "ojdbc5" in tomcat lib folder.
My Webservices creation java code is,
package com.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseClass {
static Connection con = null;
public static Connection getDataBaseConnection()
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc:oracle:thin:#10.137.12.133:1521:ora11gr2","tran1","training123");
} catch (SQLException e) {
e.printStackTrace();
}
if (con != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
return con;
}
}
and Consuming webservices Java code is:
package com.db;
import java.rmi.RemoteException;
import com.db.DatabaseClassStub.GetDataBaseConnection;
import com.db.DatabaseClassStub.GetDataBaseConnectionResponse;
public class TestDatabaseClass {
public static void main(String[] args) throws RemoteException {
DatabaseClassStub stub = new DatabaseClassStub();
GetDataBaseConnection conn = new GetDataBaseConnection();
GetDataBaseConnectionResponse response = stub.getDataBaseConnection(conn);
System.out.println(response.get_return());
}
}
will you plz let me know where i am doing wrong?whenever i trying to execute TestDatabaseClass.java getting error which i have mentioned earlier. Same code (DatabaseClass.java) when i am executing in simple java project, its giving output but why not in webservices ?
You cannot 'export' a JDBC Connection in a SOAP web service operation: what goes across the wire has to be by definition serializable (as an XML).
You can expose methods/operations that provide the results of a query.