I have the following webservice :
package testSmart;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
#WebService(name="AddHM", portName="prtNameHM", serviceName="srvNameHM", targetNamespace="hm.com")
#SOAPBinding(style=Style.RPC)
public class add {
AddBusinessLogic add=new AddBusinessLogic();
#WebMethod(action="GoAdd", operationName="Go_AddNumber")
public int addNum(int i, int j) {
return add.addNum(i, j);
}
}
which works perfectly fine with glassfish.
then I stopped glassfish and use the following code to make my server :
import javax.xml.ws.Endpoint;
public class publisher {
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://localhost:1234/add", new add());
}
}
Now when I try this link:
http://localhost:1234/add
Nothing happens and the browser says no data received.
Even after trying different port the same problem exist.
Can anyone help me how to fix it?
Call to http://localhost:1234/add will not get you anything because there is no specific document with that URI that browser can get. But if you type
http://localhost:1234/add?wsdl
you should get the generated wsdl document.
Related
I'm learning jda and I coded my discord bot so that console send the message that I sent, but after executing this code, I send a random message in my test discord server, the console just prints nothing. Is anything wrong with my code? I also tried e.getMessage().getContentRaw(), but it returns same result.
Main Class
package net.lib.first;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Message;
import net.lib.first.event.Listener;
import javax.security.auth.login.LoginException;
public class Main {
public static void main(String[] args) throws LoginException {
String token = (my bot token);
JDABuilder builder = JDABuilder.createDefault(token);
builder.addEventListeners(new Listener());
builder.setActivity(Activity.playing("Type !ping"));
builder.build();
Message.suppressContentIntentWarning();
}
}
Listener Class
package net.lib.first.event;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
public class Listener extends ListenerAdapter {
#Override
public void onMessageReceived(#NotNull MessageReceivedEvent e) {
System.out.println(e.getMessage().getContentDisplay());
}
}
Solved the problem, I didn't add the method enableIntents(GatewayIntent.MESSAGE_CONTENT) to builder.
I have the same problem, but there is no option to enable GatewayIntent.MESSAGE_CONTENT
only:
[...]
builder.createDefault("xxx")
.setActivity(Activity.playing("!help") )
.setStatus(OnlineStatus.ONLINE)
.addEventListeners(new CommandListener() )
.addEventListeners(new VoiceListener() )
.enableIntents(GatewayIntent.GUILD_MESSAGES)
.enableIntents(GatewayIntent.DIRECT_MESSAGES)
.build();
[...]
I have enabled the above ones.
I followed the steps on Google Cloud's Java and OpenTelemetry site (https://cloud.google.com/trace/docs/setup/java-ot) and made a simple hello world Java application locally and am trying to get my traces to show up on Google Cloud Trace using their trace exporter.
All the setup code is the same, and the program compiles and runs successfully. However, I don't see anything on the Trace dashboard. I know it is not an issue with IAM or my service account key because I ran the Python example and it shows up in Cloud Trace dashboard just fine.
Anyone have any guidance on why the Java version could be silently failing?
Thanks
package hello;
import org.joda.time.LocalTime;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.export.IntervalMetricReader;
import java.io.IOException;
import java.util.Random;
import com.google.cloud.opentelemetry.trace.TraceConfiguration;
import com.google.cloud.opentelemetry.trace.TraceExporter;
import java.util.Collections;
import static java.util.Collections.singleton;
import java.time.Duration;
public class HelloWorld {
private static final Random random = new Random();
private static OpenTelemetry setupTraceExporter() {
try {
TraceExporter traceExporter = TraceExporter.createWithConfiguration(
TraceConfiguration.builder().setProjectId("my-test-id").build());
// Register the TraceExporter with OpenTelemetry
return OpenTelemetrySdk.builder()
.setTracerProvider(
SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(traceExporter).build())
.build())
.buildAndRegisterGlobal();
} catch (IOException e) {
System.out.println("Uncaught Exception");
System.out.println(e);
return null;
}
}
public static void main(String[] args) {
System.out.println("Starting the example application");
/* SET UP */
OpenTelemetry otel = setupTraceExporter();
/* Creating tracer */
Tracer tracer =
otel.getTracer("java foo");
Span span = tracer.spanBuilder("my span").startSpan();
// put the span into the current Context
try (Scope scope = span.makeCurrent()) {
System.out.println("Hello");
Thread.sleep(4000);
} catch (Throwable t) {
span.setStatus(StatusCode.ERROR, "error");
System.out.println(t);
} finally {
span.end();
}
System.out.println("Closing");
//otel.getSdkTracerProvider().shutdown();
}
}
After some debugging, I figured out the answer.
Seems like with this simple example, the BatchSpanProcessor is not a good idea because there is only one span that is getting traced.
SimpleSpanProcessor directly forwards the spans to Cloud Trace no matter what whereas BatchSpanProcessor waits until there is enough data before pushing to Cloud Trace. Hence why I was not seeing anything in Cloud Trace because BatchSpanProcessor hadn't registered enough spans for it to actually upload it to Google Cloud.
Span Processors Documentation
Change the following lines
return OpenTelemetrySdk.builder()
.setTracerProvider(
SdkTracerProvider.builder()
.addSpanProcessor(SimpleSpanProcessor.create(traceExporter))
.build())
.buildAndRegisterGlobal();
Hope this helps others!
For several days I have been trying to implement SignalA in my Android-Project.
I've found out that I have to import the 3 Projects (parallel-basic-http-client, SignalA and SignalALongPolling) in Eclipse. After the import of parallel-basic-http-client, I have several errors. It seems that the origin of those errors is in the import statement:
import com.turbomanage.httpclient.AsyncCallback;
In the console, the following statement is listed:
[2013-12-03 09:03:45 - parallel-basic-http-client] WARNING: unable to write jarlist cache file C:\Users\Patrik\workspace\parallel-basic-http-client\bin\jarlist.cache
Below is the complete code for the understanding:
package com.zsoft.parallelhttpclient;
import android.os.AsyncTask;
import android.os.Build;
import com.turbomanage.httpclient.AsyncCallback;
import com.turbomanage.httpclient.AsyncHttpClient;
import com.turbomanage.httpclient.HttpRequest;
import com.turbomanage.httpclient.android.DoHttpRequestTask;
public class DoParallelHttpRequestTask extends DoHttpRequestTask {
public DoParallelHttpRequestTask(AsyncHttpClient httpClient,
AsyncCallback callback) {
super(httpClient, callback);
// TODO Auto-generated constructor stub
}
public void execute(HttpRequest httpRequest) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
super.execute(httpRequest);
} else {
super.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, httpRequest);
}
}
}
Can anyone help me?
I think there is a problem with the dependencies used by SignalA.
To make it easier to use SignalA I've published it on Maven Central.
Hi All
I am new to web services. I have written a java class.
But I am not getting how to deploy it. I mean do i need web server or app server . As this is simple java class i can not make WAR file to deploy it . So what is the method to deploy it and which server should i use. I am using JDK 1.6
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;
#WebService
public class WiseQuoteServer {
#SOAPBinding(style = Style.RPC)
public String getQuote(String category) {
if (category.equals("fun")) {
return "5 is a sufficient approximation of infinity.";
}
if (category.equals("work")) {
return "Remember to enjoy life, even during difficult situatons.";
} else {
return "Becoming a master is relatively easily. Do something well and then continue to do it for the next 20 years";
}
}
public static void main(String[] args) {
WiseQuoteServer server = new WiseQuoteServer();
Endpoint endpoint = Endpoint.publish(
"http://localhost:9191/wisequotes", server);
The best answer to your question would be the tutorial of JAX-WS
I'm creating some web services using JAX-WS and the java SE build-in server. Every time I add a new parameter on a web service i need to change the URL it's published to. Otherwise the new parameters always get a null value. How can I make this work without changing the URL?
Here's the main class code with the publishing code:
import javax.xml.ws.Endpoint;
import pickate.AmazonMail;
import pickate.FacebookStream;
class Main {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8888/pickate/amazonmail", new AmazonMail());
Endpoint.publish("http://localhost:8888/pickate/facebookstream", new FacebookStream());
}
}
And the implementation of one of the webservices
package pickate;
import java.util.List;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
// Other imports go here
#WebService
public class FacebookStream
{
public FacebookStream()
{
}
#WebMethod
#Oneway
public void sendNotification(
#WebParam(name = "receivers") List<String> receivers,
#WebParam(name = "fbtoken") String fbtoken,
#WebParam(name = "body") String body,
)
{
// Some interesting stuff goes here
}
}
It was indeed the client caching up the WSDL file. It seems the PHP Soap Extension (which is what i'm using on the client-side) does it by default.