I faced with problem using jax ws client with Weblogic 10.3. I generate webservice stubs and test connection with webservice in simple java project. All works fine. But when I pack this project in jar file and add it to my main project which contains other jars and running on weblogic I get:
java.lang.NoSuchMethodError: org.home.client.AddressWS.getAddressByRequestAsync(ILjava/lang/String;)Ljavax/xml/ws/Response;
This exception was thrown when I tried to call webservice stub`s method.
public class MyServiceImpl implements MyService {
private AddressWS service;
private static final String ENDPOINT = "http://endpoint.address.ws.company.org/";
private static final String SERVICE_NAME = "AddressWSImplService";
#Override
public void setSOAPServiceURL(String serviceURL) {
URL url = createURL(serviceURL);
QName qName = new QName(ENDPOINT, SERVICE_NAME);
AddressWSImplService addressWSImplService= new AddressWSImplService(url, qName);
service = addressWSImplService.getAddressWSImplPort();
}
#Override
public String getAddressById(int id, String param) throws TimeoutException {
// NoSuchMethodError was thrown here
final Response<GetAddressById> response = service
.getAddressByIdAsync(id, param);
return (String) getValue(new Future<String>() {...});}
Any pointers will be helpfull.
Related
My REST API works fine when deployed but my tests are failing using Jersey Arquillian extension:
#Test
#RunAsClient
public void postTest(#ArquillianResteasyResource final WebTarget webTarget) {
MyRequest request = new MyRequest();
String response = webTarget.path("/demo").request(MediaType.APPLICATION_JSON)
.post(Entity.json(request)).readEntity(String.class);
Assert.assertEquals("OK", response);
}
I get the error:
Error HTTP method POST is not supported by this URL
My JAX-RS programs look OK:
#ApplicationPath("api")
public class JaxRsActivator extends Application {
}
#Path("/demo")
#Stateless
public class DemoResource extends BaseResource {
#POST
public Response demo(MyRequest request) {
return Response.ok().entity("OK").build();
}
}
The default value for #ArquillianResteasyResource is rest, but my JaxRsActivator is set to api.
To solve it I used:
#ArquillianResteasyResource("api")
To get the complete URI: webTarget.getUri()
I am new to the game of web-service clients, and have generated code using the wsdl2java maven dependency.
I am packaging this project as a .war file.
My issue is that I do not know how to make the autogenerated client reach an endpoint across domains, and I also do not know how to set the client's wsdlLocation properly.
Starting with the latter:
Inside of the autogenerated service class, I found a static URL WSDL_LOCATION attribute, as well as 'parameters?' to a WebServiceClient annotation.
#WebServiceClient(name = "my_service",
wsdlLocation = "file:/c:/tmp/my_service.wsdl",
targetNamespace = "someAutoGenTargetNS/wsdl")
public class my_service_Service extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("someAutoGenTargetNS/wsdl", "my_service");
public final static QName my_service = new QName("http://someAtuoGenTargetNS/wsdl", "my_service");
static {
URL url = null;
try {
url = new URL("file:/c:/tmp/my_service.wsdl");
} catch (MalformedURLException e) {
java.util.logging.Logger.getLogger(my_service_Service.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}", "file:/c:/tmp/my_service.wsdl");
}
WSDL_LOCATION = url;
}
Currently, the WSDL_LOCATION url is always set to null, as it can not find the filepath specified (which is expected). I have the wsdl and xsd stored in the resources folder, but do not know how to specify the path to reach that. I have tried
new URL("file:/resources/my_service.wsdl")
new URL("file:/src/main/java/resources/my_service.wsdl")
new URL("classpath:my_service.wsdl")
and quite a few others. What is the correct way to do this, and if it requires an xml-catalog, where can I find documentation about where to put the catalog.xml file.
And now the former:
I believe my implementation to change the endpoint to the location I want is correct, and it is the wsdlLocation issue that is giving me a headache. Here is my implementation to change the endpoints. If this does not look right, simply point me in the direction of what to use, no need for a full implementation.
private static final QName SERVICE_NAME = new QName(""someAutoGenTargetNS/wsdl"", "my_service");
private URL wsdlURL = my_service_Service.WSDL_LOCATION;
my_service_Service ss;
my_service port;
public my_service_client()
{
//Redacted code for trusting all SSL Certs and hostnameVerifiers as it is not needed for the scope of this question
this.ss = new my_service_Service(this.wsdlURL,SERVICE_NAME);
this.port = ss.getMy_Service();
BindingProvider bp = (BindingProvider) this.port;
Map<String,Object> clientRequestContext = bp.getRequestContext();
clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://New_Endpoint_IP");
//Basic auth header credentials
clientRequestContext.put(BindingProvider.USERNAME_PROPERTY,"username");
clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY,"password");
}
Resources I attempted to understand prior to asking this question:
1
2
3
4
5
6
7+
8
Conclusively, I am coming to the realization I would much rather work with HTTP than SOAP, but legacy systems require legacy interaction.
Error's received that lead me to believe this is a wsdlURL issue:
javax.xml.ws.soap.SOAPFaultException: Internal Error (from client)
org.apache.cxf.binding.soap.SoapFault: Internal Error (from client)
Figured out the issue (4 days of tracking the problem later, and i can solve it shortly after asking the question here...)
This is indeed a valid way of setting the endpoint URL. That answers that question.
I adopted the classLoader.getResource approach from this reference to set the wsdlLocation
My new code became:
#WebServiceClient(name = "my_service",
wsdlLocation = "classpath:my_service.wsdl",
targetNamespace = "someAutoGenTargetNS/wsdl")
public class my_service_Service extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("someAutoGenTargetNS/wsdl", "my_service");
public final static QName my_service = new QName("http://someAtuoGenTargetNS/wsdl", "my_service");
static {
URL url = null;
url = my_service.class.getClassLoader().getResource("my_service.wsdl");
WSDL_LOCATION = url;
}
Lastly I realized that the most basic web-service call I was trying to utilize was incorrectly setting the request body. I had set the request_body to null, in stead of instantiation a new instance of the request class that was autogenerated. This is what was throwing these two errors, but I am sure fixing the above helped lead me to the solution by enforcing my understanding of how these pieces work together.
Currently I need to programm a RESTful Webservice in Java and I'm using Grizzly server as my server and I'm using Jersey for the HTML code generation.
This is my Grizzly server:
public static void main(String[] args) throws IOException {
URI baseUri = URI.create("http://localhost:9998");
final ResourceConfig resourceConfig = new ResourceConfig(homepage.class);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
System.out.println("Starting grizzly ...");
JOptionPane.showMessageDialog(null, "Stop Server");
server.shutdownNow();
}
And this is my current homepage code:
#Path("")
public class homepage {
#GET
#Produces("text/html")
public String sayHelloInHtml() {
return "<html><body><h2>Hello World</h2></body></html>";
}
}
Right now I'm using a string for my HTML code but is their a way to use a HTML file instead?
Also how can I create a button that triggers a Java method on click? I know how to create a button but I don't know how to make the event handler to trigger the Java method on click.
I'm developing an SOAP Service in Java but i encountered this error:
WARNING: Mismatch between Java model and WSDL model found, For wsdl operation
{http://database.unitn.it/}isLoginOkay,There is no matching wsdl fault with detail
QName {http://interfaces.database.unitn.it/}Exception
com.sun.xml.internal.ws.spi.db.DatabindingException: Unknown JAXBContext
implementation: class com.sun.xml.bind.v2.runtime.JAXBContextImpl
at com.sun.xml.internal.ws.spi.db.BindingContextFactory.getJAXBFactory(BindingContextFactory.j
ava:192)
at com.sun.xml.internal.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:134)
at com.sun.xml.internal.ws.message.jaxb.JAXBMessage.create(JAXBMessage.java:152)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:241)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:224)
at com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.getWSDLOperationMapping(PayloadQNameBasedOperationFinder.java:143)
at com.sun.xml.internal.ws.wsdl.OperationDispatcher.getWSDLOperationMapping(OperationDispatcher.java:82)
at com.sun.xml.internal.ws.api.message.Packet.getWSDLOperationMapping(Packet.java:285)
at com.sun.xml.internal.ws.api.message.Message.getOperation(Message.java:284)
at com.sun.xml.internal.ws.api.message.Message.getOperation(Message.java:302)
at com.sun.xml.internal.ws.api.message.Message.isOneWay(Message.java:379)
...
I am working with java 1.8 and everything run on localhost. The wsdl seams to work fine.
I do not know what the problem could be. I tried a lot to solve the problem but I have not four no one thread that talk about this problem.
Please help.
EDIT:
Here the publisher:
private static final String mUrl = "http://localhost:" + Ports.MASTER_DATABASE_SERVICE + "/database";
public static void launch() throws Exception
{
System.out.println("----Starting on ..." + mUrl);
Endpoint.publish(mUrl, new Database());
System.out.println("----SOAP Service started!!!!");
}
Here the interface for the client part:
#WebService
#SOAPBinding(style = Style.RPC)
public interface DatabaseAPIsInterface
{
#WebMethod
public User isLoginOkay(String password, String email) throws Exception;
}
Here the implementation of the method isLoginOkay(...)
#Override
public User isLoginOkay(String password, String email) throws Exception
{
Database db = null;
try
{
db = fromConnectionPool();
Dao<User, Integer> dao = createPersonDAO(db);
throwIfSomeNull(password, email);
QueryBuilder<User, Integer> builder = dao.queryBuilder();
User user = builder.where().eq(User.FIELD_NAME_EMAIL, email).and().eq(User.FIELD_NAME_PASSWORD, password).queryForFirst();
if (user != null) return user;
else throw new FileNotFoundException("User does not exist");
} finally
{
close(db);
}
}
And here the client part:
String mUrl = "http://localhost:" + Ports.MASTER_DATABASE_SERVICE + "/database?wsdl";
URL url = new URL(mUrl);
QName qname = new QName("http://database.unitn.it/", "DatabaseService");
Service service = Service.create(url, qname);
DatabaseInterface database = service.getPort(new QName("http://database.unitn.it/", "DatabasePort"), DatabaseAPIsInterface.class);
User user = database.isLoginOkay(password, email);
System.out.println(user);
I'm building a web service that's supposed to register on another server by sending its wsdl URL to that server.
I built a very basic web service in Netbeans,
#WebService
public class RegisterTest{
#WebMethod(operationName = "emphasize")
public String emphasize(#WebParam(name = "inputStr") String input){
return input + "!!!";
}
}
and Netbeans automatically directs me to localhost:8080/RegisterTest/RegisterTestService?Tester, and naturally, the wsdl can be found at localhost:8080/RegisterTest/RegisterTestService?wsdl.
How would I programmatically get this URL?
Edit:
I've noticed that the only place that seems to store this URL is the glassfish server itself. The context-root seems to only be found in glassfish/domain//config/domain.xml.
Is there a nice way of accessing the glassfish server APIs? I can easily get the endpoint address through the UI in applications > serviceName > View Endpoint, is there a programmatic way of doing this?
I've tried looking through asadmin commands, but can't seem to find anything there that gets the context-root or the endpoint URL either.
Untested, but should be pretty close to what you're looking for:
#WebService
public class RegisterTest
{
#Resource
private WebServiceContext context;
#WebMethod(operationName = "emphasize")
public String emphasize(#WebParam(name = "inputStr") String input)
{
return input + "!!!";
}
#WebMethod(operationName = "getWsdlUrl")
public String getWsdlUrl()
{
final ServletContext sContext = (ServletContext)
this.context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
final HttpServletRequest req = (HttpServletRequest)
this.context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
final StringBuilder sb = new StringBuilder();
sb.append(req.isSecure() ? "https" : "http");
sb.append("://");
sb.append(req.getLocalName());
if ((req.isSecure() && req.getLocalPort() != 443) ||
(!req.isSecure() && req.getLocalPort() != 80))
{
sb.append(":");
sb.append(req.getLocalPort());
}
sb.append(sContext.getContextPath());
sb.append(RegisterTest.class.getSimpleName());
sb.append("Service?wsdl");
return sb.toString();
}
}