I have installed OpenX-2.8.10 on Web Server.
I'm using samples from it to connect to OpenX Server. I want to get Advertiser from server, and I have problem with it. I'm trying use AdvertiserService, but no success.
Code is here:
public class Prototype {
private final static String serverURL = "http://demo.pwi.ru";
private final static String openadsDir = "/openx";
private final static String logonService = "/www/api/v1/xmlrpc/LogonXmlRpcService.php";
private final static String agencyService = "/www/api/v1/xmlrpc/AgencyXmlRpcService.php";
private final static String username = "admin";
private final static String password = "875698";
private static Integer id = 1;
public static void main(String[] args) {
final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new URL(serverURL + openadsDir + logonService));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
String sessionId = (String) client.execute("logon", new Object[]{username, password});
System.out.println("User logged on with session Id: " + sessionId);
AdvertiserService service = new AdvertiserService(client, sessionId);
service.setSessionId(sessionId);
System.out.println("AdvertiserService: " + service.getAdvertiser(id ));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlRpcException e) {
e.printStackTrace();
}
}
}
Console says:
User logged on with session Id: phpads50addd559301e5.24695272
org.apache.xmlrpc.XmlRpcException: Failed to create input stream: demo.pwi.ru//phpads50addd559301e5.24695272//AdvertiserXmlRpcService.php
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:65)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:141)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:44)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
at org.openads.proxy.AbstractService.execute(AbstractService.java:111)
at org.openads.proxy.AdvertiserService.execute(AdvertiserService.java:1)
at org.openads.proxy.AdvertiserService.getAdvertiser(AdvertiserService.java:118)
at org.openads.proxy.prototype.Prototype.main(Prototype.java:36)
Caused by: java.io.FileNotFoundException: demo.pwi.ru//phpads50addd559301e5.24695272//AdvertiserXmlRpcService.php
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:63)
... 11 more
Caused by:
java.io.FileNotFoundException: demo.pwi.ru//phpads50addd559301e5.24695272//AdvertiserXmlRpcService.php
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:63)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:141)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:44)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
at org.openads.proxy.AbstractService.execute(AbstractService.java:111)
at org.openads.proxy.AdvertiserService.execute(AdvertiserService.java:1)
at org.openads.proxy.AdvertiserService.getAdvertiser(AdvertiserService.java:118)
at org.openads.proxy.prototype.Prototype.main(Prototype.java:36)
Related
I have to change the authentication for our web app (hybris project). What I need is a way to authenticate against an SMTP server (Office 356).
The problem is to get a token using "tenant id", "client_id" and "client_secret."
Using POSTMAN it does work properly (using the same credentials):
https://login.microsoftonline.com/3c111111-aed1-4dc2-ab93-f69fbef31111/oauth2/v2.0/token
But using java, it hast to look like this (or similar):
private static final String CLIENT_ID = "3c11111-aed1-4dc2-ab93-f69fbef31112";
private static final String CLIENT_SECRET = "f69fbef31112f69fbef31112f69fbef31112";
private static final String EWS_URL = "https://outlook.office365.com/EWS/Exchange.asmx";
private static final String RESOURCE = "https://graph.microsoft.com/.default";
private static final String TENANT_ID = "3c111111-aed1-4dc2-ab93-f69fbef31111";
private static final String AUTHORITY = "https://login.microsoftonline.com/" + TENANT_ID + "/oauth2/v2.0/authorize";
public String getAccessToken() {
AuthenticationResult result = null;
final ExecutorService service = Executors.newFixedThreadPool(1);
try {
final AuthenticationContext context = new AuthenticationContext(AUTHORITY, false, service);
final Future<AuthenticationResult> future = context.acquireToken(RESOURCE,
new ClientCredential(CLIENT_ID, CLIENT_SECRET), null);
result = future.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
log.error("Error", e);
} catch (MalformedURLException e) {
e.printStackTrace();
} finally {
service.shutdown();
}
String accessToken = null;
final String refreshToken;
// cache token and expiration
if (result != null) {
accessToken = result.getAccessToken();
refreshToken = result.getRefreshToken();
}
return accessToken;
}
}
When I deploy the code, I get a message:
java.util.concurrent.ExecutionException: com.microsoft.aad.adal4j.AuthenticationException: {"error_description":"AADSTS900023: Specified tenant identifier ...
It looks like the tenant id was wrong, but using POSTMAN, it does work. What am I doing wrong?
I am using DocuSign java client first time. I am create custom template for my pdf file. I am using DocuSign APIs. But facing following error:
javax.servlet.ServletException: java.lang.NoClassDefFoundError:
com/migcomponents/migbase64/Base64
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
I have created REST API and in that API i am trying to use createTemplate code but facing above issue.
I have imported all required jars in my project using maven. All jars are also present in my classpath. It seems at compile time all jar are found but at runtime not able to find the jars.
#Path("/template")
public class CreateTemplate {
private static final String UserName = "xyz.abc#gmail.com";
private static final String UserId = "fcc5726c-cd73-4844-b580-40bbbe6ca126";
private static final String IntegratorKey = "ae30ea4e-3959-4d1c-b867-fcb57d2dc4df";
private static final String IntegratorKeyImplicit = "68c1711f-8b19-47b1-888f-b49b4211d831";
//private static final String ClientSecret = "b4dccdbe-232f-46cc-96c5-b2f0f7448f8f";
private static final String RedirectURI = "https://www.docusign.com/api";
private static final String BaseUrl = "https://demo.docusign.net/restapi";
//private static final String OAuthBaseUrl = "account-d.docusign.com";
private static final String privateKeyFullPath = System.getProperty("user.dir") + "/src/test/keys/docusign_private_key.txt";
private static final String SignTest1File = "C:\\Users\\xyz\\Documents\\testDocuments\\SignTest1.pdf";
//private static final String TemplateId = "cf2a46c2-8d6e-4258-9d62-752547b1a419";
private String[] envelopeIds = new String[0];
TemplateSummary templateSummary;
#GET
#Path("/createTemplate")
#Produces("text/plain")
public TemplateSummary createTemplate() {
System.out.println("\nCreateTemplateTest:\n" + "===========================================");
byte[] fileBytes = null;
File f;
try {
// String currentDir = new java.io.File(".").getCononicalPath();
String currentDir = System.getProperty("user.dir");
java.nio.file.Path path = Paths.get(SignTest1File);
fileBytes = Files.readAllBytes(path);
f = new File(path.toString());
//Assert.assertTrue(f.length() > 0);
System.out.println("f.length()-->"+f.length());
} catch (IOException ioExcp) {
//Assert.assertEquals(null, ioExcp);
ioExcp.printStackTrace();
}
// create an envelope to be signed
EnvelopeTemplate templateDef = new EnvelopeTemplate();
templateDef.setEmailSubject("Please Sign my Java SDK Envelope");
templateDef.setEmailBlurb("Hello, Please sign my Java SDK Envelope.");
// add a document to the envelope
Document doc = new Document();
String base64Doc = Base64.encodeToString(fileBytes, false);
//String base64Doc = Base64.encodeToString(str.getBytes("UTF-8"), false))
doc.setDocumentBase64(base64Doc);
doc.setName("TestFile.pdf");
doc.setDocumentId("1");
List<Document> docs = new ArrayList<Document>();
docs.add(doc);
templateDef.setDocuments(docs);
// Add a recipient to sign the document
Signer signer = new Signer();
signer.setRoleName("Signer1");
signer.setRecipientId("1");
// Create a SignHere tab somewhere on the document for the signer to
// sign
SignHere signHere = new SignHere();
signHere.setDocumentId("1");
signHere.setPageNumber("1");
signHere.setRecipientId("1");
signHere.setXPosition("100");
signHere.setYPosition("100");
signHere.setScaleValue("0.5");
List<SignHere> signHereTabs = new ArrayList<SignHere>();
signHereTabs.add(signHere);
Tabs tabs = new Tabs();
tabs.setSignHereTabs(signHereTabs);
signer.setTabs(tabs);
templateDef.setRecipients(new Recipients());
templateDef.getRecipients().setSigners(new ArrayList<Signer>());
templateDef.getRecipients().getSigners().add(signer);
EnvelopeTemplateDefinition envTemplateDef = new EnvelopeTemplateDefinition();
envTemplateDef.setName("myTemplate");
templateDef.setEnvelopeTemplateDefinition(envTemplateDef);
ApiClient apiClient = new ApiClient(BaseUrl);
//String currentDir = System.getProperty("user.dir");
try {
// IMPORTANT NOTE:
// the first time you ask for a JWT access token, you should grant access by making the following call
// get DocuSign OAuth authorization url:
//String oauthLoginUrl = apiClient.getJWTUri(IntegratorKey, RedirectURI, OAuthBaseUrl);
// open DocuSign OAuth authorization url in the browser, login and grant access
//Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
// END OF NOTE
byte[] privateKeyBytes = null;
try {
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
} catch (IOException ioExcp) {
//Assert.assertEquals(null, ioExcp);
ioExcp.printStackTrace();
}
if (privateKeyBytes == null) return null;
java.util.List<String> scopes = new ArrayList<String>();
scopes.add(OAuth.Scope_SIGNATURE);
OAuth.OAuthToken oAuthToken = apiClient.requestJWTUserToken(IntegratorKey, UserId, scopes, privateKeyBytes, 3600);
//Assert.assertNotSame(null, oAuthToken);
// now that the API client has an OAuth token, let's use it in all
// DocuSign APIs
apiClient.setAccessToken(oAuthToken.getAccessToken(), oAuthToken.getExpiresIn());
UserInfo userInfo = apiClient.getUserInfo(oAuthToken.getAccessToken());
/*Assert.assertNotSame(null, userInfo);
Assert.assertNotNull(userInfo.getAccounts());
Assert.assertTrue(userInfo.getAccounts().size() > 0);
*/
System.out.println("userInfo.getAccounts().size()-->"+userInfo.getAccounts().size());
System.out.println("UserInfo: " + userInfo);
// parse first account's baseUrl
// below code required for production, no effect in demo (same
// domain)
apiClient.setBasePath(userInfo.getAccounts().get(0).getBaseUri() + "/restapi");
Configuration.setDefaultApiClient(apiClient);
String accountId = userInfo.getAccounts().get(0).getAccountId();
TemplatesApi templatesApi = new TemplatesApi();
templateSummary = templatesApi.createTemplate(accountId, templateDef);
//Assert.assertNotNull(templateSummary);
//Assert.assertNotNull(templateSummary.getTemplateId());
System.out.println("templateSummary-->"+templateSummary);
System.out.println("templateSummary.getTemplateId()-->"+templateSummary.getTemplateId());
//System.out.println("TemplateSummary: " + templateSummary);
} catch (ApiException ex) {
System.out.println("Exception: 123");
ex.printStackTrace();
} catch (Exception e) {
//System.out.println("Exception: " + e.getLocalizedMessage());
System.out.println("Exception: 234");
e.printStackTrace();
}
return templateSummary;
}
}
I feel like I am facing missing runtime jar files.
private static String url ="https://myemail.com/ews/exchange.asmx";
private static String username="user#email.com";
private static String password="user#123";
private static String domain="Dir";
public class service{
ExchangeService exchangeService = null;
exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
exchangeService.setUrl(new URI(EmailService.url));
ExchangeCredentials credentials = new WebCredentials(username, password,domain);
exchangeService.setCredentials(credentials);
FindItemsResults<Item> results = null;
try {
String getFolderId = null;
Folder rootfolder =
Folder.bind(service,WellKnownFolderName.MsgFolderRoot);
rootfolder.load();
}
}
I am trying to connect to web server by using the above code i am getting the exception as,
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Connection is still allocated
I am trying to get the name and state of the servers in a domain using MBeanServerConnection
public class GetServerState {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static final ObjectName service;
// Initializing the object name for DomainRuntimeServiceMBean
// so it can be used throughout the class.
static {
try {
service = new ObjectName(
"com.bea:Name=DomainRuntimeService,Type=weblogic.management.
mbeanservers.domainruntime.DomainRuntimeServiceMBean");
}catch (MalformedObjectNameException e) {
throw new AssertionError(e.getMessage());
}
}
/*
* Initialize connection to the Domain Runtime MBean Server
*/
public static void initConnection(String hostname, String portString,
String username, String password) throws IOException,
MalformedURLException {
String protocol = "t3";
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.domainruntime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,
port, jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection();
}
/*
* Print an array of ServerRuntimeMBeans.
* This MBean is the root of the runtime MBean hierarchy, and
* each server in the domain hosts its own instance.
*/
public static ObjectName[] getServerRuntimes() throws Exception {
return (ObjectName[]) connection.getAttribute(service,
"ServerRuntimes");
}
/*
* Iterate through ServerRuntimeMBeans and get the name and state
*/
public void printNameAndState() throws Exception {
ObjectName[] serverRT = getServerRuntimes();
System.out.println("got server runtimes");
int length = (int) serverRT.length;
for (int i = 0; i < length; i++) {
String name = (String) connection.getAttribute(serverRT[i],
"Name");
String state = (String) connection.getAttribute(serverRT[i],
"State");
System.out.println("Server name: " + name + ". Server state: "
+ state);
}
}
public static void main(String[] args) throws Exception {
String hostname = args[0];
String portString = args[1];
String username = args[2];
String password = args[3];
GetServerState s = new GetServerState();
initConnection(hostname, portString, username, password);
s.printNameAndState();
connector.close();
}
}
Here I am getting the name of only those servers which are in "RUNNING" state and not the list of all the servers in the Domain.
Can some one guide me with what changes I need to make to get name and states of all the server in the domain?
I have this error:
WARNING: Authentication error: Unable to respond to any of these challenges: {}
Exception : No authentication header information
I am using GWT with eclipse.
I really don't know what's wrong in my code.
Any help would be appreciated.
Thanks in advance.
Client side EntryPoint class:
private static final String GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
private static final String GOOGLE_CLIENT_ID = "xxxxxxx.apps.googleusercontent.com";
private static final String CONTACTS_SCOPE = "https://www.google.com/m8/feeds";
private static final Auth AUTH = Auth.get();
public void onModuleLoad() {
final AuthRequest req = new AuthRequest(GOOGLE_AUTH_URL, GOOGLE_CLIENT_ID).withScopes(CONTACTS_SCOPE);
AUTH.login(req, new Callback<String, Throwable>() {
public void onSuccess(String token) {
ABASession.setToken(token);
}
public void onFailure(Throwable caught) {
Window.alert("Error:\n" + caught.getMessage());
}
});
}
I store the token in a class that I will use later.
Server side: ContactServiceImpl (RPC GAE procedure)
//The token stored previously is then passed through RPC
public List printAllContacts(String token) {
try {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey("My consumer key");
oauthParameters.setOAuthConsumerSecret("My consumer secret");
PrivateKey privKey = getPrivateKey("certificate/akyosPrivateKey.key");
OAuthRsaSha1Signer signer = new OAuthRsaSha1Signer(privKey);
ContactsService service = new ContactsService("XXX");
service.setProtocolVersion(ContactsService.Versions.V3);
oauthParameters.setOAuthToken(token);
service.setOAuthCredentials(oauthParameters, signer);
// Request the feed
URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/default/full?xoauth_requestor_id=xxx.yyy#gmail.com");
ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
for (ContactEntry entry : resultFeed.getEntries()) {
for (Email email : entry.getEmailAddresses()) {
contactNames.add(email.getAddress());
}
}
return contactNames;
} catch (Exception e) {
System.err.println("Exception : " + e.getMessage());
}
return null;
}
set the scope
oauthParameters.setScope("http://www.google.com/m8/feeds/contacts/default/full");