繁体   English   中英

从Applet呼叫本地服务

[英]Calling local service from Applet

从我已阅读的所有内容中,小程序可以调用其自己的服务器提供的任何服务。 这就是为什么我在netbeans中编写并启动了一项服务,并且可以在浏览器中看到它的原因

http://localhost:12345/server?wsdl

为了连接到服务,我使用了wsimport并将文件放置在applet目录中,然后清理并构建了项目。

如果我同时启动两个(服务+小程序),则工作正常,当我删除策略文件时,它不会。

Caused by: java.security.AccessControlException: access denied                       
("java.util.PropertyPermission" "xml.catalog.ignoreMissing" "read")

我在Netbeans中启动了服务并将小程序放置在本地服务器(xampp)上,我可以通过以下方式访问它

http://localhost/sql/mainapplet.html

但什么也没发生。 我做错了什么?

这是代码:

服务器项目:

程序库

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService(targetNamespace = "GUI")
@SOAPBinding(style = Style.RPC)
public class CP {
public String getResults(String u, String p, String s, String se, String q) {
  ...
 }
}

服务器.java

public class Server {
public static void main(String[] args) {
    CP server = new CP();
    Endpoint e = Endpoint.publish("http://localhost:12345/server", server);
 }
}

客户端项目:CP.java

package gui;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.Action;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.4-b01
 * Generated source version: 2.2
 * 
 */
@WebService(name = "CP", targetNamespace = "GUI")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface CP {


/**
 * 
 * @param arg4
 * @param arg3
 * @param arg2
 * @param arg1
 * @param arg0
 * @return
 *     returns java.lang.String
 */
@WebMethod
@WebResult(partName = "return")
@Action(input = "GUI/CP/getResultsRequest", output = "GUI/CP/getResultsResponse")
public String getResults(
    @WebParam(name = "arg0", partName = "arg0")
    String arg0,
    @WebParam(name = "arg1", partName = "arg1")
    String arg1,
    @WebParam(name = "arg2", partName = "arg2")
    String arg2,
    @WebParam(name = "arg3", partName = "arg3")
    String arg3,
    @WebParam(name = "arg4", partName = "arg4")
    String arg4);

}

CPService.java

package gui;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.4-b01
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "CPService", targetNamespace = "GUI", wsdlLocation =     "http://localhost:12345/server?wsdl")
public class CPService
extends Service {

private final static URL CPSERVICE_WSDL_LOCATION;
private final static WebServiceException CPSERVICE_EXCEPTION;
private final static QName CPSERVICE_QNAME = new QName("GUI", "CPService");

static {
    URL url = null;
    WebServiceException e = null;
    try {
        url = new URL("http://localhost:12345/server?wsdl");
    } catch (MalformedURLException ex) {
        e = new WebServiceException(ex);
    }
    CPSERVICE_WSDL_LOCATION = url;
    CPSERVICE_EXCEPTION = e;
}

public CPService() {
    super(__getWsdlLocation(), CPSERVICE_QNAME);
}

public CPService(WebServiceFeature... features) {
    super(__getWsdlLocation(), CPSERVICE_QNAME, features);
}

public CPService(URL wsdlLocation) {
    super(wsdlLocation, CPSERVICE_QNAME);
}

public CPService(URL wsdlLocation, WebServiceFeature... features) {
    super(wsdlLocation, CPSERVICE_QNAME, features);
}

public CPService(URL wsdlLocation, QName serviceName) {
    super(wsdlLocation, serviceName);
}

public CPService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
    super(wsdlLocation, serviceName, features);
}

/**
 * 
 * @return
 *     returns CP
 */
@WebEndpoint(name = "CPPort")
public CP getCPPort() {
    return super.getPort(new QName("GUI", "CPPort"), CP.class);
}

/**
 * 
 * @param features
 *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
 * @return
 *     returns CP
 */
@WebEndpoint(name = "CPPort")
public CP getCPPort(WebServiceFeature... features) {
    return super.getPort(new QName("GUI", "CPPort"), CP.class, features);
}

private static URL __getWsdlLocation() {
    if (CPSERVICE_EXCEPTION!= null) {
        throw CPSERVICE_EXCEPTION;
    }
    return CPSERVICE_WSDL_LOCATION;
 }

}

MainApplet.java

package gui;

public class MainApplet extends javax.swing.JApplet {
...
    CPService cps = new CPService();
    CP cproc = cps.getCPPort();
    txtResult.setText(cproc.getResults("a","b","j","s", "q"));
}

HTML文件:

<HTML>
<BODY>
<P>
<APPLET codebase="client/build/classes" code="gui/MainApplet.class"     archive="client/dist/client.jar" width=1400 height=800></APPLET>
</P>
</BODY>
</HTML>

解决的问题:我必须像这样嵌入小程序

<applet archive="client.jar" code="gui.MainApplet" width="1600" height="1400"></applet>

而且我不得不签署我的小程序(仍然不确定为什么)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM