I'd like to use MockServer analysis in the dumpToLogAsJava mode to have it print java-formatted expectations of a HTTP service I have.
Moreover I'd like to use mockserver-maven-plugin for it.
So far I was able to get a json-formatted output like this:
2016-06-07 19:10:46,348 DEBUG [main] org.mockserver.cli.Main [?:?]
Using command line options: proxyPort=18080
2016-06-07 19:10:46,623 INFO [MockServer HttpProxy Thread] org.mockserver.proxy.http.HttpProxy [?:?] MockServer proxy started on port: 18080
2016-06-07 19:10:46,626 DEBUG [MockServer HttpProxy Thread] o.m.c.ConfigurationProperties [?:?] Property file not found on classpath using path [mockserver.properties]
2016-06-07 19:10:46,626 DEBUG [MockServer HttpProxy Thread] o.m.c.ConfigurationProperties [?:?] Property file not found using path [mockserver.properties]
2016-06-07 19:11:01,838 DEBUG [nioEventLoopGroup-3-1] o.m.client.netty.NettyHttpClient [?:?] Sending request: {
"method" : "GET",
"path" : "/sources",
[...]
}
2016-06-07 19:11:02,180 DEBUG [nioEventLoopGroup-3-1] o.m.client.netty.NettyHttpClient [?:?] Received response: {
[...]
}
2016-06-07 19:11:02,220 INFO [nioEventLoopGroup-3-1] o.m.proxy.http.HttpProxyHandler [?:?] returning response:
{
[...]
}
for request as json:
{
[...]
}
as curl:
[...]
By adding the following to my pom.xml
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>3.10.4</version>
<configuration>
<proxyPort>18080</proxyPort>
<logLevel>DEBUG</logLevel>
</configuration>
<executions>
<execution>
<id>start-mock</id>
<phase>pre-integration-test</phase>
<goals>
<goal>runForked</goal>
</goals>
</execution>
<execution>
<id>stop-mock</id>
<phase>post-integration-test</phase>
<goals>
<goal>stopForked</goal>
</goals>
</execution>
</executions>
</plugin>
I have no idea how to change the output format to Java without writing some additional Java code (and even then I'm not sure what exactly would I have to write).
PS. I can't seem to get a Java-formatted dump at all -- I've filled an issue on GH
The missing part was that you need dump the expectations after the requests you are interested in have been executed.
My impression was that it's a feature you enable and then Mockserver dumps the expectation on the go.
Anyhow, here is one ugly way to do it:
ClientAndProxy client = ClientAndProxy.startClientAndProxy(18080);
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
client.dumpToLogAsJava();
}
});
Related
I am facing this issue while building a maven project
[INFO] Cloning git#bitbucket.org:bookkeeper/bookkeeper-openapi3-hosted-ui-configuration.git:refs/tags/v5.0.0 into /Users/shubhamjain/bookkeeper/de/bookkeeper-ui-service/service/bookkeeper-api/bookkeeper-platform-hosted-ui-configuration-5.0.0
[ERROR] Failed to fetch bookkeeper-platform-hosted-ui-configuration API (5.0.0):
org.eclipse.jgit.api.errors.TransportException: git#bitbucket.org:bookkeeper/bookkeeper-openapi3-hosted-ui-configuration.git: Auth fail
at org.eclipse.jgit.api.FetchCommand.call (FetchCommand.java:222)
----
----
Caused by: org.eclipse.jgit.errors.TransportException: git#bitbucket.org:bookkeeper/bookkeeper-openapi3-hosted-ui-configuration.git: Auth fail
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession (JschConfigSessionFactory.java:162)
at org.eclipse.jgit.transport.SshTransport.getSession (SshTransport.java:107)
Initially I had issues in access to the mentioned repository but then I got required permissions.
In the pom.xml
-----
-----
<plugin>
<groupId>com.bookkeeper</groupId>
<artifactId>bookkeeper-api-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-hosted-ui-configuration-openapi-hook</id>
<goals>
<goal>generate-client</goal>
</goals>
<configuration>
<apiName>bookkeeper-platform-hosted-ui-configuration</apiName>
<apiVersion>5.0.0</apiVersion>
<repositorySpecPath>bookkeeper-platform-hosted-ui-configuration/application-hosted-ui-configuration.yaml</repositorySpecPath>
<gitUrlTemplate>git#bitbucket.org:bookkeeper/bookkeeper-openapi3-hosted-ui-configuration.git</gitUrlTemplate>
<openapiConfigurationOverrides>
<isExperimental>false</isExperimental>
<apiName>hosted-ui-configuration</apiName>
</openapiConfigurationOverrides>
</configuration>
</execution>
</executions>
</plugin>
-----
-----
What could be missing ? Thanks in advance.
Issue was Maven couldn't find ssh binary path on the environment
Setting GIT_SSH environment variable worked.
export GIT_SSH=${SSH_BINARY_PATH}
In my case
export GIT_SSH=/usr/bin/ssh
I am trying to generate the java classes from a WSLD file, that uses basic authentication.
Although there are many plugins out there, I have to use the following one: org.jvnet.jaxb2.maven2:maven-jaxb2-plugin
With wsimport or wsdl2java i have found the way to configure the basic authentication parameters. Using the maven-jaxb2-plugin i had no luck.
My configuration follows:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<packageName>com.mycompany</packageName>
<sourceType>wsdl</sourceType>
<specVersion>2.2</specVersion>
<schemas>
<schema>
<url>https://some-url?wsdl</url>
</schema>
</schemas>
<outputDirectory>target/generated-sources/xjb</outputDirectory>
<clearOutputDir>false</clearOutputDir>
<useActiveProxyAsHttpproxy>true</useActiveProxyAsHttpproxy>
</configuration>
</execution>
</executions>
</plugin>
As expected, the build fails with the following message:
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: https://some-url?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:2275)
... 36 more
Any ideas about the basic authentication configuration? Thank's in advance!
Note: https://username:pass#some-url?wsdl, i still get an IOException because of the unauthorized request.
I haven't found any way of solving this. I ended up downloading the .wsdl and the needed .xsd files and edited them (changed the import URL's) properly.
Note: For people that have the same issue, i would recommend the jaxws:wsimport plugin, that supports an xauthFile option for the configuration of the basic authentication.
wsimport, wsdl2java, maven-jaxb2 are meant for generating Proxy classes out of the Descriptor file.
Since you are getting Unauthorized (401), it could be either due to wrong creds or may be you are not sending credentials et all in a request.
For Basic Auth, refer another stackoverflow question here
Also, if you can post your exact code here where you configure the Creds, it will be helpful in identifying the cause
It took a while for me to understand what is there inside xauthfile.
An xauthfile is nothing but, URL with basic authentication credentials.
https://username:pass#url:port/
I've inherited a project that contains many java web services. I want to add another one so I've been using one that works as a template. I've added
<namespace id="bsghandle"
uri="http://bsghandle.queryservice.vcwh.oss.cable.company.com/" />
into the <namespaces> section of enunciate.xml and
namespace="http://bsghandle.queryservice.vcwh.oss.cable.company.com/"
file="bsghandle.wsdl" />
into the <xml> section.
Here is the pom.xml snippet
<plugin>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>maven-enunciate-plugin</artifactId>
<version>1.25</version>
<configuration>
<configFile>${basedir}/src/main/webapp/WEB-INF/enunciate.xml</configFile>
<compileDebug>true</compileDebug>
<addGWTSources>false</addGWTSources>
<addActionscriptSources>false</addActionscriptSources>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
Maven generates the web.xml entries, including this one:
<filter-mapping>
<filter-name>wsdl-redirect-filter-bsghandle</filter-name>
<url-pattern>/soap/BsgHandleResourceService</url-pattern>
</filter-mapping>
I created three classes to handle the request, similar to the template.
I send a request to the working service like this
./soapget.sh soap_serial.xml r.xml
where soapget.sh is
#!/bin/bash
wget "http://localhost:5032/VCWH_QueryService/soap/SettopChannelMapResourceService" --post-file=$1 --header="Content-Type: text/xml" -O $2
This produces a good response, captured in r.xml.
Now when I try the same thing for the new service I wrote
./bsg.sh soap_rate.xml r2.xml
where bsg.sh is
#!/bin/bash
wget "http://localhost:5032/VCWH_QueryService/soap/BsgHandleResourceService" --post-file=$1 --header="Content-Type: text/xml" -O $2
I get the useless error
2015-11-23 20:26:52 ERROR 500: Internal Server Error
The log files for the project do not contain any more info either.
When I watch the log file for the working service (in SettopChannelMapResource.java), I can see this debugging statement getting hit as the first thing being output to the log
logger.debug("getChannelMapBySerialNumber() called for sn=" + serialNumber
+ " from ip" + request.getRemoteAddr());
But in my similar service the same logger output does not get hit.
How do I debug this?
I used a request in SoapUI. For some reason, that returned a useful error message and I was able to find and fix the problem. Even after fixed, the other method still returned the same useless ERROR 500: Internal Server Error
I'm trying to make my wsdl location not static anymore in my generated client (using the jaxws-maven-plugin), but I'm not having a lot of succes.
What I've found is the following..
My plugin (placed in the plugins in the build of the pom):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>ecad-ws</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<sourceDestDir>${basedir}/target/generated-sources</sourceDestDir>
<keep>true</keep>
<verbose>true</verbose>
<extension>true</extension>
<wsdlDirectory>src/main/resources</wsdlDirectory>
<wsdlFiles>
<wsdlFile>CBS.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>http://localhost/wsdl/msw/cbs?wsdl</wsdlLocation>
<catalog>
${basedir}/src/main/resources/META-INF/jax-ws-catalog.xml
</catalog>
</configuration>
</execution>
</executions>
</plugin>
and a jax-ws-catalog file (placed in src/main/resources/META-INF):
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<system
systemId="http://localhost/wsdl/msw/cbs?wsdl"
uri="../CBS.wsdl" />
</catalog>
the CBS.wsdl is placed in src/main/resouces. As far as I understand my research the above code changes the URL in the generated client to http://localhost/wsdl/msw/cbs?wsdl (that's working) and then, when the client is invoked, it looks for the catalog and matches the above url to ../CBS.wsdl. That last part isn't working since I'm getting the following exception:
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
... 118 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://localhost/wsdl/msw/cbs?wsdl'.: java.net.ConnectException: Connection refused: connect
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:244)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
... 120 more
Caused by: java.net.ConnectException: Connection refused: connect
I can't really find another solution. If I'm not changing the wsdl location in the generated client I'm always getting something like "Failed to access the WSDL at: file: XXXXX" (what is completely normal)
I'm using the jdk 7 btw..
This answer is about 6 years late, but...
I wandered onto this question as I was searching for how to setup the catalog file in my own repository .. in 2021 .. using Java 11. I managed to get it to work for my repo, and looking at this configuration above against mine, the only thing I could say is that you might need to add ${basedir} to the <wsdlDirectory> section.
...
<wsdlDirectory>${basedir}src/main/resources</wsdlDirectory>
...
I'm leaving this here for the next weary developer (like me) who has to implement a wsdl connection in the age of REST.
When I try to deploy or undeploy my application(EAR) in JBoss using Maven and Jenkins I get the following error :
INFO: JBoss Remoting version 3.2.12.GA
[DEBUG]
java.io.IOException: java.net.ConnectException: JBAS012144: Could not
connect to remote://192.168.1.8:10099. The connection timed out
at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeForResult(AbstractModelControllerClient.java:129)
at org.jboss.as.controller.client.impl.AbstractModelControllerClient.execute(AbstractModelControllerClient.java:71)
at org.jboss.as.plugin.common.AbstractServerConnection.isDomainServer(AbstractServerConnection.java:234)
at org.jboss.as.plugin.common.AbstractServerConnection.getClient(AbstractServerConnection.java:156)
...
My JBoss server is listening the port 10099 (9999+100) taking into account the following jboss configuration:
<socket-binding-group
name="standard-sockets"
default-interface="public"
port-offset="${jboss.socket.binding.port-offset:100}">
<socket-binding
name="management-native"
interface="management"
port="${jboss.management.native.port:9999}"/>
The Maven plugin configuration :
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.6.Final</version>
<inherited>true</inherited>
<configuration>
<!-- <skip>true</skip> -->
<hostname>${deploy.jboss.host}</hostname>
<port>${deploy.jboss.port}</port>
<username>${deploy.jboss.user}</username>
<password>${deploy.jboss.password}</password>
<filename>fitness-${stage}-${app.server}.ear</filename>
<name>fitness-${stage}-${app.server}.ear</name>
<skip>${skip.deployment}</skip>
<!-- Logging ??? not working-->
<execute-commands>
<commands>
<command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir", "path"=>"jenkins-deployment.log"})
</command>
<command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])
</command>
</commands>
</execute-commands>
</configuration>
<executions>
<execution>
<id>deploy-application</id>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>undeploying-all-application</id>
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<match-pattern>fitness-.*</match-pattern>
<matchPatternStrategy>all</matchPatternStrategy>
</configuration>
</execution>
</executions>
</plugin>
With the following variables :
deploy.jboss.host = 192.168.1.8
deploy.jboss.port = 10099
Here is my configuration :
OS : Ubuntu 13.04
Java : 1.6.0_26
JBoss : 7.1.1.final
Maven : 3.0.3
Jboss-as-maven-plugin : 7.6.final
Jenkins and the target jboss server are running the same machine identified by the ip 192.168.1.8
My own diagnostic :
If I run
sudo netstat -nlp | grep :10099
I get :
tcp 0 0 0.0.0.0:10099 0.0.0.0:* LISTEN 25475/java
And 25475 is my Jboss instance. It seems that JBoss is listening behind the right port.
I can connect using another instance with CLI :
sh jboss-cli.sh controller=192.168.1.8:10099
Thanks in advance for your help
I had same problem and I solved it setting a higher timeout value.
For example:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.9.Final</version>
<inherited>true</inherited>
<configuration>
<hostname>${jboss.hostname}</hostname>
<port>${jboss.port}</port>
<username>${jboss.user}</username>
<password>${jboss.pass}</password>
....
<timeout>30000</timeout>
....
</configuration>
</plugin>
Default "timeout" value is 5000ms. You can try with a higher value like 30000ms. It worked for me.
Edited:
As Pedro said, another option can be passing "timeout" to maven via a command line argument. eg. -Djboss-as.timeout=30000
The problem was JDK 7 related. My jenkins server was using Java 1.7
If you want to use the jdk 7 you need to use the following parameter :
-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.KQueueSelectorProvider
I had the similar issue, however the fix was different, it might help somebody. I had to change maven plugin to the following one:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha11</version>
</plugin>